Skip to content
Merged
Show file tree
Hide file tree
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
109 changes: 108 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 30 additions & 1 deletion src/app/api/native/git/branches/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ const LOCAL_TAXONOMY_ROOT_DIR = process.env.NEXT_PUBLIC_LOCAL_TAXONOMY_ROOT_DIR
const REMOTE_TAXONOMY_ROOT_DIR = process.env.NEXT_PUBLIC_TAXONOMY_ROOT_DIR || '';
const REMOTE_TAXONOMY_REPO_CONTAINER_MOUNT_DIR = '/tmp/.instructlab-ui';

interface CommitDetails {
message: string;
email: string;
name: string;
}

interface Diffs {
file: string;
status: string;
Expand Down Expand Up @@ -131,6 +137,29 @@ async function handleDiff(branchName: string, localTaxonomyDir: string) {
return NextResponse.json({ error: 'Invalid branch name for comparison' }, { status: 400 });
}

// Resolve the reference to the branch's HEAD
const commitOid = await git.resolveRef({
fs,
dir: localTaxonomyDir,
ref: `refs/heads/${branchName}` // Resolve the branch reference
});

// Read the commit object using its OID
const commit = await git.readCommit({
fs,
dir: localTaxonomyDir,
oid: commitOid
});

const signoffMatch = commit.commit.message.split('Signed-off-by:');
const message = signoffMatch ? signoffMatch[0].trim() : '';

const commitDetails: CommitDetails = {
message: message,
email: commit.commit.author.email,
name: commit.commit.author.name
};

const changes = await findDiff(branchName, localTaxonomyDir);
const enrichedChanges: Diffs[] = [];
for (const change of changes) {
Expand All @@ -142,7 +171,7 @@ async function handleDiff(branchName: string, localTaxonomyDir: string) {
}
}

return NextResponse.json({ changes: enrichedChanges }, { status: 200 });
return NextResponse.json({ changes: enrichedChanges, commitDetails: commitDetails }, { status: 200 });
} catch (error) {
console.error(`Failed to show contribution changes ${branchName}:`, error);
return NextResponse.json(
Expand Down
55 changes: 45 additions & 10 deletions src/app/api/native/pr/knowledge/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,14 @@ export async function POST(req: NextRequest) {
const REPO_DIR = path.join(LOCAL_TAXONOMY_ROOT_DIR, '/taxonomy');
try {
// Extract the data from the request body
const { content, attribution, name, email, submissionSummary, filePath } = await req.json();
const { action, branchName, content, attribution, name, email, submissionSummary, filePath, oldFilesPath } = await req.json();

let knowledgeBranchName;
if (action == 'update' && branchName != '') {
knowledgeBranchName = branchName;
} else {
knowledgeBranchName = `knowledge-contribution-${Date.now()}`;
}

// Parse the YAML string into an object
const knowledgeData = yaml.load(content) as KnowledgeYamlData;
Expand All @@ -27,24 +34,29 @@ export async function POST(req: NextRequest) {
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');
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}
Creator names: ${attribution.creator_names}
`;

// Set the flag if commit needs to be amended
let amendCommit = false;

// Initialize the repository if it doesn’t exist
await git.init({ fs, dir: REPO_DIR });

// Create a new branch
await git.branch({ fs, dir: REPO_DIR, ref: branchName });
// Create a new branch if the knowledge is pushed for first time
if (action != 'update') {
await git.branch({ fs, dir: REPO_DIR, ref: knowledgeBranchName });
}

// Checkout the new branch
await git.checkout({ fs, dir: REPO_DIR, ref: branchName });
await git.checkout({ fs, dir: REPO_DIR, ref: knowledgeBranchName });

const newYamlFilePath = path.join(KNOWLEDGE_DIR, filePath, 'qna.yaml');
const newAttributionFilePath = path.join(KNOWLEDGE_DIR, filePath, 'attribution.txt');

// Write YAML file to the knowledge directory
const yamlFilePath = path.join(REPO_DIR, newYamlFilePath);
Expand All @@ -59,6 +71,28 @@ Creator names: ${attribution.creator_names}
await git.add({ fs, dir: REPO_DIR, filepath: newYamlFilePath });
await git.add({ fs, dir: REPO_DIR, filepath: newAttributionFilePath });

if (action == 'update') {
// Define file paths
const oldYamlFilePath = path.join(KNOWLEDGE_DIR, oldFilesPath, 'qna.yaml');
const oldAttributionFilePath = path.join(KNOWLEDGE_DIR, oldFilesPath, 'attribution.txt');

if (oldYamlFilePath != newYamlFilePath) {
console.log('File path for the knowledge contribution is updated, removing the old files.');
// Write the QnA YAML file
const yamlFilePath = path.join(REPO_DIR, oldYamlFilePath);
fs.unlinkSync(yamlFilePath);

// Write the attribution text file
const attributionFilePath = path.join(REPO_DIR, oldAttributionFilePath);
fs.unlinkSync(attributionFilePath);

await git.remove({ fs, dir: REPO_DIR, filepath: oldYamlFilePath });
await git.remove({ fs, dir: REPO_DIR, filepath: oldAttributionFilePath });

amendCommit = true;
}
}

// Commit the changes
await git.commit({
fs,
Expand All @@ -67,12 +101,13 @@ Creator names: ${attribution.creator_names}
author: {
name: name,
email: email
}
},
amend: amendCommit
});

// Respond with success message and branch name
console.log(`Knowledge contribution submitted successfully to local taxonomy repo. Submission Name is ${branchName}.`);
return NextResponse.json({ message: 'Knowledge contribution submitted successfully.', branch: branchName }, { status: 201 });
console.log(`Knowledge contribution submitted successfully to local taxonomy repo. Submission Name is ${knowledgeBranchName}.`);
return NextResponse.json({ message: 'Knowledge contribution submitted successfully.', branch: knowledgeBranchName }, { status: 201 });
} catch (error) {
console.error(`Failed to submit knowledge contribution to local taxonomy repo:`, error);
return NextResponse.json({ error: 'Failed to submit knowledge contribution.' }, { status: 500 });
Expand Down
56 changes: 45 additions & 11 deletions src/app/api/native/pr/skill/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ export async function POST(req: NextRequest) {
const REPO_DIR = path.join(LOCAL_TAXONOMY_ROOT_DIR, '/taxonomy');
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
const { action, branchName, content, attribution, name, email, submissionSummary, documentOutline, filePath, oldFilesPath } = await req.json(); // eslint-disable-line @typescript-eslint/no-unused-vars

// Define file paths
const branchName = `skill-contribution-${Date.now()}`;
const newYamlFilePath = path.join(SKILLS_DIR, filePath, 'qna.yaml');
const newAttributionFilePath = path.join(SKILLS_DIR, filePath, 'attribution.txt');
let skillBranchName;
if (action == 'update' && branchName != '') {
skillBranchName = branchName;
} else {
skillBranchName = `skill-contribution-${Date.now()}`;
}

const skillData = yaml.load(content) as SkillYamlData;
const attributionData = attribution as AttributionData;
Expand All @@ -34,14 +36,23 @@ License of the work: ${attributionData.license_of_the_work}
Creator names: ${attributionData.creator_names}
`;

// Set the flag if commit needs to be amended
let amendCommit = false;

// Initialize the repository if it doesn’t exist
await git.init({ fs, dir: REPO_DIR });

// Create a new branch
await git.branch({ fs, dir: REPO_DIR, ref: branchName });
// Create a new branch if the skill is pushed for first time
if (action != 'update') {
await git.branch({ fs, dir: REPO_DIR, ref: skillBranchName });
}

// Checkout the new branch
await git.checkout({ fs, dir: REPO_DIR, ref: branchName });
await git.checkout({ fs, dir: REPO_DIR, ref: skillBranchName });

// Define file paths
const newYamlFilePath = path.join(SKILLS_DIR, filePath, 'qna.yaml');
const newAttributionFilePath = path.join(SKILLS_DIR, filePath, 'attribution.txt');

// Write the QnA YAML file
const yamlFilePath = path.join(REPO_DIR, newYamlFilePath);
Expand All @@ -56,6 +67,28 @@ Creator names: ${attributionData.creator_names}
await git.add({ fs, dir: REPO_DIR, filepath: newYamlFilePath });
await git.add({ fs, dir: REPO_DIR, filepath: newAttributionFilePath });

if (action == 'update') {
// Define file paths
const oldYamlFilePath = path.join(SKILLS_DIR, oldFilesPath, 'qna.yaml');
const oldAttributionFilePath = path.join(SKILLS_DIR, oldFilesPath, 'attribution.txt');

if (oldYamlFilePath != newYamlFilePath) {
console.log('File path for the skill contribution is updated, removing the old files.');
// Write the QnA YAML file
const yamlFilePath = path.join(REPO_DIR, oldYamlFilePath);
fs.unlinkSync(yamlFilePath);

// Write the attribution text file
const attributionFilePath = path.join(REPO_DIR, oldAttributionFilePath);
fs.unlinkSync(attributionFilePath);

await git.remove({ fs, dir: REPO_DIR, filepath: oldYamlFilePath });
await git.remove({ fs, dir: REPO_DIR, filepath: oldAttributionFilePath });

amendCommit = true;
}
}

// Commit files
await git.commit({
fs,
Expand All @@ -64,12 +97,13 @@ Creator names: ${attributionData.creator_names}
author: {
name: name,
email: email
}
},
amend: amendCommit
});

// Respond with success
console.log('Skill contribution submitted successfully. Submission name is ', branchName);
return NextResponse.json({ message: 'Skill contribution submitted successfully.', branch: branchName }, { status: 201 });
console.log('Skill contribution submitted successfully. Submission name is ', skillBranchName);
return NextResponse.json({ message: 'Skill contribution submitted successfully.', branch: skillBranchName }, { status: 201 });
} catch (error) {
console.error('Failed to create local branch and commit:', error);
return NextResponse.json({ error: 'Failed to submit skill contribution.' }, { status: 500 });
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// src/app/edit-submission/knowledge/[id]/page.tsx
import * as React from 'react';
import { AppLayout } from '@/components/AppLayout';
import EditKnowledge from '@/components/Contribute/EditKnowledge/EditKnowledge';
import EditKnowledge from '@/components/Contribute/EditKnowledge/github/EditKnowledge';

type PageProps = {
params: Promise<{ id: string }>;
Expand Down
20 changes: 20 additions & 0 deletions src/app/edit-submission/knowledge/native/[id]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// src/app/edit-submission/knowledge/[id]/page.tsx
import * as React from 'react';
import { AppLayout } from '@/components/AppLayout';
import EditKnowledgeNative from '@/components/Contribute/EditKnowledge/native/EditKnowledge';

type PageProps = {
params: Promise<{ id: string }>;
};

const EditKnowledgePage = async ({ params }: PageProps) => {
const branchName = await params;

return (
<AppLayout>
<EditKnowledgeNative branchName={branchName.id} />
</AppLayout>
);
};

export default EditKnowledgePage;
Loading
Loading