mirror of
https://github.com/actions/stale.git
synced 2025-12-25 09:58:16 +00:00
Compare commits
7 Commits
v3.0.1
...
handle_api
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
06fc759d9f | ||
|
|
65bccdf399 | ||
|
|
c72e3d7ff2 | ||
|
|
db0a20585c | ||
|
|
b6f9559915 | ||
|
|
96b682d29f | ||
|
|
5ce6b77f2c |
@@ -62,11 +62,36 @@ 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', async () => {
|
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 () => {
|
||||||
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(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
@@ -78,7 +103,7 @@ test('processing an issue with no label will make it stale and close it, if it i
|
|||||||
await processor.processIssues(1);
|
await processor.processIssues(1);
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(1);
|
expect(processor.staleIssues.length).toEqual(1);
|
||||||
expect(processor.closedIssues.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 () => {
|
test('processing an issue with no label will make it stale but not close it', async () => {
|
||||||
@@ -426,6 +451,7 @@ 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 () => {
|
||||||
@@ -474,6 +500,7 @@ 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 () => {
|
||||||
@@ -493,7 +520,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: {type: 'User'}}], // return a fake comment so indicate there was an update
|
async (num, dt) => [{user: {login: 'notme', type: 'User'}}], // return a fake comment to indicate there was an update
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -504,3 +531,127 @@ 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);
|
||||||
|
});
|
||||||
|
|||||||
206
dist/index.js
vendored
206
dist/index.js
vendored
@@ -3596,7 +3596,7 @@ exports.getUserAgent = getUserAgent;
|
|||||||
/***/ 215:
|
/***/ 215:
|
||||||
/***/ (function(module) {
|
/***/ (function(module) {
|
||||||
|
|
||||||
module.exports = {"_args":[["@octokit/rest@16.43.1","/Users/pjquirk/Source/GitHub/pjquirk/stale"]],"_from":"@octokit/rest@16.43.1","_id":"@octokit/rest@16.43.1","_inBundle":false,"_integrity":"sha512-gfFKwRT/wFxq5qlNjnW2dh+qh74XgTQ2B179UX5K1HYCluioWj8Ndbgqw2PVqa1NnVJkGHp2ovMpVn/DImlmkw==","_location":"/@octokit/rest","_phantomChildren":{"@octokit/types":"2.8.2","deprecation":"2.3.1","once":"1.4.0"},"_requested":{"type":"version","registry":true,"raw":"@octokit/rest@16.43.1","name":"@octokit/rest","escapedName":"@octokit%2frest","scope":"@octokit","rawSpec":"16.43.1","saveSpec":null,"fetchSpec":"16.43.1"},"_requiredBy":["/","/@actions/github"],"_resolved":"https://registry.npmjs.org/@octokit/rest/-/rest-16.43.1.tgz","_spec":"16.43.1","_where":"/Users/pjquirk/Source/GitHub/pjquirk/stale","author":{"name":"Gregor Martynus","url":"https://github.com/gr2m"},"bugs":{"url":"https://github.com/octokit/rest.js/issues"},"bundlesize":[{"path":"./dist/octokit-rest.min.js.gz","maxSize":"33 kB"}],"contributors":[{"name":"Mike de Boer","email":"info@mikedeboer.nl"},{"name":"Fabian Jakobs","email":"fabian@c9.io"},{"name":"Joe Gallo","email":"joe@brassafrax.com"},{"name":"Gregor Martynus","url":"https://github.com/gr2m"}],"dependencies":{"@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"},"description":"GitHub REST API client for Node.js","devDependencies":{"@gimenete/type-writer":"^0.1.3","@octokit/auth":"^1.1.1","@octokit/fixtures-server":"^5.0.6","@octokit/graphql":"^4.2.0","@types/node":"^13.1.0","bundlesize":"^0.18.0","chai":"^4.1.2","compression-webpack-plugin":"^3.1.0","cypress":"^3.0.0","glob":"^7.1.2","http-proxy-agent":"^4.0.0","lodash.camelcase":"^4.3.0","lodash.merge":"^4.6.1","lodash.upperfirst":"^4.3.1","lolex":"^5.1.2","mkdirp":"^1.0.0","mocha":"^7.0.1","mustache":"^4.0.0","nock":"^11.3.3","npm-run-all":"^4.1.2","nyc":"^15.0.0","prettier":"^1.14.2","proxy":"^1.0.0","semantic-release":"^17.0.0","sinon":"^8.0.0","sinon-chai":"^3.0.0","sort-keys":"^4.0.0","string-to-arraybuffer":"^1.0.0","string-to-jsdoc-comment":"^1.0.0","typescript":"^3.3.1","webpack":"^4.0.0","webpack-bundle-analyzer":"^3.0.0","webpack-cli":"^3.0.0"},"files":["index.js","index.d.ts","lib","plugins"],"homepage":"https://github.com/octokit/rest.js#readme","keywords":["octokit","github","rest","api-client"],"license":"MIT","name":"@octokit/rest","nyc":{"ignore":["test"]},"publishConfig":{"access":"public"},"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"repository":{"type":"git","url":"git+https://github.com/octokit/rest.js.git"},"scripts":{"build":"npm-run-all build:*","build:browser":"npm-run-all build:browser:*","build:browser:development":"webpack --mode development --entry . --output-library=Octokit --output=./dist/octokit-rest.js --profile --json > dist/bundle-stats.json","build:browser:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=Octokit --output-path=./dist --output-filename=octokit-rest.min.js --devtool source-map","build:ts":"npm run -s update-endpoints:typescript","coverage":"nyc report --reporter=html && open coverage/index.html","generate-bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","lint":"prettier --check '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","lint:fix":"prettier --write '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","postvalidate:ts":"tsc --noEmit --target es6 test/typescript-validate.ts","prebuild:browser":"mkdirp dist/","pretest":"npm run -s lint","prevalidate:ts":"npm run -s build:ts","start-fixtures-server":"octokit-fixtures-server","test":"nyc mocha test/mocha-node-setup.js \"test/*/**/*-test.js\"","test:browser":"cypress run --browser chrome","update-endpoints":"npm-run-all update-endpoints:*","update-endpoints:fetch-json":"node scripts/update-endpoints/fetch-json","update-endpoints:typescript":"node scripts/update-endpoints/typescript","validate:ts":"tsc --target es6 --noImplicitAny index.d.ts"},"types":"index.d.ts","version":"16.43.1"};
|
module.exports = {"_args":[["@octokit/rest@16.43.1","/Users/hross/Code/stale"]],"_from":"@octokit/rest@16.43.1","_id":"@octokit/rest@16.43.1","_inBundle":false,"_integrity":"sha512-gfFKwRT/wFxq5qlNjnW2dh+qh74XgTQ2B179UX5K1HYCluioWj8Ndbgqw2PVqa1NnVJkGHp2ovMpVn/DImlmkw==","_location":"/@octokit/rest","_phantomChildren":{"@octokit/types":"2.8.2","deprecation":"2.3.1","once":"1.4.0"},"_requested":{"type":"version","registry":true,"raw":"@octokit/rest@16.43.1","name":"@octokit/rest","escapedName":"@octokit%2frest","scope":"@octokit","rawSpec":"16.43.1","saveSpec":null,"fetchSpec":"16.43.1"},"_requiredBy":["/","/@actions/github"],"_resolved":"https://registry.npmjs.org/@octokit/rest/-/rest-16.43.1.tgz","_spec":"16.43.1","_where":"/Users/hross/Code/stale","author":{"name":"Gregor Martynus","url":"https://github.com/gr2m"},"bugs":{"url":"https://github.com/octokit/rest.js/issues"},"bundlesize":[{"path":"./dist/octokit-rest.min.js.gz","maxSize":"33 kB"}],"contributors":[{"name":"Mike de Boer","email":"info@mikedeboer.nl"},{"name":"Fabian Jakobs","email":"fabian@c9.io"},{"name":"Joe Gallo","email":"joe@brassafrax.com"},{"name":"Gregor Martynus","url":"https://github.com/gr2m"}],"dependencies":{"@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"},"description":"GitHub REST API client for Node.js","devDependencies":{"@gimenete/type-writer":"^0.1.3","@octokit/auth":"^1.1.1","@octokit/fixtures-server":"^5.0.6","@octokit/graphql":"^4.2.0","@types/node":"^13.1.0","bundlesize":"^0.18.0","chai":"^4.1.2","compression-webpack-plugin":"^3.1.0","cypress":"^3.0.0","glob":"^7.1.2","http-proxy-agent":"^4.0.0","lodash.camelcase":"^4.3.0","lodash.merge":"^4.6.1","lodash.upperfirst":"^4.3.1","lolex":"^5.1.2","mkdirp":"^1.0.0","mocha":"^7.0.1","mustache":"^4.0.0","nock":"^11.3.3","npm-run-all":"^4.1.2","nyc":"^15.0.0","prettier":"^1.14.2","proxy":"^1.0.0","semantic-release":"^17.0.0","sinon":"^8.0.0","sinon-chai":"^3.0.0","sort-keys":"^4.0.0","string-to-arraybuffer":"^1.0.0","string-to-jsdoc-comment":"^1.0.0","typescript":"^3.3.1","webpack":"^4.0.0","webpack-bundle-analyzer":"^3.0.0","webpack-cli":"^3.0.0"},"files":["index.js","index.d.ts","lib","plugins"],"homepage":"https://github.com/octokit/rest.js#readme","keywords":["octokit","github","rest","api-client"],"license":"MIT","name":"@octokit/rest","nyc":{"ignore":["test"]},"publishConfig":{"access":"public"},"release":{"publish":["@semantic-release/npm",{"path":"@semantic-release/github","assets":["dist/*","!dist/*.map.gz"]}]},"repository":{"type":"git","url":"git+https://github.com/octokit/rest.js.git"},"scripts":{"build":"npm-run-all build:*","build:browser":"npm-run-all build:browser:*","build:browser:development":"webpack --mode development --entry . --output-library=Octokit --output=./dist/octokit-rest.js --profile --json > dist/bundle-stats.json","build:browser:production":"webpack --mode production --entry . --plugin=compression-webpack-plugin --output-library=Octokit --output-path=./dist --output-filename=octokit-rest.min.js --devtool source-map","build:ts":"npm run -s update-endpoints:typescript","coverage":"nyc report --reporter=html && open coverage/index.html","generate-bundle-report":"webpack-bundle-analyzer dist/bundle-stats.json --mode=static --no-open --report dist/bundle-report.html","lint":"prettier --check '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","lint:fix":"prettier --write '{lib,plugins,scripts,test}/**/*.{js,json,ts}' 'docs/*.{js,json}' 'docs/src/**/*' index.js README.md package.json","postvalidate:ts":"tsc --noEmit --target es6 test/typescript-validate.ts","prebuild:browser":"mkdirp dist/","pretest":"npm run -s lint","prevalidate:ts":"npm run -s build:ts","start-fixtures-server":"octokit-fixtures-server","test":"nyc mocha test/mocha-node-setup.js \"test/*/**/*-test.js\"","test:browser":"cypress run --browser chrome","update-endpoints":"npm-run-all update-endpoints:*","update-endpoints:fetch-json":"node scripts/update-endpoints/fetch-json","update-endpoints:typescript":"node scripts/update-endpoints/typescript","validate:ts":"tsc --target es6 --noImplicitAny index.d.ts"},"types":"index.d.ts","version":"16.43.1"};
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
@@ -8649,20 +8649,16 @@ class IssueProcessor {
|
|||||||
}
|
}
|
||||||
processIssues(page = 1) {
|
processIssues(page = 1) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
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 = yield this.getIssues(page);
|
const issues = yield this.getIssues(page);
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
if (issues.length <= 0) {
|
if (issues.length <= 0) {
|
||||||
core.debug('No more issues found to process. Exiting.');
|
core.info('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.debug(`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`);
|
core.info(`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`);
|
||||||
// calculate string based messages for this issue
|
// calculate string based messages for this issue
|
||||||
const staleMessage = isPr
|
const staleMessage = isPr
|
||||||
? this.options.stalePrMessage
|
? this.options.stalePrMessage
|
||||||
@@ -8673,37 +8669,41 @@ class IssueProcessor {
|
|||||||
const exemptLabels = IssueProcessor.parseCommaSeparatedString(isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels);
|
const exemptLabels = IssueProcessor.parseCommaSeparatedString(isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels);
|
||||||
const issueType = isPr ? 'pr' : 'issue';
|
const issueType = isPr ? 'pr' : 'issue';
|
||||||
if (!staleMessage) {
|
if (!staleMessage) {
|
||||||
core.debug(`Skipping ${issueType} due to empty stale message`);
|
core.info(`Skipping ${issueType} due to empty stale message`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (issue.state === 'closed') {
|
if (issue.state === 'closed') {
|
||||||
core.debug(`Skipping ${issueType} because it is closed`);
|
core.info(`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.debug(`Skipping ${issueType} because it is locked`);
|
core.info(`Skipping ${issueType} because it is locked`);
|
||||||
continue; // don't process locked issues
|
continue; // don't process locked issues
|
||||||
}
|
}
|
||||||
if (exemptLabels.some((exemptLabel) => IssueProcessor.isLabeled(issue, exemptLabel))) {
|
if (exemptLabels.some((exemptLabel) => IssueProcessor.isLabeled(issue, exemptLabel))) {
|
||||||
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
core.info(`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?
|
// does this issue have a stale label?
|
||||||
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
||||||
|
// should this issue be marked stale?
|
||||||
|
const shouldBeStale = !IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale);
|
||||||
// determine if this issue needs to be marked stale first
|
// determine if this issue needs to be marked stale first
|
||||||
if (!isStale &&
|
if (!isStale && shouldBeStale) {
|
||||||
!IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale)) {
|
core.info(`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`);
|
||||||
core.debug(`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`);
|
|
||||||
yield this.markStale(issue, staleMessage, staleLabel);
|
yield this.markStale(issue, staleMessage, staleLabel);
|
||||||
this.operationsLeft -= 2;
|
|
||||||
isStale = true; // this issue is now considered stale
|
isStale = true; // this issue is now considered stale
|
||||||
}
|
}
|
||||||
// process any issues marked stale (including the issue above, if it was marked)
|
// process the issue if it was marked stale
|
||||||
if (isStale) {
|
if (isStale) {
|
||||||
core.debug(`Found a stale ${issueType}`);
|
core.info(`Found a stale ${issueType}`);
|
||||||
yield this.processStaleIssue(issue, issueType, staleLabel);
|
yield 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
|
||||||
return this.processIssues(page + 1);
|
return this.processIssues(page + 1);
|
||||||
});
|
});
|
||||||
@@ -8711,135 +8711,171 @@ class IssueProcessor {
|
|||||||
// handle all of the stale issue logic when we find a stale issue
|
// handle all of the stale issue logic when we find a stale issue
|
||||||
processStaleIssue(issue, issueType, staleLabel) {
|
processStaleIssue(issue, issueType, staleLabel) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const markedStaleOn = (yield this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
||||||
|
core.info(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
||||||
|
const issueHasComments = yield this.hasCommentsSince(issue, markedStaleOn);
|
||||||
|
core.info(`Issue #${issue.number} has been commented on: ${issueHasComments}`);
|
||||||
|
const issueHasUpdate = IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeClose);
|
||||||
|
core.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||||
|
// should we un-stale this issue?
|
||||||
|
if (this.options.removeStaleWhenUpdated && issueHasComments) {
|
||||||
|
core.info(`Issue #${issue.number} is no longer stale. Removing stale label.`);
|
||||||
|
yield this.removeLabel(issue, staleLabel);
|
||||||
|
}
|
||||||
|
// now start closing logic
|
||||||
if (this.options.daysBeforeClose < 0) {
|
if (this.options.daysBeforeClose < 0) {
|
||||||
return; // nothing to do because we aren't closing stale issues
|
return; // nothing to do because we aren't closing stale issues
|
||||||
}
|
}
|
||||||
const markedStaleOn = yield this.getLabelCreationDate(issue, staleLabel);
|
|
||||||
const issueHasComments = yield this.isIssueStillStale(issue, markedStaleOn || issue.updated_at);
|
|
||||||
const issueHasUpdate = IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeClose);
|
|
||||||
if (markedStaleOn) {
|
|
||||||
core.debug(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
core.debug(`Issue #${issue.number} is not marked stale, but last update of ${issue.updated_at} is older than ${this.options.daysBeforeStale} days`);
|
|
||||||
}
|
|
||||||
core.debug(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
|
||||||
core.debug(`Issue #${issue.number} has been commented on: ${issueHasComments}`);
|
|
||||||
if (!issueHasComments && !issueHasUpdate) {
|
if (!issueHasComments && !issueHasUpdate) {
|
||||||
core.debug(`Closing ${issueType} because it was last updated on ${issue.updated_at}`);
|
core.info(`Closing ${issueType} because it was last updated on ${issue.updated_at}`);
|
||||||
yield this.closeIssue(issue);
|
yield this.closeIssue(issue);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (this.options.removeStaleWhenUpdated) {
|
core.info(`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`);
|
||||||
yield this.removeLabel(issue, staleLabel);
|
|
||||||
}
|
|
||||||
core.debug(`Ignoring stale ${issueType} because it was updated recently`);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// 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)
|
||||||
isIssueStillStale(issue, sinceDate) {
|
hasCommentsSince(issue, sinceDate) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.debug(`Checking for comments on issue #${issue.number} since ${sinceDate} to see if it is still stale`);
|
core.info(`Checking for comments on issue #${issue.number} since ${sinceDate}`);
|
||||||
if (!sinceDate) {
|
if (!sinceDate) {
|
||||||
return true; // if no date was provided then the issue was marked stale a long time ago
|
return true;
|
||||||
}
|
}
|
||||||
this.operationsLeft -= 1;
|
// find any comments since the date
|
||||||
// find any comments since the stale label
|
|
||||||
const comments = yield this.listIssueComments(issue.number, sinceDate);
|
const comments = yield this.listIssueComments(issue.number, sinceDate);
|
||||||
// if there are any user comments returned, issue is not stale anymore
|
const filteredComments = comments.filter(comment => comment.user.type === 'User' &&
|
||||||
return comments.filter(comment => comment.user.type === 'User').length > 0;
|
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
|
||||||
listIssueComments(issueNumber, sinceDate) {
|
listIssueComments(issueNumber, sinceDate) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// find any comments since date on the given issue
|
// find any comments since date on the given issue
|
||||||
const comments = yield this.client.issues.listComments({
|
try {
|
||||||
owner: github.context.repo.owner,
|
const comments = yield this.client.issues.listComments({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issueNumber,
|
repo: github.context.repo.repo,
|
||||||
since: sinceDate
|
issue_number: issueNumber,
|
||||||
});
|
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
|
||||||
getIssues(page) {
|
getIssues(page) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const issueResult = yield this.client.issues.listForRepo({
|
try {
|
||||||
owner: github.context.repo.owner,
|
const issueResult = yield this.client.issues.listForRepo({
|
||||||
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
|
||||||
markStale(issue, staleMessage, staleLabel) {
|
markStale(issue, staleMessage, staleLabel) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.debug(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
core.info(`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 = new Date();
|
||||||
|
issue.updated_at = newUpdatedAtDate.toString();
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
yield this.client.issues.createComment({
|
try {
|
||||||
owner: github.context.repo.owner,
|
yield this.client.issues.createComment({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issue.number,
|
repo: github.context.repo.repo,
|
||||||
body: staleMessage
|
issue_number: issue.number,
|
||||||
});
|
body: staleMessage
|
||||||
yield this.client.issues.addLabels({
|
});
|
||||||
owner: github.context.repo.owner,
|
}
|
||||||
repo: github.context.repo.repo,
|
catch (error) {
|
||||||
issue_number: issue.number,
|
core.error(`Error creating a comment: ${error.message}`);
|
||||||
labels: [staleLabel]
|
}
|
||||||
});
|
try {
|
||||||
|
yield this.client.issues.addLabels({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
labels: [staleLabel]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.error(`Error adding a label: ${error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Close an issue based on staleness
|
// Close an issue based on staleness
|
||||||
closeIssue(issue) {
|
closeIssue(issue) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.debug(`Closing issue #${issue.number} - ${issue.title} for being stale`);
|
core.info(`Closing issue #${issue.number} - ${issue.title} for being stale`);
|
||||||
this.closedIssues.push(issue);
|
this.closedIssues.push(issue);
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
yield this.client.issues.update({
|
try {
|
||||||
owner: github.context.repo.owner,
|
yield this.client.issues.update({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issue.number,
|
repo: github.context.repo.repo,
|
||||||
state: 'closed'
|
issue_number: issue.number,
|
||||||
});
|
state: 'closed'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
core.error(`Error updating an issue: ${error.message}`);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Remove a label from an issue
|
// Remove a label from an issue
|
||||||
removeLabel(issue, label) {
|
removeLabel(issue, label) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.debug(`Removing label ${label} from issue #${issue.number} - ${issue.title}`);
|
core.info(`Removing label ${label} from issue #${issue.number} - ${issue.title}`);
|
||||||
this.removedLabelIssues.push(issue);
|
this.removedLabelIssues.push(issue);
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
yield this.client.issues.removeLabel({
|
try {
|
||||||
owner: github.context.repo.owner,
|
yield this.client.issues.removeLabel({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issue.number,
|
repo: github.context.repo.repo,
|
||||||
name: encodeURIComponent(label) // A label can have a "?" in the name
|
issue_number: issue.number,
|
||||||
});
|
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)
|
||||||
///see https://developer.github.com/v3/activity/events/
|
///see https://developer.github.com/v3/activity/events/
|
||||||
getLabelCreationDate(issue, label) {
|
getLabelCreationDate(issue, label) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.debug(`Checking for label ${label} on issue #${issue.number}`);
|
core.info(`Checking for label ${label} on issue #${issue.number}`);
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
const options = this.client.issues.listEvents.endpoint.merge({
|
const options = this.client.issues.listEvents.endpoint.merge({
|
||||||
owner: github.context.repo.owner,
|
owner: github.context.repo.owner,
|
||||||
@@ -8864,7 +8900,7 @@ class IssueProcessor {
|
|||||||
static updatedSince(timestamp, num_days) {
|
static updatedSince(timestamp, num_days) {
|
||||||
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
||||||
const millisSinceLastUpdated = new Date().getTime() - new Date(timestamp).getTime();
|
const millisSinceLastUpdated = new Date().getTime() - new Date(timestamp).getTime();
|
||||||
return millisSinceLastUpdated < daysInMillis;
|
return millisSinceLastUpdated <= daysInMillis;
|
||||||
}
|
}
|
||||||
static parseCommaSeparatedString(s) {
|
static parseCommaSeparatedString(s) {
|
||||||
// String.prototype.split defaults to [''] when called on an empty string
|
// String.prototype.split defaults to [''] when called on an empty string
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ export interface Issue {
|
|||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
type: string;
|
type: string;
|
||||||
|
login: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Comment {
|
export interface Comment {
|
||||||
@@ -67,7 +68,10 @@ export class IssueProcessor {
|
|||||||
issueNumber: number,
|
issueNumber: number,
|
||||||
sinceDate: string
|
sinceDate: string
|
||||||
) => Promise<Comment[]>,
|
) => Promise<Comment[]>,
|
||||||
getLabelCreationDate?: (issue: Issue, label: string) => Promise<string | undefined>
|
getLabelCreationDate?: (
|
||||||
|
issue: Issue,
|
||||||
|
label: string
|
||||||
|
) => Promise<string | undefined>
|
||||||
) {
|
) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.operationsLeft = options.operationsPerRun;
|
this.operationsLeft = options.operationsPerRun;
|
||||||
@@ -93,24 +97,19 @@ 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.debug('No more issues found to process. Exiting.');
|
core.info('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.debug(
|
core.info(
|
||||||
`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})`
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -127,17 +126,17 @@ export class IssueProcessor {
|
|||||||
const issueType: string = isPr ? 'pr' : 'issue';
|
const issueType: string = isPr ? 'pr' : 'issue';
|
||||||
|
|
||||||
if (!staleMessage) {
|
if (!staleMessage) {
|
||||||
core.debug(`Skipping ${issueType} due to empty stale message`);
|
core.info(`Skipping ${issueType} due to empty stale message`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (issue.state === 'closed') {
|
if (issue.state === 'closed') {
|
||||||
core.debug(`Skipping ${issueType} because it is closed`);
|
core.info(`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.debug(`Skipping ${issueType} because it is locked`);
|
core.info(`Skipping ${issueType} because it is locked`);
|
||||||
continue; // don't process locked issues
|
continue; // don't process locked issues
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -146,36 +145,40 @@ export class IssueProcessor {
|
|||||||
IssueProcessor.isLabeled(issue, exemptLabel)
|
IssueProcessor.isLabeled(issue, exemptLabel)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
core.info(`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?
|
// does this issue have a stale label?
|
||||||
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
||||||
|
|
||||||
|
// should this issue be marked stale?
|
||||||
|
const shouldBeStale = !IssueProcessor.updatedSince(
|
||||||
|
issue.updated_at,
|
||||||
|
this.options.daysBeforeStale
|
||||||
|
);
|
||||||
|
|
||||||
// determine if this issue needs to be marked stale first
|
// determine if this issue needs to be marked stale first
|
||||||
if (
|
if (!isStale && shouldBeStale) {
|
||||||
!isStale &&
|
core.info(
|
||||||
!IssueProcessor.updatedSince(
|
|
||||||
issue.updated_at,
|
|
||||||
this.options.daysBeforeStale
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
core.debug(
|
|
||||||
`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`
|
`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);
|
||||||
this.operationsLeft -= 2;
|
|
||||||
isStale = true; // this issue is now considered stale
|
isStale = true; // this issue is now considered stale
|
||||||
}
|
}
|
||||||
|
|
||||||
// process any issues marked stale (including the issue above, if it was marked)
|
// process the issue if it was marked stale
|
||||||
if (isStale) {
|
if (isStale) {
|
||||||
core.debug(`Found a stale ${issueType}`);
|
core.info(`Found a stale ${issueType}`);
|
||||||
await this.processStaleIssue(issue, issueType, staleLabel);
|
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
|
||||||
return this.processIssues(page + 1);
|
return this.processIssues(page + 1);
|
||||||
}
|
}
|
||||||
@@ -186,65 +189,77 @@ export class IssueProcessor {
|
|||||||
issueType: string,
|
issueType: string,
|
||||||
staleLabel: string
|
staleLabel: string
|
||||||
) {
|
) {
|
||||||
if (this.options.daysBeforeClose < 0) {
|
const markedStaleOn: string =
|
||||||
return; // nothing to do because we aren't closing stale issues
|
(await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
||||||
}
|
core.info(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
||||||
|
|
||||||
const markedStaleOn: string | undefined = await this.getLabelCreationDate(
|
const issueHasComments: boolean = await this.hasCommentsSince(
|
||||||
issue,
|
issue,
|
||||||
staleLabel
|
markedStaleOn
|
||||||
);
|
);
|
||||||
const issueHasComments: boolean = await this.isIssueStillStale(
|
core.info(
|
||||||
issue,
|
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
||||||
markedStaleOn || issue.updated_at
|
|
||||||
);
|
);
|
||||||
|
|
||||||
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}`);
|
||||||
|
|
||||||
if (markedStaleOn) {
|
// should we un-stale this issue?
|
||||||
core.debug(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
if (this.options.removeStaleWhenUpdated && issueHasComments) {
|
||||||
|
core.info(
|
||||||
|
`Issue #${issue.number} is no longer stale. Removing stale label.`
|
||||||
|
);
|
||||||
|
await this.removeLabel(issue, staleLabel);
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
core.debug(`Issue #${issue.number} is not marked stale, but last update of ${issue.updated_at} is older than ${this.options.daysBeforeStale} days`);
|
// now start closing logic
|
||||||
|
if (this.options.daysBeforeClose < 0) {
|
||||||
|
return; // nothing to do because we aren't closing stale issues
|
||||||
}
|
}
|
||||||
core.debug(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
|
||||||
core.debug(`Issue #${issue.number} has been commented on: ${issueHasComments}`);
|
|
||||||
|
|
||||||
if (!issueHasComments && !issueHasUpdate) {
|
if (!issueHasComments && !issueHasUpdate) {
|
||||||
core.debug(
|
core.info(
|
||||||
`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 {
|
||||||
if (this.options.removeStaleWhenUpdated) {
|
core.info(
|
||||||
await this.removeLabel(issue, staleLabel);
|
`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`
|
||||||
}
|
);
|
||||||
core.debug(`Ignoring stale ${issueType} because it was updated recently`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 isIssueStillStale(
|
private async hasCommentsSince(
|
||||||
issue: Issue,
|
issue: Issue,
|
||||||
sinceDate: string
|
sinceDate: string
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
core.debug(
|
core.info(
|
||||||
`Checking for comments on issue #${issue.number} since ${sinceDate} to see if it is still stale`
|
`Checking for comments on issue #${issue.number} since ${sinceDate}`
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!sinceDate) {
|
if (!sinceDate) {
|
||||||
return true; // if no date was provided then the issue was marked stale a long time ago
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.operationsLeft -= 1;
|
// find any comments since the date
|
||||||
|
|
||||||
// find any comments since the stale label
|
|
||||||
const comments = await this.listIssueComments(issue.number, sinceDate);
|
const comments = await this.listIssueComments(issue.number, sinceDate);
|
||||||
|
|
||||||
// if there are any user comments returned, issue is not stale anymore
|
const filteredComments = comments.filter(
|
||||||
return comments.filter(comment => comment.user.type === 'User').length > 0;
|
comment =>
|
||||||
|
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
|
||||||
@@ -253,28 +268,38 @@ 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
|
||||||
const comments = await this.client.issues.listComments({
|
try {
|
||||||
owner: github.context.repo.owner,
|
const comments = await this.client.issues.listComments({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issueNumber,
|
repo: github.context.repo.repo,
|
||||||
since: sinceDate
|
issue_number: issueNumber,
|
||||||
});
|
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[]> {
|
||||||
const issueResult: OctoKitIssueList = await this.client.issues.listForRepo({
|
try {
|
||||||
owner: github.context.repo.owner,
|
const issueResult: OctoKitIssueList = await this.client.issues.listForRepo(
|
||||||
repo: github.context.repo.repo,
|
{
|
||||||
state: 'open',
|
owner: github.context.repo.owner,
|
||||||
labels: this.options.onlyLabels,
|
repo: github.context.repo.repo,
|
||||||
per_page: 100,
|
state: 'open',
|
||||||
page
|
labels: this.options.onlyLabels,
|
||||||
});
|
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
|
||||||
@@ -283,34 +308,47 @@ export class IssueProcessor {
|
|||||||
staleMessage: string,
|
staleMessage: string,
|
||||||
staleLabel: string
|
staleLabel: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
core.debug(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
core.info(`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;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.client.issues.createComment({
|
try {
|
||||||
owner: github.context.repo.owner,
|
await this.client.issues.createComment({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issue.number,
|
repo: github.context.repo.repo,
|
||||||
body: staleMessage
|
issue_number: issue.number,
|
||||||
});
|
body: staleMessage
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
core.error(`Error creating a comment: ${error.message}`);
|
||||||
|
}
|
||||||
|
|
||||||
await this.client.issues.addLabels({
|
try {
|
||||||
owner: github.context.repo.owner,
|
await this.client.issues.addLabels({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issue.number,
|
repo: github.context.repo.repo,
|
||||||
labels: [staleLabel]
|
issue_number: issue.number,
|
||||||
});
|
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.debug(
|
core.info(
|
||||||
`Closing issue #${issue.number} - ${issue.title} for being stale`
|
`Closing issue #${issue.number} - ${issue.title} for being stale`
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -322,17 +360,21 @@ export class IssueProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.client.issues.update({
|
try {
|
||||||
owner: github.context.repo.owner,
|
await this.client.issues.update({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issue.number,
|
repo: github.context.repo.repo,
|
||||||
state: 'closed'
|
issue_number: issue.number,
|
||||||
});
|
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.debug(
|
core.info(
|
||||||
`Removing label ${label} from issue #${issue.number} - ${issue.title}`
|
`Removing label ${label} from issue #${issue.number} - ${issue.title}`
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -344,12 +386,16 @@ export class IssueProcessor {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await this.client.issues.removeLabel({
|
try {
|
||||||
owner: github.context.repo.owner,
|
await this.client.issues.removeLabel({
|
||||||
repo: github.context.repo.repo,
|
owner: github.context.repo.owner,
|
||||||
issue_number: issue.number,
|
repo: github.context.repo.repo,
|
||||||
name: encodeURIComponent(label) // A label can have a "?" in the name
|
issue_number: issue.number,
|
||||||
});
|
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)
|
||||||
@@ -358,7 +404,7 @@ export class IssueProcessor {
|
|||||||
issue: Issue,
|
issue: Issue,
|
||||||
label: string
|
label: string
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
core.debug(`Checking for label ${label} on issue #${issue.number}`);
|
core.info(`Checking for label ${label} on issue #${issue.number}`);
|
||||||
|
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
@@ -395,7 +441,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