mirror of
https://github.com/actions/stale.git
synced 2025-12-25 17:58:17 +00:00
Compare commits
2 Commits
handle_api
...
to_v3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c605ff6848 | ||
|
|
17e10153fc |
@@ -36,7 +36,7 @@ const DefaultProcessorOptions: IssueProcessorOptions = {
|
|||||||
staleIssueMessage: 'This issue is stale',
|
staleIssueMessage: 'This issue is stale',
|
||||||
stalePrMessage: 'This PR is stale',
|
stalePrMessage: 'This PR is stale',
|
||||||
daysBeforeStale: 1,
|
daysBeforeStale: 1,
|
||||||
daysBeforeClose: 30,
|
daysBeforeClose: 1,
|
||||||
staleIssueLabel: 'Stale',
|
staleIssueLabel: 'Stale',
|
||||||
exemptIssueLabels: '',
|
exemptIssueLabels: '',
|
||||||
stalePrLabel: 'Stale',
|
stalePrLabel: 'Stale',
|
||||||
@@ -62,60 +62,11 @@ test('empty issue list results in 1 operation', async () => {
|
|||||||
expect(operationsLeft).toEqual(99);
|
expect(operationsLeft).toEqual(99);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('processing an issue with no label will make it stale and close it, if it is old enough only if days-before-close is set to 0', async () => {
|
test('processing an issue with no label will make it stale', async () => {
|
||||||
const TestIssueList: Issue[] = [
|
const TestIssueList: Issue[] = [
|
||||||
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z')
|
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z')
|
||||||
];
|
];
|
||||||
|
|
||||||
const opts = {...DefaultProcessorOptions};
|
|
||||||
opts.daysBeforeClose = 0;
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
|
||||||
opts,
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
|
||||||
async (num, dt) => [],
|
|
||||||
async (issue, label) => new Date().toDateString()
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(1);
|
|
||||||
expect(processor.closedIssues.length).toEqual(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('processing an issue with no label will make it stale and not close it if days-before-close is set to > 0', async () => {
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z')
|
|
||||||
];
|
|
||||||
|
|
||||||
const opts = {...DefaultProcessorOptions};
|
|
||||||
opts.daysBeforeClose = 15;
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
|
||||||
DefaultProcessorOptions,
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
|
||||||
async (num, dt) => [],
|
|
||||||
async (issue, label) => new Date().toDateString()
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(1);
|
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('processing an issue with no label will make it stale but not close it', async () => {
|
|
||||||
// issue should be from 2 days ago so it will be
|
|
||||||
// stale but not close-able, based on default settings
|
|
||||||
let issueDate = new Date();
|
|
||||||
issueDate.setDate(issueDate.getDate() - 2);
|
|
||||||
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(1, 'An issue with no label', issueDate.toDateString())
|
|
||||||
];
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
@@ -451,7 +402,6 @@ test('exempt issue labels will not be marked stale (multi issue label)', async (
|
|||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('exempt pr labels will not be marked stale', async () => {
|
test('exempt pr labels will not be marked stale', async () => {
|
||||||
@@ -500,7 +450,6 @@ test('stale issues should not be closed if days is set to -1', async () => {
|
|||||||
await processor.processIssues(1);
|
await processor.processIssues(1);
|
||||||
|
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('stale label should be removed if a comment was added to a stale issue', async () => {
|
test('stale label should be removed if a comment was added to a stale issue', async () => {
|
||||||
@@ -520,7 +469,7 @@ test('stale label should be removed if a comment was added to a stale issue', as
|
|||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [{user: {login: 'notme', type: 'User'}}], // return a fake comment to indicate there was an update
|
async (num, dt) => [{user: {type: 'User'}}], // return a fake comment so indicate there was an update
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -531,127 +480,3 @@ test('stale label should be removed if a comment was added to a stale issue', as
|
|||||||
expect(processor.staleIssues.length).toEqual(0);
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
expect(processor.removedLabelIssues.length).toEqual(1);
|
expect(processor.removedLabelIssues.length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('stale label should not be removed if a comment was added by the bot (and the issue should be closed)', async () => {
|
|
||||||
github.context.actor = 'abot';
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(
|
|
||||||
1,
|
|
||||||
'An issue that should stay stale',
|
|
||||||
'2020-01-01T17:00:00Z',
|
|
||||||
false,
|
|
||||||
['Stale']
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
const opts = DefaultProcessorOptions;
|
|
||||||
opts.removeStaleWhenUpdated = true;
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
|
||||||
opts,
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
|
||||||
async (num, dt) => [{user: {login: 'abot', type: 'User'}}], // return a fake comment to indicate there was an update by the bot
|
|
||||||
async (issue, label) => new Date().toDateString()
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.closedIssues.length).toEqual(1);
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
|
||||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('stale issues should not be closed until after the closed number of days', async () => {
|
|
||||||
let lastUpdate = new Date();
|
|
||||||
lastUpdate.setDate(lastUpdate.getDate() - 5);
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(
|
|
||||||
1,
|
|
||||||
'An issue that should be marked stale but not closed',
|
|
||||||
lastUpdate.toString(),
|
|
||||||
false
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
const opts = DefaultProcessorOptions;
|
|
||||||
opts.daysBeforeStale = 5; // stale after 5 days
|
|
||||||
opts.daysBeforeClose = 1; // closes after 6 days
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
|
||||||
opts,
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
|
||||||
async (num, dt) => [],
|
|
||||||
async (issue, label) => new Date().toDateString()
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
|
||||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
|
||||||
expect(processor.staleIssues.length).toEqual(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('stale issues should be closed if the closed nubmer of days (additive) is also passed', async () => {
|
|
||||||
let lastUpdate = new Date();
|
|
||||||
lastUpdate.setDate(lastUpdate.getDate() - 7);
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(
|
|
||||||
1,
|
|
||||||
'An issue that should be stale and closed',
|
|
||||||
lastUpdate.toString(),
|
|
||||||
false,
|
|
||||||
['Stale']
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
const opts = DefaultProcessorOptions;
|
|
||||||
opts.daysBeforeStale = 5; // stale after 5 days
|
|
||||||
opts.daysBeforeClose = 1; // closes after 6 days
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
|
||||||
opts,
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
|
||||||
async (num, dt) => [],
|
|
||||||
async (issue, label) => new Date().toDateString()
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.closedIssues.length).toEqual(1);
|
|
||||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('stale issues should not be closed until after the closed number of days (long)', async () => {
|
|
||||||
let lastUpdate = new Date();
|
|
||||||
lastUpdate.setDate(lastUpdate.getDate() - 10);
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(
|
|
||||||
1,
|
|
||||||
'An issue that should be marked stale but not closed',
|
|
||||||
lastUpdate.toString(),
|
|
||||||
false
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
const opts = DefaultProcessorOptions;
|
|
||||||
opts.daysBeforeStale = 5; // stale after 5 days
|
|
||||||
opts.daysBeforeClose = 20; // closes after 25 days
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
|
||||||
opts,
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
|
||||||
async (num, dt) => [],
|
|
||||||
async (issue, label) => new Date().toDateString()
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
|
||||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
|
||||||
expect(processor.staleIssues.length).toEqual(1);
|
|
||||||
});
|
|
||||||
|
|||||||
2278
dist/index.js
vendored
2278
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
65
package-lock.json
generated
65
package-lock.json
generated
@@ -5,18 +5,53 @@
|
|||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.2.4",
|
"version": "1.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.4.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.3.tgz",
|
||||||
"integrity": "sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg=="
|
"integrity": "sha512-Wp4xnyokakM45Uuj4WLUxdsa8fJjKVl1fDTsPbTEcTcuu0Nb26IPQbOtjmnfaCPGcaoPOOqId8H9NapZ8gii4w=="
|
||||||
},
|
},
|
||||||
"@actions/github": {
|
"@actions/github": {
|
||||||
"version": "2.2.0",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/github/-/github-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/github/-/github-2.1.1.tgz",
|
||||||
"integrity": "sha512-9UAZqn8ywdR70n3GwVle4N8ALosQs4z50N7XMXrSTUVOmVpaBC5kE3TRTT7qQdi3OaQV24mjGuJZsHUmhD+ZXw==",
|
"integrity": "sha512-kAgTGUx7yf5KQCndVeHSwCNZuDBvPyxm5xKTswW2lofugeuC1AZX73nUUVDNaysnM9aKFMHv9YCdVJbg7syEyA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@actions/http-client": "^1.0.3",
|
"@actions/http-client": "^1.0.3",
|
||||||
"@octokit/graphql": "^4.3.1",
|
"@octokit/graphql": "^4.3.1",
|
||||||
"@octokit/rest": "^16.43.1"
|
"@octokit/rest": "^16.43.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@octokit/request-error": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-+6yDyk1EES6WK+l3viRDElw96MvwfJxCt45GvmjDUKWjYIb3PJZQkq3i46TwGwoPD4h8NmTrENmtyA1FwbmhRA==",
|
||||||
|
"requires": {
|
||||||
|
"@octokit/types": "^2.0.0",
|
||||||
|
"deprecation": "^2.0.0",
|
||||||
|
"once": "^1.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@octokit/rest": {
|
||||||
|
"version": "16.43.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-16.43.1.tgz",
|
||||||
|
"integrity": "sha512-gfFKwRT/wFxq5qlNjnW2dh+qh74XgTQ2B179UX5K1HYCluioWj8Ndbgqw2PVqa1NnVJkGHp2ovMpVn/DImlmkw==",
|
||||||
|
"requires": {
|
||||||
|
"@octokit/auth-token": "^2.4.0",
|
||||||
|
"@octokit/plugin-paginate-rest": "^1.1.1",
|
||||||
|
"@octokit/plugin-request-log": "^1.0.0",
|
||||||
|
"@octokit/plugin-rest-endpoint-methods": "2.4.0",
|
||||||
|
"@octokit/request": "^5.2.0",
|
||||||
|
"@octokit/request-error": "^1.0.2",
|
||||||
|
"atob-lite": "^2.0.0",
|
||||||
|
"before-after-hook": "^2.0.0",
|
||||||
|
"btoa-lite": "^1.0.0",
|
||||||
|
"deprecation": "^2.0.0",
|
||||||
|
"lodash.get": "^4.4.2",
|
||||||
|
"lodash.set": "^4.3.2",
|
||||||
|
"lodash.uniq": "^4.5.0",
|
||||||
|
"octokit-pagination-methods": "^1.1.0",
|
||||||
|
"once": "^1.4.0",
|
||||||
|
"universal-user-agent": "^4.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@actions/http-client": {
|
"@actions/http-client": {
|
||||||
@@ -522,23 +557,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@octokit/graphql": {
|
"@octokit/graphql": {
|
||||||
"version": "4.4.0",
|
"version": "4.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.3.1.tgz",
|
||||||
"integrity": "sha512-Du3hAaSROQ8EatmYoSAJjzAz3t79t9Opj/WY1zUgxVUGfIKn0AEjg+hlOLscF6fv6i/4y/CeUvsWgIfwMkTccw==",
|
"integrity": "sha512-hCdTjfvrK+ilU2keAdqNBWOk+gm1kai1ZcdjRfB30oA3/T6n53UVJb7w0L5cR3/rhU91xT3HSqCd+qbvH06yxA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@octokit/request": "^5.3.0",
|
"@octokit/request": "^5.3.0",
|
||||||
"@octokit/types": "^2.0.0",
|
"@octokit/types": "^2.0.0",
|
||||||
"universal-user-agent": "^5.0.0"
|
"universal-user-agent": "^4.0.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"universal-user-agent": {
|
|
||||||
"version": "5.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-5.0.0.tgz",
|
|
||||||
"integrity": "sha512-B5TPtzZleXyPrUMKCpEHFmVhMN6EhmJYjG5PQna9s7mXeSqGTLap4OpqLl5FCEFUI3UBmllkETwKf/db66Y54Q==",
|
|
||||||
"requires": {
|
|
||||||
"os-name": "^3.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@octokit/plugin-paginate-rest": {
|
"@octokit/plugin-paginate-rest": {
|
||||||
|
|||||||
@@ -25,7 +25,7 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.4",
|
"@actions/core": "^1.2.3",
|
||||||
"@actions/github": "^2.2.0",
|
"@actions/github": "^2.2.0",
|
||||||
"@octokit/rest": "^16.43.1",
|
"@octokit/rest": "^16.43.1",
|
||||||
"semver": "^6.1.1"
|
"semver": "^6.1.1"
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ export interface Issue {
|
|||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
type: string;
|
type: string;
|
||||||
login: string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Comment {
|
export interface Comment {
|
||||||
@@ -68,10 +67,7 @@ export class IssueProcessor {
|
|||||||
issueNumber: number,
|
issueNumber: number,
|
||||||
sinceDate: string
|
sinceDate: string
|
||||||
) => Promise<Comment[]>,
|
) => Promise<Comment[]>,
|
||||||
getLabelCreationDate?: (
|
getLabelCreationDate?: (issue: Issue, label: string) => Promise<string>
|
||||||
issue: Issue,
|
|
||||||
label: string
|
|
||||||
) => Promise<string | undefined>
|
|
||||||
) {
|
) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.operationsLeft = options.operationsPerRun;
|
this.operationsLeft = options.operationsPerRun;
|
||||||
@@ -97,19 +93,24 @@ export class IssueProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async processIssues(page: number = 1): Promise<number> {
|
async processIssues(page: number = 1): Promise<number> {
|
||||||
|
if (this.operationsLeft <= 0) {
|
||||||
|
core.warning('Reached max number of operations to process. Exiting.');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
// get the next batch of issues
|
// get the next batch of issues
|
||||||
const issues: Issue[] = await this.getIssues(page);
|
const issues: Issue[] = await this.getIssues(page);
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
if (issues.length <= 0) {
|
if (issues.length <= 0) {
|
||||||
core.info('No more issues found to process. Exiting.');
|
core.debug('No more issues found to process. Exiting.');
|
||||||
return this.operationsLeft;
|
return this.operationsLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const issue of issues.values()) {
|
for (const issue of issues.values()) {
|
||||||
const isPr = !!issue.pull_request;
|
const isPr = !!issue.pull_request;
|
||||||
|
|
||||||
core.info(
|
core.debug(
|
||||||
`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`
|
`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -126,17 +127,17 @@ export class IssueProcessor {
|
|||||||
const issueType: string = isPr ? 'pr' : 'issue';
|
const issueType: string = isPr ? 'pr' : 'issue';
|
||||||
|
|
||||||
if (!staleMessage) {
|
if (!staleMessage) {
|
||||||
core.info(`Skipping ${issueType} due to empty stale message`);
|
core.debug(`Skipping ${issueType} due to empty stale message`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (issue.state === 'closed') {
|
if (issue.state === 'closed') {
|
||||||
core.info(`Skipping ${issueType} because it is closed`);
|
core.debug(`Skipping ${issueType} because it is closed`);
|
||||||
continue; // don't process closed issues
|
continue; // don't process closed issues
|
||||||
}
|
}
|
||||||
|
|
||||||
if (issue.locked) {
|
if (issue.locked) {
|
||||||
core.info(`Skipping ${issueType} because it is locked`);
|
core.debug(`Skipping ${issueType} because it is locked`);
|
||||||
continue; // don't process locked issues
|
continue; // don't process locked issues
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,38 +146,25 @@ export class IssueProcessor {
|
|||||||
IssueProcessor.isLabeled(issue, exemptLabel)
|
IssueProcessor.isLabeled(issue, exemptLabel)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
core.info(`Skipping ${issueType} because it has an exempt label`);
|
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
||||||
continue; // don't process exempt issues
|
continue; // don't process exempt issues
|
||||||
}
|
}
|
||||||
|
|
||||||
// does this issue have a stale label?
|
if (IssueProcessor.isLabeled(issue, staleLabel)) {
|
||||||
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
core.debug(`Found a stale ${issueType}`);
|
||||||
|
await this.processStaleIssue(issue, issueType, staleLabel);
|
||||||
// should this issue be marked stale?
|
} else if (
|
||||||
const shouldBeStale = !IssueProcessor.updatedSince(
|
!IssueProcessor.updatedSince(
|
||||||
issue.updated_at,
|
issue.updated_at,
|
||||||
this.options.daysBeforeStale
|
this.options.daysBeforeStale
|
||||||
);
|
)
|
||||||
|
) {
|
||||||
// determine if this issue needs to be marked stale first
|
core.debug(
|
||||||
if (!isStale && shouldBeStale) {
|
`Marking ${issueType} stale because it was last updated on ${issue.updated_at}`
|
||||||
core.info(
|
|
||||||
`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`
|
|
||||||
);
|
);
|
||||||
await this.markStale(issue, staleMessage, staleLabel);
|
await this.markStale(issue, staleMessage, staleLabel);
|
||||||
isStale = true; // this issue is now considered stale
|
this.operationsLeft -= 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
// process the issue if it was marked stale
|
|
||||||
if (isStale) {
|
|
||||||
core.info(`Found a stale ${issueType}`);
|
|
||||||
await this.processStaleIssue(issue, issueType, staleLabel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.operationsLeft <= 0) {
|
|
||||||
core.warning('Reached max number of operations to process. Exiting.');
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the next batch
|
// do the next batch
|
||||||
@@ -189,77 +177,63 @@ export class IssueProcessor {
|
|||||||
issueType: string,
|
issueType: string,
|
||||||
staleLabel: string
|
staleLabel: string
|
||||||
) {
|
) {
|
||||||
const markedStaleOn: string =
|
if (this.options.daysBeforeClose < 0) {
|
||||||
(await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
return; // nothing to do because we aren't closing stale issues
|
||||||
core.info(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
}
|
||||||
|
|
||||||
const issueHasComments: boolean = await this.hasCommentsSince(
|
const markedStaleOn: string = await this.getLabelCreationDate(
|
||||||
|
issue,
|
||||||
|
staleLabel
|
||||||
|
);
|
||||||
|
const issueHasComments: boolean = await this.isIssueStillStale(
|
||||||
issue,
|
issue,
|
||||||
markedStaleOn
|
markedStaleOn
|
||||||
);
|
);
|
||||||
core.info(
|
|
||||||
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
|
||||||
);
|
|
||||||
|
|
||||||
const issueHasUpdate: boolean = IssueProcessor.updatedSince(
|
const issueHasUpdate: boolean = IssueProcessor.updatedSince(
|
||||||
issue.updated_at,
|
issue.updated_at,
|
||||||
this.options.daysBeforeClose
|
this.options.daysBeforeClose
|
||||||
);
|
);
|
||||||
core.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
|
||||||
|
|
||||||
// should we un-stale this issue?
|
core.debug(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
||||||
if (this.options.removeStaleWhenUpdated && issueHasComments) {
|
core.debug(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||||
core.info(
|
core.debug(
|
||||||
`Issue #${issue.number} is no longer stale. Removing stale label.`
|
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
||||||
);
|
);
|
||||||
await this.removeLabel(issue, staleLabel);
|
|
||||||
}
|
|
||||||
|
|
||||||
// now start closing logic
|
|
||||||
if (this.options.daysBeforeClose < 0) {
|
|
||||||
return; // nothing to do because we aren't closing stale issues
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!issueHasComments && !issueHasUpdate) {
|
if (!issueHasComments && !issueHasUpdate) {
|
||||||
core.info(
|
core.debug(
|
||||||
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
|
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
|
||||||
);
|
);
|
||||||
await this.closeIssue(issue);
|
await this.closeIssue(issue);
|
||||||
} else {
|
} else {
|
||||||
core.info(
|
if (this.options.removeStaleWhenUpdated) {
|
||||||
`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`
|
await this.removeLabel(issue, staleLabel);
|
||||||
);
|
}
|
||||||
|
core.debug(`Ignoring stale ${issueType} because it was updated recenlty`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// checks to see if a given issue is still stale (has had activity on it)
|
// checks to see if a given issue is still stale (has had activity on it)
|
||||||
private async hasCommentsSince(
|
private async isIssueStillStale(
|
||||||
issue: Issue,
|
issue: Issue,
|
||||||
sinceDate: string
|
sinceDate: string
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
core.info(
|
core.debug(
|
||||||
`Checking for comments on issue #${issue.number} since ${sinceDate}`
|
`Checking for comments on issue #${issue.number} since ${sinceDate} to see if it is still stale`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!sinceDate) {
|
if (!sinceDate) {
|
||||||
return true;
|
return true; // if no date was provided then the issue was marked stale a long time ago
|
||||||
}
|
}
|
||||||
|
|
||||||
// find any comments since the date
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
|
// find any comments since the stale label
|
||||||
const comments = await this.listIssueComments(issue.number, sinceDate);
|
const comments = await this.listIssueComments(issue.number, sinceDate);
|
||||||
|
|
||||||
const filteredComments = comments.filter(
|
// if there are any user comments returned, issue is not stale anymore
|
||||||
comment =>
|
return comments.filter(comment => comment.user.type === 'User').length > 0;
|
||||||
comment.user.type === 'User' &&
|
|
||||||
comment.user.login !== github.context.actor
|
|
||||||
);
|
|
||||||
|
|
||||||
core.info(
|
|
||||||
`Comments not made by ${github.context.actor} or another bot: ${filteredComments.length}`
|
|
||||||
);
|
|
||||||
|
|
||||||
// if there are any user comments returned
|
|
||||||
return filteredComments.length > 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab comments for an issue since a given date
|
// grab comments for an issue since a given date
|
||||||
@@ -268,38 +242,28 @@ export class IssueProcessor {
|
|||||||
sinceDate: string
|
sinceDate: string
|
||||||
): Promise<Comment[]> {
|
): Promise<Comment[]> {
|
||||||
// find any comments since date on the given issue
|
// find any comments since date on the given issue
|
||||||
try {
|
const comments = await this.client.issues.listComments({
|
||||||
const comments = await this.client.issues.listComments({
|
owner: github.context.repo.owner,
|
||||||
owner: github.context.repo.owner,
|
repo: github.context.repo.repo,
|
||||||
repo: github.context.repo.repo,
|
issue_number: issueNumber,
|
||||||
issue_number: issueNumber,
|
since: sinceDate
|
||||||
since: sinceDate
|
});
|
||||||
});
|
|
||||||
return comments.data;
|
return comments.data;
|
||||||
} catch (error) {
|
|
||||||
core.error(`List issue comments error: ${error.message}`);
|
|
||||||
return Promise.resolve([]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab issues from github in baches of 100
|
// grab issues from github in baches of 100
|
||||||
private async getIssues(page: number): Promise<Issue[]> {
|
private async getIssues(page: number): Promise<Issue[]> {
|
||||||
try {
|
const issueResult: OctoKitIssueList = await this.client.issues.listForRepo({
|
||||||
const issueResult: OctoKitIssueList = await this.client.issues.listForRepo(
|
owner: github.context.repo.owner,
|
||||||
{
|
repo: github.context.repo.repo,
|
||||||
owner: github.context.repo.owner,
|
state: 'open',
|
||||||
repo: github.context.repo.repo,
|
labels: this.options.onlyLabels,
|
||||||
state: 'open',
|
per_page: 100,
|
||||||
labels: this.options.onlyLabels,
|
page
|
||||||
per_page: 100,
|
});
|
||||||
page
|
|
||||||
}
|
return issueResult.data;
|
||||||
);
|
|
||||||
return issueResult.data;
|
|
||||||
} catch (error) {
|
|
||||||
core.error(`Get issues for repo error: ${error.message}`);
|
|
||||||
return Promise.resolve([]);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark an issue as stale with a comment and a label
|
// Mark an issue as stale with a comment and a label
|
||||||
@@ -308,47 +272,34 @@ export class IssueProcessor {
|
|||||||
staleMessage: string,
|
staleMessage: string,
|
||||||
staleLabel: string
|
staleLabel: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
core.info(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
core.debug(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
||||||
|
|
||||||
this.staleIssues.push(issue);
|
this.staleIssues.push(issue);
|
||||||
|
|
||||||
this.operationsLeft -= 2;
|
this.operationsLeft -= 2;
|
||||||
|
|
||||||
// if the issue is being marked stale, the updated date should be changed to right now
|
|
||||||
// so that close calculations work correctly
|
|
||||||
const newUpdatedAtDate: Date = new Date();
|
|
||||||
issue.updated_at = newUpdatedAtDate.toString();
|
|
||||||
|
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
await this.client.issues.createComment({
|
||||||
await this.client.issues.createComment({
|
owner: github.context.repo.owner,
|
||||||
owner: github.context.repo.owner,
|
repo: github.context.repo.repo,
|
||||||
repo: github.context.repo.repo,
|
issue_number: issue.number,
|
||||||
issue_number: issue.number,
|
body: staleMessage
|
||||||
body: staleMessage
|
});
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
core.error(`Error creating a comment: ${error.message}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
await this.client.issues.addLabels({
|
||||||
await this.client.issues.addLabels({
|
owner: github.context.repo.owner,
|
||||||
owner: github.context.repo.owner,
|
repo: github.context.repo.repo,
|
||||||
repo: github.context.repo.repo,
|
issue_number: issue.number,
|
||||||
issue_number: issue.number,
|
labels: [staleLabel]
|
||||||
labels: [staleLabel]
|
});
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
core.error(`Error adding a label: ${error.message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close an issue based on staleness
|
// Close an issue based on staleness
|
||||||
private async closeIssue(issue: Issue): Promise<void> {
|
private async closeIssue(issue: Issue): Promise<void> {
|
||||||
core.info(
|
core.debug(
|
||||||
`Closing issue #${issue.number} - ${issue.title} for being stale`
|
`Closing issue #${issue.number} - ${issue.title} for being stale`
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -360,21 +311,17 @@ export class IssueProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
await this.client.issues.update({
|
||||||
await this.client.issues.update({
|
owner: github.context.repo.owner,
|
||||||
owner: github.context.repo.owner,
|
repo: github.context.repo.repo,
|
||||||
repo: github.context.repo.repo,
|
issue_number: issue.number,
|
||||||
issue_number: issue.number,
|
state: 'closed'
|
||||||
state: 'closed'
|
});
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
core.error(`Error updating an issue: ${error.message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove a label from an issue
|
// Remove a label from an issue
|
||||||
private async removeLabel(issue: Issue, label: string): Promise<void> {
|
private async removeLabel(issue: Issue, label: string): Promise<void> {
|
||||||
core.info(
|
core.debug(
|
||||||
`Removing label ${label} from issue #${issue.number} - ${issue.title}`
|
`Removing label ${label} from issue #${issue.number} - ${issue.title}`
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -386,16 +333,12 @@ export class IssueProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
await this.client.issues.removeLabel({
|
||||||
await this.client.issues.removeLabel({
|
owner: github.context.repo.owner,
|
||||||
owner: github.context.repo.owner,
|
repo: github.context.repo.repo,
|
||||||
repo: github.context.repo.repo,
|
issue_number: issue.number,
|
||||||
issue_number: issue.number,
|
name: encodeURIComponent(label) // A label can have a "?" in the name
|
||||||
name: encodeURIComponent(label) // A label can have a "?" in the name
|
});
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
core.error(`Error removing a label: ${error.message}`);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns the creation date of a given label on an issue (or nothing if no label existed)
|
// returns the creation date of a given label on an issue (or nothing if no label existed)
|
||||||
@@ -403,8 +346,8 @@ export class IssueProcessor {
|
|||||||
private async getLabelCreationDate(
|
private async getLabelCreationDate(
|
||||||
issue: Issue,
|
issue: Issue,
|
||||||
label: string
|
label: string
|
||||||
): Promise<string | undefined> {
|
): Promise<string> {
|
||||||
core.info(`Checking for label ${label} on issue #${issue.number}`);
|
core.debug(`Checking for label ${label} on issue #${issue.number}`);
|
||||||
|
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
@@ -422,12 +365,7 @@ export class IssueProcessor {
|
|||||||
event => event.event === 'labeled' && event.label.name === label
|
event => event.event === 'labeled' && event.label.name === label
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!staleLabeledEvent) {
|
return staleLabeledEvent!.created_at;
|
||||||
// Must be old rather than labeled
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
return staleLabeledEvent.created_at;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static isLabeled(issue: Issue, label: string): boolean {
|
private static isLabeled(issue: Issue, label: string): boolean {
|
||||||
@@ -441,7 +379,7 @@ export class IssueProcessor {
|
|||||||
const millisSinceLastUpdated =
|
const millisSinceLastUpdated =
|
||||||
new Date().getTime() - new Date(timestamp).getTime();
|
new Date().getTime() - new Date(timestamp).getTime();
|
||||||
|
|
||||||
return millisSinceLastUpdated <= daysInMillis;
|
return millisSinceLastUpdated < daysInMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static parseCommaSeparatedString(s: string): string[] {
|
private static parseCommaSeparatedString(s: string): string[] {
|
||||||
|
|||||||
Reference in New Issue
Block a user