mirror of
https://github.com/actions/stale.git
synced 2026-01-06 23:38:17 +00:00
Fix linting and pack for distribution
This commit is contained in:
264
dist/index.js
vendored
264
dist/index.js
vendored
@@ -3729,13 +3729,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const github = __importStar(__webpack_require__(469));
|
const IssueProcessor_1 = __webpack_require__(656);
|
||||||
function run() {
|
function run() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
const args = getAndValidateArgs();
|
const args = getAndValidateArgs();
|
||||||
const client = new github.GitHub(args.repoToken);
|
const processor = new IssueProcessor_1.IssueProcessor(args);
|
||||||
yield processIssues(client, args, args.operationsPerRun);
|
yield processor.processIssues();
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.error(error);
|
core.error(error);
|
||||||
@@ -3743,99 +3743,6 @@ function run() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function processIssues(client, args, operationsLeft, page = 1) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
const issues = yield client.issues.listForRepo({
|
|
||||||
owner: github.context.repo.owner,
|
|
||||||
repo: github.context.repo.repo,
|
|
||||||
state: 'open',
|
|
||||||
labels: args.onlyLabels,
|
|
||||||
per_page: 100,
|
|
||||||
page
|
|
||||||
});
|
|
||||||
operationsLeft -= 1;
|
|
||||||
if (issues.data.length === 0 || operationsLeft === 0) {
|
|
||||||
return operationsLeft;
|
|
||||||
}
|
|
||||||
for (const issue of issues.data.values()) {
|
|
||||||
core.debug(`found issue: ${issue.title} last updated ${issue.updated_at}`);
|
|
||||||
const isPr = !!issue.pull_request;
|
|
||||||
const staleMessage = isPr ? args.stalePrMessage : args.staleIssueMessage;
|
|
||||||
if (!staleMessage) {
|
|
||||||
core.debug(`skipping ${isPr ? 'pr' : 'issue'} due to empty message`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
const staleLabel = isPr ? args.stalePrLabel : args.staleIssueLabel;
|
|
||||||
const exemptLabels = parseCommaSeparatedString(isPr ? args.exemptPrLabels : args.exemptIssueLabels);
|
|
||||||
if (exemptLabels.some(exemptLabel => isLabeled(issue, exemptLabel))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
else if (isLabeled(issue, staleLabel)) {
|
|
||||||
if (args.daysBeforeClose >= 0 &&
|
|
||||||
wasLastUpdatedBefore(issue, args.daysBeforeClose)) {
|
|
||||||
operationsLeft -= yield closeIssue(client, issue);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (wasLastUpdatedBefore(issue, args.daysBeforeStale)) {
|
|
||||||
operationsLeft -= yield markStale(client, issue, staleMessage, staleLabel);
|
|
||||||
}
|
|
||||||
if (operationsLeft <= 0) {
|
|
||||||
core.warning(`performed ${args.operationsPerRun} operations, exiting to avoid rate limit`);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return yield processIssues(client, args, operationsLeft, page + 1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function isLabeled(issue, label) {
|
|
||||||
const labelComparer = l => label.localeCompare(l.name, undefined, { sensitivity: 'accent' }) === 0;
|
|
||||||
return issue.labels.filter(labelComparer).length > 0;
|
|
||||||
}
|
|
||||||
function wasLastUpdatedBefore(issue, num_days) {
|
|
||||||
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
|
||||||
const millisSinceLastUpdated = new Date().getTime() - new Date(issue.updated_at).getTime();
|
|
||||||
return millisSinceLastUpdated >= daysInMillis;
|
|
||||||
}
|
|
||||||
function markStale(client, issue, staleMessage, staleLabel) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
core.debug(`marking issue${issue.title} as stale`);
|
|
||||||
yield client.issues.createComment({
|
|
||||||
owner: github.context.repo.owner,
|
|
||||||
repo: github.context.repo.repo,
|
|
||||||
issue_number: issue.number,
|
|
||||||
body: staleMessage
|
|
||||||
});
|
|
||||||
yield client.issues.addLabels({
|
|
||||||
owner: github.context.repo.owner,
|
|
||||||
repo: github.context.repo.repo,
|
|
||||||
issue_number: issue.number,
|
|
||||||
labels: [staleLabel]
|
|
||||||
});
|
|
||||||
return 2; // operations performed
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function closeIssue(client, issue) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
core.debug(`closing issue ${issue.title} for being stale`);
|
|
||||||
yield client.issues.update({
|
|
||||||
owner: github.context.repo.owner,
|
|
||||||
repo: github.context.repo.repo,
|
|
||||||
issue_number: issue.number,
|
|
||||||
state: 'closed'
|
|
||||||
});
|
|
||||||
return 1; // operations performed
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function parseCommaSeparatedString(s) {
|
|
||||||
// String.prototype.split defaults to [''] when called on an empty string
|
|
||||||
// In this case, we'd prefer to just return an empty array indicating no labels
|
|
||||||
if (!s.length)
|
|
||||||
return [];
|
|
||||||
return s.split(",");
|
|
||||||
}
|
|
||||||
function getAndValidateArgs() {
|
function getAndValidateArgs() {
|
||||||
const args = {
|
const args = {
|
||||||
repoToken: core.getInput('repo-token', { required: true }),
|
repoToken: core.getInput('repo-token', { required: true }),
|
||||||
@@ -3844,11 +3751,12 @@ function getAndValidateArgs() {
|
|||||||
daysBeforeStale: parseInt(core.getInput('days-before-stale', { required: true })),
|
daysBeforeStale: parseInt(core.getInput('days-before-stale', { required: true })),
|
||||||
daysBeforeClose: parseInt(core.getInput('days-before-close', { required: true })),
|
daysBeforeClose: parseInt(core.getInput('days-before-close', { required: true })),
|
||||||
staleIssueLabel: core.getInput('stale-issue-label', { required: true }),
|
staleIssueLabel: core.getInput('stale-issue-label', { required: true }),
|
||||||
exemptIssueLabels: core.getInput('exempt-issue-labels'),
|
exemptIssueLabel: core.getInput('exempt-issue-label'),
|
||||||
stalePrLabel: core.getInput('stale-pr-label', { required: true }),
|
stalePrLabel: core.getInput('stale-pr-label', { required: true }),
|
||||||
exemptPrLabels: core.getInput('exempt-pr-labels'),
|
exemptPrLabel: core.getInput('exempt-pr-label'),
|
||||||
onlyLabels: core.getInput('only-labels'),
|
onlyLabels: core.getInput('only-labels'),
|
||||||
operationsPerRun: parseInt(core.getInput('operations-per-run', { required: true }))
|
operationsPerRun: parseInt(core.getInput('operations-per-run', { required: true })),
|
||||||
|
debugOnly: core.getInput('debug-only') === 'true'
|
||||||
};
|
};
|
||||||
for (const numberInput of [
|
for (const numberInput of [
|
||||||
'days-before-stale',
|
'days-before-stale',
|
||||||
@@ -8509,6 +8417,162 @@ if (process.platform === 'linux') {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ 656:
|
||||||
|
/***/ (function(__unusedmodule, exports, __webpack_require__) {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
|
if (mod && mod.__esModule) return mod;
|
||||||
|
var result = {};
|
||||||
|
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
||||||
|
result["default"] = mod;
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
const core = __importStar(__webpack_require__(470));
|
||||||
|
const github = __importStar(__webpack_require__(469));
|
||||||
|
/***
|
||||||
|
* Handle processing of issues for staleness/closure.
|
||||||
|
*/
|
||||||
|
class IssueProcessor {
|
||||||
|
constructor(options) {
|
||||||
|
this.operationsLeft = 0;
|
||||||
|
this.options = options;
|
||||||
|
this.client = new github.GitHub(options.repoToken);
|
||||||
|
}
|
||||||
|
processIssues(page = 1) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
if (this.options.debugOnly) {
|
||||||
|
core.warning('Executing in debug mode. Debug output will be written but no issues will be processed.');
|
||||||
|
}
|
||||||
|
if (this.operationsLeft <= 0) {
|
||||||
|
core.warning('Reached max number of operations to process. Exiting.');
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
// get the next batch of issues
|
||||||
|
const issues = yield this.getIssues(page);
|
||||||
|
if (issues.data.length <= 0) {
|
||||||
|
core.debug('No more issues found to process. Exiting.');
|
||||||
|
return this.operationsLeft;
|
||||||
|
}
|
||||||
|
for (const issue of issues.data.values()) {
|
||||||
|
const isPr = !!issue.pull_request;
|
||||||
|
core.debug(`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`);
|
||||||
|
// calculate string based messages for this issue
|
||||||
|
const staleMessage = isPr
|
||||||
|
? this.options.stalePrMessage
|
||||||
|
: this.options.staleIssueMessage;
|
||||||
|
const staleLabel = isPr
|
||||||
|
? this.options.stalePrLabel
|
||||||
|
: this.options.staleIssueLabel;
|
||||||
|
const exemptLabel = isPr
|
||||||
|
? this.options.exemptPrLabel
|
||||||
|
: this.options.exemptIssueLabel;
|
||||||
|
const issueType = isPr ? 'pr' : 'issue';
|
||||||
|
if (!staleMessage) {
|
||||||
|
core.debug(`Skipping ${issueType} due to empty stale message`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (exemptLabel && IssueProcessor.isLabeled(issue, exemptLabel)) {
|
||||||
|
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
||||||
|
continue; // don't process exempt issues
|
||||||
|
}
|
||||||
|
if (!IssueProcessor.isLabeled(issue, staleLabel)) {
|
||||||
|
core.debug(`Found a stale ${issueType}`);
|
||||||
|
if (this.options.daysBeforeClose >= 0 &&
|
||||||
|
IssueProcessor.wasLastUpdatedBefore(issue, this.options.daysBeforeClose)) {
|
||||||
|
core.debug(`Closing ${issueType} because it was last updated on ${issue.updated_at}`);
|
||||||
|
yield this.closeIssue(issue);
|
||||||
|
this.operationsLeft -= 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.debug(`Ignoring stale ${issueType} because it was updated recenlty`);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (IssueProcessor.wasLastUpdatedBefore(issue, this.options.daysBeforeStale)) {
|
||||||
|
core.debug(`Marking ${issueType} stale because it was last updated on ${issue.updated_at}`);
|
||||||
|
yield this.markStale(issue, staleMessage, staleLabel);
|
||||||
|
this.operationsLeft -= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// do the next batch
|
||||||
|
return yield this.processIssues(page + 1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// grab issues from github in baches of 100
|
||||||
|
getIssues(page) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
return this.client.issues.listForRepo({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
state: 'open',
|
||||||
|
labels: this.options.onlyLabels,
|
||||||
|
per_page: 100,
|
||||||
|
page
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// Mark an issue as stale with a comment and a label
|
||||||
|
markStale(issue, staleMessage, staleLabel) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.debug(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
||||||
|
if (this.options.debugOnly) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
yield this.client.issues.createComment({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
body: staleMessage
|
||||||
|
});
|
||||||
|
yield this.client.issues.addLabels({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
labels: [staleLabel]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
/// Close an issue based on staleness
|
||||||
|
closeIssue(issue) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.debug(`Closing issue #${issue.number} - ${issue.title} for being stale`);
|
||||||
|
if (this.options.debugOnly) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
yield this.client.issues.update({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
state: 'closed'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
static isLabeled(issue, label) {
|
||||||
|
const labelComparer = l => label.localeCompare(l.name, undefined, { sensitivity: 'accent' }) === 0;
|
||||||
|
return issue.labels.filter(labelComparer).length > 0;
|
||||||
|
}
|
||||||
|
static wasLastUpdatedBefore(issue, num_days) {
|
||||||
|
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
||||||
|
const millisSinceLastUpdated = new Date().getTime() - new Date(issue.updated_at).getTime();
|
||||||
|
return millisSinceLastUpdated >= daysInMillis;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.IssueProcessor = IssueProcessor;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 669:
|
/***/ 669:
|
||||||
@@ -24841,7 +24905,7 @@ exports.requestLog = requestLog;
|
|||||||
/***/ 919:
|
/***/ 919:
|
||||||
/***/ (function(module) {
|
/***/ (function(module) {
|
||||||
|
|
||||||
module.exports = {"_args":[["@octokit/rest@16.43.1","/Users/rwilsonperkin/Projects/stale"]],"_from":"@octokit/rest@16.43.1","_id":"@octokit/rest@16.43.1","_inBundle":false,"_integrity":"sha512-gfFKwRT/wFxq5qlNjnW2dh+qh74XgTQ2B179UX5K1HYCluioWj8Ndbgqw2PVqa1NnVJkGHp2ovMpVn/DImlmkw==","_location":"/@actions/github/@octokit/rest","_phantomChildren":{},"_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/rwilsonperkin/Projects/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 = {"_from":"@octokit/rest@^16.43.1","_id":"@octokit/rest@16.43.1","_inBundle":false,"_integrity":"sha512-gfFKwRT/wFxq5qlNjnW2dh+qh74XgTQ2B179UX5K1HYCluioWj8Ndbgqw2PVqa1NnVJkGHp2ovMpVn/DImlmkw==","_location":"/@actions/github/@octokit/rest","_phantomChildren":{},"_requested":{"type":"range","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","_shasum":"3b11e7d1b1ac2bbeeb23b08a17df0b20947eda6b","_spec":"@octokit/rest@^16.43.1","_where":"/Users/hross/Code/stale/node_modules/@actions/github","author":{"name":"Gregor Martynus","url":"https://github.com/gr2m"},"bugs":{"url":"https://github.com/octokit/rest.js/issues"},"bundleDependencies":false,"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"},"deprecated":false,"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"};
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
|
|||||||
@@ -1,171 +1,189 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
import { Octokit } from '@octokit/rest';
|
import {Octokit} from '@octokit/rest';
|
||||||
|
|
||||||
type Issue = Octokit.IssuesListForRepoResponseItem;
|
type Issue = Octokit.IssuesListForRepoResponseItem;
|
||||||
type IssueLabel = Octokit.IssuesListForRepoResponseItemLabelsItem;
|
type IssueLabel = Octokit.IssuesListForRepoResponseItemLabelsItem;
|
||||||
type IssueList = Octokit.Response<Octokit.IssuesListForRepoResponse>;
|
type IssueList = Octokit.Response<Octokit.IssuesListForRepoResponse>;
|
||||||
|
|
||||||
export interface IssueProcessorOptions {
|
export interface IssueProcessorOptions {
|
||||||
repoToken: string;
|
repoToken: string;
|
||||||
staleIssueMessage: string;
|
staleIssueMessage: string;
|
||||||
stalePrMessage: string;
|
stalePrMessage: string;
|
||||||
daysBeforeStale: number;
|
daysBeforeStale: number;
|
||||||
daysBeforeClose: number;
|
daysBeforeClose: number;
|
||||||
staleIssueLabel: string;
|
staleIssueLabel: string;
|
||||||
exemptIssueLabel: string;
|
exemptIssueLabel: string;
|
||||||
stalePrLabel: string;
|
stalePrLabel: string;
|
||||||
exemptPrLabel: string;
|
exemptPrLabel: string;
|
||||||
onlyLabels: string;
|
onlyLabels: string;
|
||||||
operationsPerRun: number;
|
operationsPerRun: number;
|
||||||
debugOnly: boolean;
|
debugOnly: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Handle processing of issues for staleness/closure.
|
* Handle processing of issues for staleness/closure.
|
||||||
*/
|
*/
|
||||||
export class IssueProcessor {
|
export class IssueProcessor {
|
||||||
readonly client: github.GitHub;
|
readonly client: github.GitHub;
|
||||||
readonly options: IssueProcessorOptions;
|
readonly options: IssueProcessorOptions;
|
||||||
private operationsLeft: number = 0;
|
private operationsLeft: number = 0;
|
||||||
|
|
||||||
constructor(options: IssueProcessorOptions) {
|
constructor(options: IssueProcessorOptions) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.client = new github.GitHub(options.repoToken);
|
this.client = new github.GitHub(options.repoToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
async processIssues(page: number = 1): Promise<number> {
|
||||||
|
if (this.options.debugOnly) {
|
||||||
|
core.warning(
|
||||||
|
'Executing in debug mode. Debug output will be written but no issues will be processed.'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async processIssues(page: number = 1): Promise<number> {
|
if (this.operationsLeft <= 0) {
|
||||||
if (this.options.debugOnly) {
|
core.warning('Reached max number of operations to process. Exiting.');
|
||||||
core.warning('Executing in debug mode. Debug output will be written but no issues will be processed.');
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
if (this.operationsLeft <= 0) {
|
|
||||||
core.warning('Reached max number of operations to process. Exiting.');
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
// get the next batch of issues
|
|
||||||
const issues: IssueList = await this.getIssues(page);
|
|
||||||
|
|
||||||
if (issues.data.length <= 0) {
|
|
||||||
core.debug('No more issues found to process. Exiting.');
|
|
||||||
return this.operationsLeft;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const issue of issues.data.values()) {
|
|
||||||
const isPr: boolean = !!issue.pull_request;
|
|
||||||
|
|
||||||
core.debug(`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`);
|
|
||||||
|
|
||||||
// calculate string based messages for this issue
|
|
||||||
const staleMessage: string = isPr ? this.options.stalePrMessage : this.options.staleIssueMessage;
|
|
||||||
const staleLabel: string = isPr ? this.options.stalePrLabel : this.options.staleIssueLabel;
|
|
||||||
const exemptLabel: string = isPr ? this.options.exemptPrLabel : this.options.exemptIssueLabel;
|
|
||||||
const issueType: string = isPr ? 'pr' : 'issue';
|
|
||||||
|
|
||||||
if (!staleMessage) {
|
|
||||||
core.debug(`Skipping ${issueType} due to empty stale message`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (exemptLabel && IssueProcessor.isLabeled(issue, exemptLabel)) {
|
|
||||||
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
|
||||||
continue; // don't process exempt issues
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!IssueProcessor.isLabeled(issue, staleLabel)) {
|
|
||||||
core.debug(`Found a stale ${issueType}`);
|
|
||||||
if (this.options.daysBeforeClose >= 0 &&
|
|
||||||
IssueProcessor.wasLastUpdatedBefore(issue, this.options.daysBeforeClose))
|
|
||||||
{
|
|
||||||
core.debug(`Closing ${issueType} because it was last updated on ${issue.updated_at}`)
|
|
||||||
await this.closeIssue(issue);
|
|
||||||
this.operationsLeft -= 1;
|
|
||||||
} else {
|
|
||||||
core.debug(`Ignoring stale ${issueType} because it was updated recenlty`);
|
|
||||||
}
|
|
||||||
} else if (IssueProcessor.wasLastUpdatedBefore(issue, this.options.daysBeforeStale)) {
|
|
||||||
core.debug(`Marking ${issueType} stale because it was last updated on ${issue.updated_at}`)
|
|
||||||
await this.markStale(
|
|
||||||
issue,
|
|
||||||
staleMessage,
|
|
||||||
staleLabel
|
|
||||||
);
|
|
||||||
this.operationsLeft -= 2;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// do the next batch
|
|
||||||
return await this.processIssues(page + 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// grab issues from github in baches of 100
|
// get the next batch of issues
|
||||||
private async getIssues(page: number): Promise<IssueList> {
|
const issues: IssueList = await this.getIssues(page);
|
||||||
return this.client.issues.listForRepo({
|
|
||||||
owner: github.context.repo.owner,
|
if (issues.data.length <= 0) {
|
||||||
repo: github.context.repo.repo,
|
core.debug('No more issues found to process. Exiting.');
|
||||||
state: 'open',
|
return this.operationsLeft;
|
||||||
labels: this.options.onlyLabels,
|
}
|
||||||
per_page: 100,
|
|
||||||
page
|
for (const issue of issues.data.values()) {
|
||||||
});
|
const isPr = !!issue.pull_request;
|
||||||
|
|
||||||
|
core.debug(
|
||||||
|
`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`
|
||||||
|
);
|
||||||
|
|
||||||
|
// calculate string based messages for this issue
|
||||||
|
const staleMessage: string = isPr
|
||||||
|
? this.options.stalePrMessage
|
||||||
|
: this.options.staleIssueMessage;
|
||||||
|
const staleLabel: string = isPr
|
||||||
|
? this.options.stalePrLabel
|
||||||
|
: this.options.staleIssueLabel;
|
||||||
|
const exemptLabel: string = isPr
|
||||||
|
? this.options.exemptPrLabel
|
||||||
|
: this.options.exemptIssueLabel;
|
||||||
|
const issueType: string = isPr ? 'pr' : 'issue';
|
||||||
|
|
||||||
|
if (!staleMessage) {
|
||||||
|
core.debug(`Skipping ${issueType} due to empty stale message`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (exemptLabel && IssueProcessor.isLabeled(issue, exemptLabel)) {
|
||||||
|
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
||||||
|
continue; // don't process exempt issues
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!IssueProcessor.isLabeled(issue, staleLabel)) {
|
||||||
|
core.debug(`Found a stale ${issueType}`);
|
||||||
|
if (
|
||||||
|
this.options.daysBeforeClose >= 0 &&
|
||||||
|
IssueProcessor.wasLastUpdatedBefore(
|
||||||
|
issue,
|
||||||
|
this.options.daysBeforeClose
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
core.debug(
|
||||||
|
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
|
||||||
|
);
|
||||||
|
await this.closeIssue(issue);
|
||||||
|
this.operationsLeft -= 1;
|
||||||
|
} else {
|
||||||
|
core.debug(
|
||||||
|
`Ignoring stale ${issueType} because it was updated recenlty`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} else if (
|
||||||
|
IssueProcessor.wasLastUpdatedBefore(issue, this.options.daysBeforeStale)
|
||||||
|
) {
|
||||||
|
core.debug(
|
||||||
|
`Marking ${issueType} stale because it was last updated on ${issue.updated_at}`
|
||||||
|
);
|
||||||
|
await this.markStale(issue, staleMessage, staleLabel);
|
||||||
|
this.operationsLeft -= 2;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// do the next batch
|
||||||
|
return await this.processIssues(page + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// grab issues from github in baches of 100
|
||||||
|
private async getIssues(page: number): Promise<IssueList> {
|
||||||
|
return this.client.issues.listForRepo({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
state: 'open',
|
||||||
|
labels: this.options.onlyLabels,
|
||||||
|
per_page: 100,
|
||||||
|
page
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark an issue as stale with a comment and a label
|
// Mark an issue as stale with a comment and a label
|
||||||
private async markStale(
|
private async markStale(
|
||||||
issue: Issue,
|
issue: Issue,
|
||||||
staleMessage: string,
|
staleMessage: string,
|
||||||
staleLabel: string
|
staleLabel: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
core.debug(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
core.debug(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
||||||
|
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
await this.client.issues.createComment({
|
|
||||||
owner: github.context.repo.owner,
|
|
||||||
repo: github.context.repo.repo,
|
|
||||||
issue_number: issue.number,
|
|
||||||
body: staleMessage
|
|
||||||
});
|
|
||||||
|
|
||||||
await this.client.issues.addLabels({
|
|
||||||
owner: github.context.repo.owner,
|
|
||||||
repo: github.context.repo.repo,
|
|
||||||
issue_number: issue.number,
|
|
||||||
labels: [staleLabel]
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close an issue based on staleness
|
await this.client.issues.createComment({
|
||||||
private async closeIssue(
|
owner: github.context.repo.owner,
|
||||||
issue: Issue
|
repo: github.context.repo.repo,
|
||||||
): Promise<void> {
|
issue_number: issue.number,
|
||||||
core.debug(`Closing issue #${issue.number} - ${issue.title} for being stale`);
|
body: staleMessage
|
||||||
|
});
|
||||||
|
|
||||||
if (this.options.debugOnly) {
|
await this.client.issues.addLabels({
|
||||||
return;
|
owner: github.context.repo.owner,
|
||||||
}
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
labels: [staleLabel]
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
await this.client.issues.update({
|
/// Close an issue based on staleness
|
||||||
owner: github.context.repo.owner,
|
private async closeIssue(issue: Issue): Promise<void> {
|
||||||
repo: github.context.repo.repo,
|
core.debug(
|
||||||
issue_number: issue.number,
|
`Closing issue #${issue.number} - ${issue.title} for being stale`
|
||||||
state: 'closed'
|
);
|
||||||
});
|
|
||||||
|
if (this.options.debugOnly) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static isLabeled(issue: Issue, label: string): boolean {
|
await this.client.issues.update({
|
||||||
const labelComparer: (l: IssueLabel) => boolean = l =>
|
owner: github.context.repo.owner,
|
||||||
label.localeCompare(l.name, undefined, {sensitivity: 'accent'}) === 0;
|
repo: github.context.repo.repo,
|
||||||
return issue.labels.filter(labelComparer).length > 0;
|
issue_number: issue.number,
|
||||||
}
|
state: 'closed'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static wasLastUpdatedBefore(issue: Issue, num_days: number): boolean {
|
private static isLabeled(issue: Issue, label: string): boolean {
|
||||||
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
const labelComparer: (l: IssueLabel) => boolean = l =>
|
||||||
const millisSinceLastUpdated =
|
label.localeCompare(l.name, undefined, {sensitivity: 'accent'}) === 0;
|
||||||
new Date().getTime() - new Date(issue.updated_at).getTime();
|
return issue.labels.filter(labelComparer).length > 0;
|
||||||
return millisSinceLastUpdated >= daysInMillis;
|
}
|
||||||
}
|
|
||||||
|
private static wasLastUpdatedBefore(issue: Issue, num_days: number): boolean {
|
||||||
|
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
||||||
|
const millisSinceLastUpdated =
|
||||||
|
new Date().getTime() - new Date(issue.updated_at).getTime();
|
||||||
|
return millisSinceLastUpdated >= daysInMillis;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
10
src/main.ts
10
src/main.ts
@@ -1,8 +1,5 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import { IssueProcessor, IssueProcessorOptions } from './IssueProcessor';
|
import {IssueProcessor, IssueProcessorOptions} from './IssueProcessor';
|
||||||
|
|
||||||
interface Args extends IssueProcessorOptions {
|
|
||||||
}
|
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
@@ -10,14 +7,13 @@ async function run(): Promise<void> {
|
|||||||
|
|
||||||
const processor: IssueProcessor = new IssueProcessor(args);
|
const processor: IssueProcessor = new IssueProcessor(args);
|
||||||
await processor.processIssues();
|
await processor.processIssues();
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(error);
|
core.error(error);
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAndValidateArgs(): Args {
|
function getAndValidateArgs(): IssueProcessorOptions {
|
||||||
const args = {
|
const args = {
|
||||||
repoToken: core.getInput('repo-token', {required: true}),
|
repoToken: core.getInput('repo-token', {required: true}),
|
||||||
staleIssueMessage: core.getInput('stale-issue-message'),
|
staleIssueMessage: core.getInput('stale-issue-message'),
|
||||||
@@ -36,7 +32,7 @@ function getAndValidateArgs(): Args {
|
|||||||
operationsPerRun: parseInt(
|
operationsPerRun: parseInt(
|
||||||
core.getInput('operations-per-run', {required: true})
|
core.getInput('operations-per-run', {required: true})
|
||||||
),
|
),
|
||||||
debugOnly: (core.getInput('debug-only') === 'true')
|
debugOnly: core.getInput('debug-only') === 'true'
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const numberInput of [
|
for (const numberInput of [
|
||||||
|
|||||||
Reference in New Issue
Block a user