Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix local git submissions by casting to KnowledgeYamlData #383

Merged
merged 1 commit into from
Dec 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/app/api/local/pr/knowledge/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { NextRequest } from 'next/server';
import * as git from 'isomorphic-git';
import fs from 'fs';
import path from 'path';
import { dumpYaml } from '@/utils/yamlConfig';
import { KnowledgeYamlData } from '@/types';
import yaml from 'js-yaml';

// Define paths and configuration
Expand All @@ -13,18 +15,20 @@ const KNOWLEDGE_DIR = 'knowledge';

export async function POST(req: NextRequest) {
try {
// Extract the QnA data from the request body TODO: what is documentOutline?
const { content, attribution, name, email, submissionSummary, documentOutline, filePath } = await req.json(); // eslint-disable-line @typescript-eslint/no-unused-vars
// Extract the data from the request body
const { content, attribution, name, email, submissionSummary, filePath } = await req.json();

// Parse the YAML string into an object
const knowledgeData = yaml.load(content) as KnowledgeYamlData;

// Convert the object to YAML
const yamlString = dumpYaml(knowledgeData);

// Define branch name and file paths
const branchName = `knowledge-contribution-${Date.now()}`;
const newYamlFilePath = path.join(KNOWLEDGE_DIR, filePath, 'qna.yaml');
const newAttributionFilePath = path.join(KNOWLEDGE_DIR, filePath, 'attribution.txt');

// Convert data to YAML and plain text formats
const yamlString = yaml.dump(content);
const attributionContent = `
Title of work: ${attribution.title_of_work}
const attributionContent = `Title of work: ${attribution.title_of_work}
Link to work: ${attribution.link_to_work}
Revision: ${attribution.revision}
License of the work: ${attribution.license_of_the_work}
Expand Down