Skip to content

Commit 2f6f8f0

Browse files
committed
feat(github-actions): skip gemini labeling if an issue already has an area label
1 parent 864d6ea commit 2f6f8f0

3 files changed

Lines changed: 31 additions & 2 deletions

File tree

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,17 @@ export class IssueLabeling {
3939
// Initialize labels and issue data
4040
await this.initialize();
4141

42-
const ai = this.getGenerativeAI();
42+
// Determine if the issue already has an area label, if it does we can exit early.
43+
if (
44+
this.issueData?.labels.some((label) =>
45+
(typeof label === 'string' ? label : label.name)?.startsWith('area: '),
46+
)
47+
) {
48+
this.coreService.info('Issue already has an area label. Skipping.');
49+
return;
50+
}
4351

52+
const ai = this.getGenerativeAI();
4453
const prompt = `
4554
You are a helper for an open source repository.
4655
Your task is to allow the user to categorize the issue with an "area: " label.

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ describe('IssueLabeling', () => {
3333
data: {
3434
title: 'Tough Issue',
3535
body: 'Complex Body',
36+
labels: [],
3637
},
3738
}),
3839
);
@@ -117,4 +118,19 @@ describe('IssueLabeling', () => {
117118
expect(issueLabeling).toBeDefined();
118119
expect(mockCore.getInput).not.toHaveBeenCalled(); // until run is called
119120
});
121+
122+
it('should skip labeling when issue already has an area label', async () => {
123+
mockGit.issues.get.and.resolveTo({
124+
data: {
125+
title: 'Tough Issue',
126+
body: 'Complex Body',
127+
labels: [{name: 'area: core'}],
128+
},
129+
});
130+
131+
await issueLabeling.run();
132+
133+
expect(mockGit.issues.addLabels).not.toHaveBeenCalled();
134+
expect(mockCore.info).toHaveBeenCalledWith('Issue already has an area label. Skipping.');
135+
});
120136
});

github-actions/issue-labeling/main.js

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

0 commit comments

Comments
 (0)