Skip to content

Commit 3e4418e

Browse files
JoannaaKLrentziass
andauthored
Issue 596/include only assigned (#817)
* Add new 'include-only-assigned' option If set, only issues containing assignees will be processed * Test new flag * Update code comment * Update src/classes/issues-processor.ts Co-authored-by: Francesco Renzi <[email protected]> * Update index.js with typo fix Co-authored-by: Francesco Renzi <[email protected]>
1 parent 33e3703 commit 3e4418e

File tree

7 files changed

+95
-4
lines changed

7 files changed

+95
-4
lines changed

__tests__/constants/default-processor-options.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,5 +51,6 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
5151
ignoreIssueUpdates: undefined,
5252
ignorePrUpdates: undefined,
5353
exemptDraftPr: false,
54-
closeIssueReason: ''
54+
closeIssueReason: '',
55+
includeOnlyAssigned: false
5556
});

__tests__/main.spec.ts

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2352,3 +2352,69 @@ test('processing a pull request to be stale with the "stalePrMessage" option set
23522352
expect(processor.closedIssues).toHaveLength(0);
23532353
expect(processor.statistics?.addedPullRequestsCommentsCount).toStrictEqual(0);
23542354
});
2355+
2356+
test('processing an issue with the "includeOnlyAssigned" option and nonempty assignee list will stale the issue', async () => {
2357+
const issueDate = new Date();
2358+
issueDate.setDate(issueDate.getDate() - 2);
2359+
2360+
const opts: IIssuesProcessorOptions = {
2361+
...DefaultProcessorOptions,
2362+
staleIssueLabel: 'This issue is stale',
2363+
includeOnlyAssigned: true
2364+
};
2365+
2366+
const TestIssueList: Issue[] = [
2367+
generateIssue(
2368+
opts,
2369+
1,
2370+
'An issue with no label',
2371+
issueDate.toDateString(),
2372+
issueDate.toDateString(),
2373+
false,
2374+
[],
2375+
false,
2376+
false,
2377+
undefined,
2378+
['assignee1']
2379+
)
2380+
];
2381+
const processor = new IssuesProcessorMock(
2382+
opts,
2383+
async p => (p === 1 ? TestIssueList : []),
2384+
async () => [],
2385+
async () => new Date().toDateString()
2386+
);
2387+
2388+
// process our fake issue list
2389+
await processor.processIssues(1);
2390+
2391+
expect(processor.staleIssues).toHaveLength(1);
2392+
expect(processor.closedIssues).toHaveLength(0);
2393+
});
2394+
2395+
test('processing an issue with the "includeOnlyAssigned" option set and no assignees will not stale the issue', async () => {
2396+
const issueDate = new Date();
2397+
issueDate.setDate(issueDate.getDate() - 2);
2398+
2399+
const opts: IIssuesProcessorOptions = {
2400+
...DefaultProcessorOptions,
2401+
staleIssueLabel: 'This issue is stale',
2402+
includeOnlyAssigned: true
2403+
};
2404+
2405+
const TestIssueList: Issue[] = [
2406+
generateIssue(opts, 1, 'An issue with no label', issueDate.toDateString())
2407+
];
2408+
const processor = new IssuesProcessorMock(
2409+
opts,
2410+
async p => (p === 1 ? TestIssueList : []),
2411+
async () => [],
2412+
async () => new Date().toDateString()
2413+
);
2414+
2415+
// process our fake issue list
2416+
await processor.processIssues(1);
2417+
2418+
expect(processor.staleIssues).toHaveLength(0);
2419+
expect(processor.closedIssues).toHaveLength(0);
2420+
});

dist/index.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,11 @@ class IssuesProcessor {
476476
IssuesProcessor._endIssueProcessing(issue);
477477
return; // Don't process locked issues
478478
}
479+
if (this._isIncludeOnlyAssigned(issue)) {
480+
issueLogger.info(`Skipping this $$type because its assignees list is empty`);
481+
IssuesProcessor._endIssueProcessing(issue);
482+
return; // If the issue has an 'include-only-assigned' option set, process only issues with nonempty assignees list
483+
}
479484
const onlyLabels = words_to_list_1.wordsToList(this._getOnlyLabels(issue));
480485
if (onlyLabels.length > 0) {
481486
issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.OnlyLabels)} was specified to only process issues and pull requests with all those labels (${logger_service_1.LoggerService.cyan(onlyLabels.length)})`);
@@ -988,6 +993,9 @@ class IssuesProcessor {
988993
}
989994
return this.options.onlyLabels;
990995
}
996+
_isIncludeOnlyAssigned(issue) {
997+
return this.options.includeOnlyAssigned && !issue.hasAssignees;
998+
}
991999
_getAnyOfLabels(issue) {
9921000
if (issue.isPullRequest) {
9931001
if (this.options.anyOfPrLabels !== '') {
@@ -2207,7 +2215,8 @@ function _getAndValidateArgs() {
22072215
ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'),
22082216
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
22092217
exemptDraftPr: core.getInput('exempt-draft-pr') === 'true',
2210-
closeIssueReason: core.getInput('close-issue-reason')
2218+
closeIssueReason: core.getInput('close-issue-reason'),
2219+
includeOnlyAssigned: core.getInput('include-only-assigned') === 'true'
22112220
};
22122221
for (const numberInput of [
22132222
'days-before-stale',

src/classes/issue.spec.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ describe('Issue', (): void => {
6262
ignoreIssueUpdates: undefined,
6363
ignorePrUpdates: undefined,
6464
exemptDraftPr: false,
65-
closeIssueReason: ''
65+
closeIssueReason: '',
66+
includeOnlyAssigned: false
6667
};
6768
issueInterface = {
6869
title: 'dummy-title',

src/classes/issues-processor.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ export class IssuesProcessor {
221221
return; // Don't process locked issues
222222
}
223223

224+
if (this._isIncludeOnlyAssigned(issue)) {
225+
issueLogger.info(
226+
`Skipping this $$type because its assignees list is empty`
227+
);
228+
IssuesProcessor._endIssueProcessing(issue);
229+
return; // If the issue has an 'include-only-assigned' option set, process only issues with nonempty assignees list
230+
}
231+
224232
const onlyLabels: string[] = wordsToList(this._getOnlyLabels(issue));
225233

226234
if (onlyLabels.length > 0) {
@@ -1012,6 +1020,10 @@ export class IssuesProcessor {
10121020
return this.options.onlyLabels;
10131021
}
10141022

1023+
private _isIncludeOnlyAssigned(issue: Issue): boolean {
1024+
return this.options.includeOnlyAssigned && !issue.hasAssignees;
1025+
}
1026+
10151027
private _getAnyOfLabels(issue: Issue): string {
10161028
if (issue.isPullRequest) {
10171029
if (this.options.anyOfPrLabels !== '') {

src/interfaces/issues-processor-options.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,5 @@ export interface IIssuesProcessorOptions {
5252
ignorePrUpdates: boolean | undefined;
5353
exemptDraftPr: boolean;
5454
closeIssueReason: string;
55+
includeOnlyAssigned: boolean;
5556
}

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
8888
ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'),
8989
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
9090
exemptDraftPr: core.getInput('exempt-draft-pr') === 'true',
91-
closeIssueReason: core.getInput('close-issue-reason')
91+
closeIssueReason: core.getInput('close-issue-reason'),
92+
includeOnlyAssigned: core.getInput('include-only-assigned') === 'true'
9293
};
9394

9495
for (const numberInput of [

0 commit comments

Comments
 (0)