Compare commits

..

5 Commits

Author SHA1 Message Date
Ross Brodbeck
dcf19effbe update logging 2020-08-28 14:22:14 -04:00
Ross Brodbeck
2392a086f1 more logging to see if we have draft results 2020-08-28 14:19:19 -04:00
Ross Brodbeck
c52e87c95b add some logging 2020-08-28 14:13:35 -04:00
Ross Brodbeck
990266dda6 Add dist file 2020-08-28 14:01:16 -04:00
Ross Brodbeck
5e528060cc Add exemption for processing draft PRs 2020-08-28 13:58:11 -04:00
8 changed files with 3507 additions and 3678 deletions

View File

@@ -18,31 +18,6 @@ Run the tests :heavy_check_mark:
```bash ```bash
$ npm test $ npm test
``` ```
### Arguments
| Input | Description | Usage |
| :---: | :---: | :---: |
| `repo-token` | PAT(Personal Access Token) for authorizing repository. | *Required* |
| `days-before-stale` | Idle number of days before marking an issue/pr as stale. *Defaults to **60*** | Optional
| `days-before-close` | Idle number of days before closing an stale issue/pr. *Defaults to **7*** | Optional
| `stale-issue-message` | Message to post on the stale issue. | Optional
| `stale-pr-message` | Message to post on the stale pr. | Optional
| `close-issue-message` | Message to post on the stale issue while closing it. | Optional
| `close-pr-message` | Message to post on the stale pr while closing it. | Optional
| `stale-issue-label` | Label to apply on the stale issue. *Defaults to **stale*** | Optional
| `close-issue-label` | Label to apply on closing issue. | Optional
| `stale-pr-label` | Label to apply on the stale pr. | Optional
| `close-pr-label` | Label to apply on the closing pr. | Optional
| `exempt-issue-labels` | Labels on an issue exempted from being marked as stale. | Optional
| `exempt-pr-labels` | Labels on the pr exempted from being marked as stale. | Optional
| `only-labels` | Only labels checked for stale issue/pr. | Optional
| `operations-per-run` | Maximum number of operations per run. *Defaults to **30*** | Optional
| `remove-stale-when-updated` | Remove stale label from issue/pr on updates or comments. *Defaults to **true*** | Optional
| `debug-only` | Dry-run on action. *Defaults to **false*** | Optional
| `ascending` | Order to get issues/pr. *Defaults to **false*** | Optional
| `skip-stale-issue-message` | Skip adding stale message on stale issue. *Defaults to **false*** | Optional
| `skip-stale-pr-message` | Skip adding stale message on stale pr. *Defaults to **false*** | Optional
### Usage ### Usage
@@ -53,7 +28,7 @@ Basic:
name: "Close stale issues" name: "Close stale issues"
on: on:
schedule: schedule:
- cron: "30 1 * * *" - cron: "0 0 * * *"
jobs: jobs:
stale: stale:
@@ -71,7 +46,7 @@ Configure stale timeouts:
name: "Close stale issues" name: "Close stale issues"
on: on:
schedule: schedule:
- cron: "30 1 * * *" - cron: "0 0 * * *"
jobs: jobs:
stale: stale:
@@ -90,7 +65,7 @@ Configure labels:
name: "Close stale issues" name: "Close stale issues"
on: on:
schedule: schedule:
- cron: "30 1 * * *" - cron: "0 0 * * *"
jobs: jobs:
stale: stale:

View File

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

View File

@@ -22,16 +22,12 @@ inputs:
stale-issue-label: stale-issue-label:
description: 'The label to apply when an issue is stale.' description: 'The label to apply when an issue is stale.'
default: 'Stale' default: 'Stale'
close-issue-label:
description: 'The label to apply when an issue is closed.'
exempt-issue-labels: 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")' description: 'The labels to apply when an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
default: '' default: ''
stale-pr-label: stale-pr-label:
description: 'The label to apply when a pull request is stale.' description: 'The label to apply when a pull request is stale.'
default: 'Stale' default: 'Stale'
close-pr-label:
description: 'The label to apply when a pull request is closed.'
exempt-pr-labels: 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")' description: 'The labels to apply when a pull request is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
default: '' default: ''
@@ -56,6 +52,9 @@ inputs:
skip-stale-issue-message: skip-stale-issue-message:
description: 'Skip adding stale message when marking an issue as stale.' description: 'Skip adding stale message when marking an issue as stale.'
default: false 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: runs:
using: 'node12' using: 'node12'
main: 'dist/index.js' main: 'dist/index.js'

6310
dist/index.js vendored

File diff suppressed because it is too large Load Diff

779
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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