Skip to content

Commit 616a50d

Browse files
thePunderWomanalan-agius4
authored andcommitted
refactor(github-actions): update labeling prompt with descriptions
This allows for providing more info via github label descriptions so the prompt can possibly do a better job of automatically labeling issues.
1 parent d69b99a commit 616a50d

File tree

3 files changed

+20
-13
lines changed

3 files changed

+20
-13
lines changed

github-actions/labeling/issue/lib/issue-labeling.spec.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ describe('IssueLabeling', () => {
1616

1717
beforeEach(() => {
1818
mockGit = jasmine.createSpyObj('Octokit', ['paginate', 'issues', 'pulls']);
19-
mockGit.issues = jasmine.createSpyObj('issues', ['addLabels', 'get']);
19+
mockGit.issues = jasmine.createSpyObj('issues', ['addLabels', 'get', 'listLabelsForRepo']);
2020

2121
// Mock paginate to return the result of the promise if it's a list, or just execute the callback
2222
(mockGit.paginate as jasmine.Spy).and.callFake((fn: any, args: any) => {
23-
if (fn === mockGit.issues.listLabelsOnIssue) {
24-
return Promise.resolve([{name: 'area: core'}, {name: 'area: router'}, {name: 'bug'}]);
23+
if (fn === mockGit.issues.listLabelsForRepo) {
24+
return Promise.resolve([
25+
{name: 'area: core', description: 'Core Angular framework'},
26+
{name: 'area: router', description: 'Angular Router'},
27+
{name: 'bug', description: 'Bug report'},
28+
]);
2529
}
2630
return Promise.resolve([]);
2731
});

github-actions/labeling/issue/lib/issue-labeling.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {Labeling} from '../../shared/labeling.js';
88
export class IssueLabeling extends Labeling {
99
readonly type = 'Issue';
1010
/** Set of area labels available in the current repository. */
11-
repoAreaLabels = new Set<string>();
11+
repoAreaLabels = new Map<string, string>();
1212
/** The issue data fetched from Github. */
1313
issueData?: components['schemas']['issue'];
1414

@@ -17,7 +17,7 @@ export class IssueLabeling extends Labeling {
1717

1818
// Determine if the issue already has an area label, if it does we can exit early.
1919
if (
20-
this.issueData?.labels.some((label) =>
20+
this.issueData?.labels.some((label: string | {name?: string}) =>
2121
(typeof label === 'string' ? label : label.name)?.startsWith('area: '),
2222
)
2323
) {
@@ -37,10 +37,13 @@ ${this.issueData!.body}
3737
3838
The available area labels are:
3939
${Array.from(this.repoAreaLabels)
40-
.map((label) => ` - ${label}`)
40+
.map(
41+
([label, description]) =>
42+
` - Label: ${label}${description ? `, Description: ${description}` : ''}`,
43+
)
4144
.join('\n')}
4245
43-
Based on the content, which area label is the best fit?
46+
Based on the content of the issue and the available labels, which area label is the best fit?
4447
Respond ONLY with the exact label name (e.g. "area: core").
4548
If you are strictly unsure or if multiple labels match equally well, respond with "ambiguous".
4649
If no area label applies, respond with "none".
@@ -82,7 +85,7 @@ If no area label applies, respond with "none".
8285
.then((labels) =>
8386
labels
8487
.filter((l) => l.name.startsWith('area: '))
85-
.forEach((l) => this.repoAreaLabels.add(l.name)),
88+
.forEach((l) => this.repoAreaLabels.set(l.name, l.description ?? '')),
8689
),
8790
this.git.issues.get({owner, repo, issue_number: context.issue.number}).then((resp) => {
8891
this.issueData = resp.data;

github-actions/labeling/issue/main.js

Lines changed: 5 additions & 5 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)