Skip to content

Commit 3e6da41

Browse files
committed
Retrive the skill and knowledge summary from the commit message
Signed-off-by: Anil Vishnoi <[email protected]>
1 parent 1754c1e commit 3e6da41

File tree

3 files changed

+43
-5
lines changed

3 files changed

+43
-5
lines changed

src/app/api/native/git/branches/route.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ const LOCAL_TAXONOMY_ROOT_DIR = process.env.NEXT_PUBLIC_LOCAL_TAXONOMY_ROOT_DIR
99
const REMOTE_TAXONOMY_ROOT_DIR = process.env.NEXT_PUBLIC_TAXONOMY_ROOT_DIR || '';
1010
const REMOTE_TAXONOMY_REPO_CONTAINER_MOUNT_DIR = '/tmp/.instructlab-ui';
1111

12+
interface CommitDetails {
13+
message: string;
14+
email: string;
15+
name: string;
16+
}
17+
1218
interface Diffs {
1319
file: string;
1420
status: string;
@@ -131,6 +137,29 @@ async function handleDiff(branchName: string, localTaxonomyDir: string) {
131137
return NextResponse.json({ error: 'Invalid branch name for comparison' }, { status: 400 });
132138
}
133139

140+
// Resolve the reference to the branch's HEAD
141+
const commitOid = await git.resolveRef({
142+
fs,
143+
dir: localTaxonomyDir,
144+
ref: `refs/heads/${branchName}` // Resolve the branch reference
145+
});
146+
147+
// Read the commit object using its OID
148+
const commit = await git.readCommit({
149+
fs,
150+
dir: localTaxonomyDir,
151+
oid: commitOid
152+
});
153+
154+
const signoffMatch = commit.commit.message.split('Signed-off-by:');
155+
const message = signoffMatch ? signoffMatch[0].trim() : '';
156+
157+
const commitDetails: CommitDetails = {
158+
message: message,
159+
email: commit.commit.author.email,
160+
name: commit.commit.author.name
161+
};
162+
134163
const changes = await findDiff(branchName, localTaxonomyDir);
135164
const enrichedChanges: Diffs[] = [];
136165
for (const change of changes) {
@@ -142,7 +171,7 @@ async function handleDiff(branchName: string, localTaxonomyDir: string) {
142171
}
143172
}
144173

145-
return NextResponse.json({ changes: enrichedChanges }, { status: 200 });
174+
return NextResponse.json({ changes: enrichedChanges, commitDetails: commitDetails }, { status: 200 });
146175
} catch (error) {
147176
console.error(`Failed to show contribution changes ${branchName}:`, error);
148177
return NextResponse.json(

src/components/Contribute/EditKnowledge/native/EditKnowledge.tsx

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,18 @@ const EditKnowledgeNative: React.FC<EditKnowledgeClientComponentProps> = ({ bran
6969
pullRequestNumber: 0,
7070
oldFilesPath: ''
7171
};
72-
//TODO: read the signoff from the commit and set the name and email accordingly
73-
// Meanwhile let's use the session email/name
72+
7473
if (session?.user?.name && session?.user?.email) {
7574
knowledgeExistingFormData.name = session?.user?.name;
7675
knowledgeExistingFormData.email = session?.user?.email;
7776
}
7877

78+
if (result?.commitDetails != null) {
79+
knowledgeExistingFormData.submissionSummary = result?.commitDetails.message;
80+
knowledgeExistingFormData.name = result?.commitDetails.name;
81+
knowledgeExistingFormData.email = result?.commitDetails.email;
82+
}
83+
7984
if (result?.changes.length > 0) {
8085
result.changes.forEach((change: ChangeData) => {
8186
if (change.status != 'deleted' && change.content) {

src/components/Contribute/EditSkill/native/EditSkill.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@ const EditSkillNative: React.FC<EditSkillClientComponentProps> = ({ branchName }
6262
oldFilesPath: ''
6363
};
6464

65-
//TODO: read the signoff from the commit and set the name and email accordingly
66-
// Meanwhile let's use the session email/name
6765
if (session?.user?.name && session?.user?.email) {
6866
skillExistingFormData.name = session?.user?.name;
6967
skillExistingFormData.email = session?.user?.email;
7068
}
7169

70+
if (result?.commitDetails != null) {
71+
skillExistingFormData.submissionSummary = result?.commitDetails.message;
72+
skillExistingFormData.name = result?.commitDetails.name;
73+
skillExistingFormData.email = result?.commitDetails.email;
74+
}
75+
7276
if (result?.changes.length > 0) {
7377
result.changes.forEach((change: ChangeData) => {
7478
if (change.status != 'deleted' && change.content) {

0 commit comments

Comments
 (0)