Compare commits

..

8 Commits

Author SHA1 Message Date
dependabot[bot]
1849651e2a Bump @actions/core from 1.2.4 to 1.2.5 (#154)
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.4 to 1.2.5.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-09-11 09:20:39 -04:00
dependabot[bot]
adc83cbd46 Bump @vercel/ncc from 0.23.0 to 0.24.0 (#155)
Bumps [@vercel/ncc](https://github.com/vercel/ncc) from 0.23.0 to 0.24.0.
- [Release notes](https://github.com/vercel/ncc/releases)
- [Commits](https://github.com/vercel/ncc/compare/0.23.0...0.24.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-09-11 09:20:29 -04:00
dependabot[bot]
691fea805f Bump jest-circus from 26.1.0 to 26.4.2 (#157)
Bumps [jest-circus](https://github.com/facebook/jest/tree/HEAD/packages/jest-circus) from 26.1.0 to 26.4.2.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/commits/v26.4.2/packages/jest-circus)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-09-11 09:20:19 -04:00
dependabot[bot]
65b38a69a5 Bump prettier from 2.0.5 to 2.1.1 (#158)
Bumps [prettier](https://github.com/prettier/prettier) from 2.0.5 to 2.1.1.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.0.5...2.1.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-09-11 09:20:09 -04:00
dependabot[bot]
1919ea432e Bump @types/node from 14.6.0 to 14.10.0 (#162)
Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 14.6.0 to 14.10.0.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-09-11 09:19:59 -04:00
dependabot[bot]
1402601e7a Bump node-fetch from 2.6.0 to 2.6.1 (#163)
Bumps [node-fetch](https://github.com/bitinn/node-fetch) from 2.6.0 to 2.6.1.
- [Release notes](https://github.com/bitinn/node-fetch/releases)
- [Changelog](https://github.com/node-fetch/node-fetch/blob/master/docs/CHANGELOG.md)
- [Commits](https://github.com/bitinn/node-fetch/compare/v2.6.0...v2.6.1)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2020-09-11 09:19:46 -04:00
Ross Brodbeck
655dd09f5f Add updated dist file 2020-09-11 08:24:59 -04:00
Daniel Jankowski
13b324e4b2 Add support for adding close label (#135) 2020-09-08 15:32:42 -04:00
7 changed files with 473 additions and 405 deletions

View File

@@ -40,8 +40,10 @@ const DefaultProcessorOptions: IssueProcessorOptions = Object.freeze({
daysBeforeStale: 1,
daysBeforeClose: 30,
staleIssueLabel: 'Stale',
closeIssueLabel: '',
exemptIssueLabels: '',
stalePrLabel: 'Stale',
closePrLabel: '',
exemptPrLabels: '',
onlyLabels: '',
operationsPerRun: 100,

View File

@@ -22,12 +22,16 @@ inputs:
stale-issue-label:
description: 'The label to apply when an issue is stale.'
default: 'Stale'
close-issue-label:
description: 'The label to apply when an issue is closed.'
exempt-issue-labels:
description: 'The labels to apply when an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
default: ''
stale-pr-label:
description: 'The label to apply when a pull request is stale.'
default: 'Stale'
close-pr-label:
description: 'The label to apply when a pull request is closed.'
exempt-pr-labels:
description: 'The labels to apply when a pull request is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
default: ''
@@ -52,9 +56,6 @@ inputs:
skip-stale-issue-message:
description: 'Skip adding stale message when marking an issue as stale.'
default: false
process-drafts:
description: 'Should the draft PRs be marked stale? If set to true, draft PRs will be included in processing.'
default: false
runs:
using: 'node12'
main: 'dist/index.js'

34
dist/index.js vendored
View File

@@ -1455,8 +1455,10 @@ function getAndValidateArgs() {
daysBeforeStale: parseInt(core.getInput('days-before-stale', { required: true })),
daysBeforeClose: parseInt(core.getInput('days-before-close', { required: true })),
staleIssueLabel: core.getInput('stale-issue-label', { required: true }),
closeIssueLabel: core.getInput('close-issue-label'),
exemptIssueLabels: core.getInput('exempt-issue-labels'),
stalePrLabel: core.getInput('stale-pr-label', { required: true }),
closePrLabel: core.getInput('close-pr-label'),
exemptPrLabels: core.getInput('exempt-pr-labels'),
onlyLabels: core.getInput('only-labels'),
operationsPerRun: parseInt(core.getInput('operations-per-run', { required: true })),
@@ -1464,8 +1466,7 @@ function getAndValidateArgs() {
debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true',
skipStalePrMessage: core.getInput('skip-stale-pr-message') === 'true',
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true',
processDrafts: core.getInput('process-drafts') === 'true'
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true'
};
for (const numberInput of [
'days-before-stale',
@@ -2589,6 +2590,9 @@ class IssueProcessor {
const staleLabel = isPr
? this.options.stalePrLabel
: this.options.staleIssueLabel;
const closeLabel = isPr
? this.options.closePrLabel
: this.options.closeIssueLabel;
const exemptLabels = IssueProcessor.parseCommaSeparatedString(isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels);
const skipMessage = isPr
? this.options.skipStalePrMessage
@@ -2607,10 +2611,6 @@ class IssueProcessor {
core.info(`Skipping ${issueType} because it is locked`);
continue; // don't process locked issues
}
if (issue.draft && !this.options.processDrafts) {
core.info(`Skipping ${issueType} because it is a draft`);
continue; // don't process drafts
}
if (exemptLabels.some((exemptLabel) => IssueProcessor.isLabeled(issue, exemptLabel))) {
core.info(`Skipping ${issueType} because it has an exempt label`);
continue; // don't process exempt issues
@@ -2628,7 +2628,7 @@ class IssueProcessor {
// process the issue if it was marked stale
if (isStale) {
core.info(`Found a stale ${issueType}`);
yield this.processStaleIssue(issue, issueType, staleLabel, closeMessage);
yield this.processStaleIssue(issue, issueType, staleLabel, closeMessage, closeLabel);
}
}
if (this.operationsLeft <= 0) {
@@ -2640,7 +2640,7 @@ class IssueProcessor {
});
}
// handle all of the stale issue logic when we find a stale issue
processStaleIssue(issue, issueType, staleLabel, closeMessage) {
processStaleIssue(issue, issueType, staleLabel, closeMessage, closeLabel) {
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}`);
@@ -2659,7 +2659,7 @@ class IssueProcessor {
}
if (!issueHasComments && !issueHasUpdate) {
core.info(`Closing ${issueType} because it was last updated on ${issue.updated_at}`);
yield this.closeIssue(issue, closeMessage);
yield this.closeIssue(issue, closeMessage, closeLabel);
}
else {
core.info(`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`);
@@ -2715,7 +2715,6 @@ class IssueProcessor {
direction: this.options.ascending ? 'asc' : 'desc',
page
});
core.info(`issue data: ${JSON.stringify(issueResult.data)}`);
return issueResult.data;
}
catch (error) {
@@ -2764,7 +2763,7 @@ class IssueProcessor {
});
}
// Close an issue based on staleness
closeIssue(issue, closeMessage) {
closeIssue(issue, closeMessage, closeLabel) {
return __awaiter(this, void 0, void 0, function* () {
core.info(`Closing issue #${issue.number} - ${issue.title} for being stale`);
this.closedIssues.push(issue);
@@ -2785,6 +2784,19 @@ class IssueProcessor {
core.error(`Error creating a comment: ${error.message}`);
}
}
if (closeLabel) {
try {
yield this.client.issues.addLabels({
owner: github_1.context.repo.owner,
repo: github_1.context.repo.repo,
issue_number: issue.number,
labels: [closeLabel]
});
}
catch (error) {
core.error(`Error adding a label: ${error.message}`);
}
}
try {
yield this.client.issues.update({
owner: github_1.context.repo.owner,

779
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -25,7 +25,7 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.4",
"@actions/core": "^1.2.5",
"@actions/github": "^4.0.0",
"@octokit/rest": "^18.0.4",
"semver": "^7.3.2"
@@ -33,16 +33,16 @@
"devDependencies": {
"@types/semver": "^7.3.1",
"@types/jest": "^26.0.10",
"@types/node": "^14.6.0",
"@types/node": "^14.10.0",
"@typescript-eslint/parser": "^3.10.1",
"@vercel/ncc": "^0.23.0",
"@vercel/ncc": "^0.24.0",
"eslint": "^7.7.0",
"eslint-plugin-github": "^4.0.1",
"eslint-plugin-jest": "^23.20.0",
"jest": "^24.9.0",
"jest-circus": "^26.1.0",
"jest-circus": "^26.4.2",
"js-yaml": "^3.14.0",
"prettier": "^2.0.5",
"prettier": "^2.1.1",
"ts-jest": "^24.2.0",
"typescript": "^4.0.2"
}

View File

@@ -10,7 +10,6 @@ export interface Issue {
pull_request: any;
state: string;
locked: boolean;
draft: boolean;
}
export interface User {
@@ -41,8 +40,10 @@ export interface IssueProcessorOptions {
daysBeforeStale: number;
daysBeforeClose: number;
staleIssueLabel: string;
closeIssueLabel: string;
exemptIssueLabels: string;
stalePrLabel: string;
closePrLabel: string;
exemptPrLabels: string;
onlyLabels: string;
operationsPerRun: number;
@@ -51,7 +52,6 @@ export interface IssueProcessorOptions {
ascending: boolean;
skipStaleIssueMessage: boolean;
skipStalePrMessage: boolean;
processDrafts: boolean;
}
/***
@@ -128,6 +128,9 @@ export class IssueProcessor {
const staleLabel: string = isPr
? this.options.stalePrLabel
: this.options.staleIssueLabel;
const closeLabel: string = isPr
? this.options.closePrLabel
: this.options.closeIssueLabel;
const exemptLabels = IssueProcessor.parseCommaSeparatedString(
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
);
@@ -152,11 +155,6 @@ export class IssueProcessor {
continue; // don't process locked issues
}
if (issue.draft && !this.options.processDrafts) {
core.info(`Skipping ${issueType} because it is a draft`);
continue; // don't process drafts
}
if (
exemptLabels.some((exemptLabel: string) =>
IssueProcessor.isLabeled(issue, exemptLabel)
@@ -191,7 +189,8 @@ export class IssueProcessor {
issue,
issueType,
staleLabel,
closeMessage
closeMessage,
closeLabel
);
}
}
@@ -210,7 +209,8 @@ export class IssueProcessor {
issue: Issue,
issueType: string,
staleLabel: string,
closeMessage?: string
closeMessage?: string,
closeLabel?: string
) {
const markedStaleOn: string =
(await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
@@ -247,7 +247,7 @@ export class IssueProcessor {
core.info(
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
);
await this.closeIssue(issue, closeMessage);
await this.closeIssue(issue, closeMessage, closeLabel);
} else {
core.info(
`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`
@@ -322,8 +322,6 @@ export class IssueProcessor {
page
}
);
core.info(`issue data: ${JSON.stringify(issueResult.data)}`);
return issueResult.data;
} catch (error) {
core.error(`Get issues for repo error: ${error.message}`);
@@ -379,7 +377,11 @@ export class IssueProcessor {
}
// Close an issue based on staleness
private async closeIssue(issue: Issue, closeMessage?: string): Promise<void> {
private async closeIssue(
issue: Issue,
closeMessage?: string,
closeLabel?: string
): Promise<void> {
core.info(
`Closing issue #${issue.number} - ${issue.title} for being stale`
);
@@ -405,6 +407,19 @@ export class IssueProcessor {
}
}
if (closeLabel) {
try {
await this.client.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: [closeLabel]
});
} catch (error) {
core.error(`Error adding a label: ${error.message}`);
}
}
try {
await this.client.issues.update({
owner: context.repo.owner,

View File

@@ -27,8 +27,10 @@ function getAndValidateArgs(): IssueProcessorOptions {
core.getInput('days-before-close', {required: true})
),
staleIssueLabel: core.getInput('stale-issue-label', {required: true}),
closeIssueLabel: core.getInput('close-issue-label'),
exemptIssueLabels: core.getInput('exempt-issue-labels'),
stalePrLabel: core.getInput('stale-pr-label', {required: true}),
closePrLabel: core.getInput('close-pr-label'),
exemptPrLabels: core.getInput('exempt-pr-labels'),
onlyLabels: core.getInput('only-labels'),
operationsPerRun: parseInt(
@@ -40,8 +42,7 @@ function getAndValidateArgs(): IssueProcessorOptions {
debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true',
skipStalePrMessage: core.getInput('skip-stale-pr-message') === 'true',
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true',
processDrafts: core.getInput('process-drafts') === 'true'
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true'
};
for (const numberInput of [