mirror of
https://github.com/actions/stale.git
synced 2025-12-26 18:28:18 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c244b41bff |
@@ -23,7 +23,7 @@
|
|||||||
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
|
"@typescript-eslint/generic-type-naming": ["error", "^[A-Z][A-Za-z]*$"],
|
||||||
"@typescript-eslint/no-array-constructor": "error",
|
"@typescript-eslint/no-array-constructor": "error",
|
||||||
"@typescript-eslint/no-empty-interface": "error",
|
"@typescript-eslint/no-empty-interface": "error",
|
||||||
"@typescript-eslint/no-explicit-any": "off",
|
"@typescript-eslint/no-explicit-any": "error",
|
||||||
"@typescript-eslint/no-extraneous-class": "error",
|
"@typescript-eslint/no-extraneous-class": "error",
|
||||||
"@typescript-eslint/no-for-in-array": "error",
|
"@typescript-eslint/no-for-in-array": "error",
|
||||||
"@typescript-eslint/no-inferrable-types": "error",
|
"@typescript-eslint/no-inferrable-types": "error",
|
||||||
@@ -45,7 +45,7 @@
|
|||||||
"@typescript-eslint/restrict-plus-operands": "error",
|
"@typescript-eslint/restrict-plus-operands": "error",
|
||||||
"semi": "off",
|
"semi": "off",
|
||||||
"@typescript-eslint/type-annotation-spacing": "error",
|
"@typescript-eslint/type-annotation-spacing": "error",
|
||||||
"@typescript-eslint/unbound-method": "off"
|
"@typescript-eslint/unbound-method": "error"
|
||||||
},
|
},
|
||||||
"env": {
|
"env": {
|
||||||
"node": true,
|
"node": true,
|
||||||
|
|||||||
26
.github/workflows/test.yml
vendored
26
.github/workflows/test.yml
vendored
@@ -1,26 +0,0 @@
|
|||||||
name: "Build"
|
|
||||||
on: # rebuild any PRs and main branch changes
|
|
||||||
pull_request:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- master
|
|
||||||
- 'releases/*'
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build: # make sure build/ci work properly
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- run: |
|
|
||||||
npm install
|
|
||||||
npm run all
|
|
||||||
test: # make sure the action works on a clean machine without building
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v2
|
|
||||||
- uses: ./
|
|
||||||
with:
|
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
||||||
stale-issue-message: 'This issue is stale'
|
|
||||||
stale-pr-message: 'This PR is stale'
|
|
||||||
debug-only: true
|
|
||||||
25
README.md
25
README.md
@@ -2,23 +2,6 @@
|
|||||||
|
|
||||||
Warns and then closes issues and PRs that have had no activity for a specified amount of time.
|
Warns and then closes issues and PRs that have had no activity for a specified amount of time.
|
||||||
|
|
||||||
### Building and testing
|
|
||||||
|
|
||||||
Install the dependencies
|
|
||||||
```bash
|
|
||||||
$ npm install
|
|
||||||
```
|
|
||||||
|
|
||||||
Build the typescript and package it for distribution
|
|
||||||
```bash
|
|
||||||
$ npm run build && npm run pack
|
|
||||||
```
|
|
||||||
|
|
||||||
Run the tests :heavy_check_mark:
|
|
||||||
```bash
|
|
||||||
$ npm test
|
|
||||||
```
|
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
See [action.yml](./action.yml) For comprehensive list of options.
|
See [action.yml](./action.yml) For comprehensive list of options.
|
||||||
@@ -77,11 +60,7 @@ jobs:
|
|||||||
stale-issue-message: 'Stale issue message'
|
stale-issue-message: 'Stale issue message'
|
||||||
stale-pr-message: 'Stale issue message'
|
stale-pr-message: 'Stale issue message'
|
||||||
stale-issue-label: 'no-issue-activity'
|
stale-issue-label: 'no-issue-activity'
|
||||||
exempt-issue-labels: 'awaiting-approval,work-in-progress'
|
exempt-issue-label: 'awaiting-approval'
|
||||||
stale-pr-label: 'no-pr-activity'
|
stale-pr-label: 'no-pr-activity'
|
||||||
exempt-pr-labels: 'awaiting-approval,work-in-progress'
|
exempt-pr-label: 'awaiting-approval'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Debugging
|
|
||||||
|
|
||||||
To see debug ouput from this action, you must set the secret `ACTIONS_STEP_DEBUG` to `true` in your repository. You can run this action in debug only mode (no actions will be taken on your issues) by passing `debug-only` `true` as an argument to the action.
|
|
||||||
@@ -1,202 +1,3 @@
|
|||||||
import * as core from '@actions/core';
|
describe('TODO - Add a test suite', () => {
|
||||||
import * as github from '@actions/github';
|
it('TODO - Add a test', async () => {});
|
||||||
import {Octokit} from '@octokit/rest';
|
|
||||||
|
|
||||||
import {
|
|
||||||
IssueProcessor,
|
|
||||||
Issue,
|
|
||||||
Label,
|
|
||||||
IssueProcessorOptions
|
|
||||||
} from '../src/IssueProcessor';
|
|
||||||
|
|
||||||
function generateIssue(
|
|
||||||
id: number,
|
|
||||||
title: string,
|
|
||||||
updatedAt: string,
|
|
||||||
isPullRequest: boolean = false,
|
|
||||||
labels: string[] = []
|
|
||||||
): Issue {
|
|
||||||
return {
|
|
||||||
number: id,
|
|
||||||
labels: labels.map(l => {
|
|
||||||
return {name: l};
|
|
||||||
}),
|
|
||||||
title: title,
|
|
||||||
updated_at: updatedAt,
|
|
||||||
pull_request: isPullRequest ? {} : null
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
const DefaultProcessorOptions: IssueProcessorOptions = {
|
|
||||||
repoToken: 'none',
|
|
||||||
staleIssueMessage: 'This issue is stale',
|
|
||||||
stalePrMessage: 'This PR is stale',
|
|
||||||
daysBeforeStale: 1,
|
|
||||||
daysBeforeClose: 1,
|
|
||||||
staleIssueLabel: 'Stale',
|
|
||||||
exemptIssueLabels: '',
|
|
||||||
stalePrLabel: 'Stale',
|
|
||||||
exemptPrLabels: '',
|
|
||||||
onlyLabels: '',
|
|
||||||
operationsPerRun: 100,
|
|
||||||
debugOnly: true
|
|
||||||
};
|
|
||||||
|
|
||||||
test('empty issue list results in 1 operation', async () => {
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async () => []);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
const operationsLeft = await processor.processIssues(1);
|
|
||||||
|
|
||||||
// processing an empty issue list should result in 1 operation
|
|
||||||
expect(operationsLeft).toEqual(99);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('processing an issue with no label will make it stale', async () => {
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z')
|
|
||||||
];
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
||||||
p == 1 ? TestIssueList : []
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(1);
|
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('processing a stale issue will close it', async () => {
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Stale'])
|
|
||||||
];
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
||||||
p == 1 ? TestIssueList : []
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
|
||||||
expect(processor.closedIssues.length).toEqual(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('processing a stale PR will close it', async () => {
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, ['Stale'])
|
|
||||||
];
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
||||||
p == 1 ? TestIssueList : []
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
|
||||||
expect(processor.closedIssues.length).toEqual(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('exempt issue labels will not be marked stale', async () => {
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [
|
|
||||||
'Exempt'
|
|
||||||
])
|
|
||||||
];
|
|
||||||
|
|
||||||
let opts = DefaultProcessorOptions;
|
|
||||||
opts.exemptIssueLabels = 'Exempt';
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
||||||
p == 1 ? TestIssueList : []
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('exempt issue labels will not be marked stale (multi issue label with spaces)', async () => {
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool'])
|
|
||||||
];
|
|
||||||
|
|
||||||
let opts = DefaultProcessorOptions;
|
|
||||||
opts.exemptIssueLabels = 'Exempt, Cool, None';
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
||||||
p == 1 ? TestIssueList : []
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('exempt issue labels will not be marked stale (multi issue label)', async () => {
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool'])
|
|
||||||
];
|
|
||||||
|
|
||||||
let opts = DefaultProcessorOptions;
|
|
||||||
opts.exemptIssueLabels = 'Exempt,Cool,None';
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
||||||
p == 1 ? TestIssueList : []
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('exempt pr labels will not be marked stale', async () => {
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool']),
|
|
||||||
generateIssue(2, 'My first PR', '2020-01-01T17:00:00Z', true, ['Cool']),
|
|
||||||
generateIssue(3, 'Another issue', '2020-01-01T17:00:00Z', false)
|
|
||||||
];
|
|
||||||
|
|
||||||
let opts = DefaultProcessorOptions;
|
|
||||||
opts.exemptIssueLabels = 'Cool';
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
||||||
p == 1 ? TestIssueList : []
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(2); // PR should get processed even though it has an exempt **issue** label
|
|
||||||
});
|
|
||||||
|
|
||||||
test('stale issues should not be closed if days is set to -1', async () => {
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, [
|
|
||||||
'Stale'
|
|
||||||
]),
|
|
||||||
generateIssue(2, 'My first PR', '2020-01-01T17:00:00Z', true, ['Stale']),
|
|
||||||
generateIssue(3, 'Another issue', '2020-01-01T17:00:00Z', false, ['Stale'])
|
|
||||||
];
|
|
||||||
|
|
||||||
let opts = DefaultProcessorOptions;
|
|
||||||
opts.daysBeforeClose = -1;
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
|
||||||
p == 1 ? TestIssueList : []
|
|
||||||
);
|
|
||||||
|
|
||||||
// process our fake issue list
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
|
||||||
});
|
});
|
||||||
|
|||||||
13
action.yml
13
action.yml
@@ -18,24 +18,19 @@ 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'
|
||||||
exempt-issue-labels:
|
exempt-issue-label:
|
||||||
description: 'The labels to apply when an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
description: 'The label to apply when an issue is exempt from being marked stale.'
|
||||||
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'
|
||||||
exempt-pr-labels:
|
exempt-pr-label:
|
||||||
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 label to apply when a pull request is exempt from being marked stale.'
|
||||||
default: ''
|
|
||||||
only-labels:
|
only-labels:
|
||||||
description: 'Only issues or pull requests with all of these labels are checked if stale. Defaults to `[]` (disabled) and can be a comma-separated list of labels.'
|
description: 'Only issues or pull requests with all of these labels are checked if stale. Defaults to `[]` (disabled) and can be a comma-separated list of labels.'
|
||||||
default: ''
|
default: ''
|
||||||
operations-per-run:
|
operations-per-run:
|
||||||
description: 'The maximum number of operations per run, used to control rate limiting.'
|
description: 'The maximum number of operations per run, used to control rate limiting.'
|
||||||
default: 30
|
default: 30
|
||||||
debug-only:
|
|
||||||
description: 'Run the processor in debug mode without actually performing any operations on live issues.'
|
|
||||||
default: false
|
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
main: 'dist/index.js'
|
main: 'dist/index.js'
|
||||||
|
|||||||
2288
dist/index.js
vendored
2288
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
65
package-lock.json
generated
65
package-lock.json
generated
@@ -10,19 +10,54 @@
|
|||||||
"integrity": "sha512-Wp4xnyokakM45Uuj4WLUxdsa8fJjKVl1fDTsPbTEcTcuu0Nb26IPQbOtjmnfaCPGcaoPOOqId8H9NapZ8gii4w=="
|
"integrity": "sha512-Wp4xnyokakM45Uuj4WLUxdsa8fJjKVl1fDTsPbTEcTcuu0Nb26IPQbOtjmnfaCPGcaoPOOqId8H9NapZ8gii4w=="
|
||||||
},
|
},
|
||||||
"@actions/github": {
|
"@actions/github": {
|
||||||
"version": "2.2.0",
|
"version": "2.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/github/-/github-2.2.0.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/github/-/github-2.1.1.tgz",
|
||||||
"integrity": "sha512-9UAZqn8ywdR70n3GwVle4N8ALosQs4z50N7XMXrSTUVOmVpaBC5kE3TRTT7qQdi3OaQV24mjGuJZsHUmhD+ZXw==",
|
"integrity": "sha512-kAgTGUx7yf5KQCndVeHSwCNZuDBvPyxm5xKTswW2lofugeuC1AZX73nUUVDNaysnM9aKFMHv9YCdVJbg7syEyA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@actions/http-client": "^1.0.3",
|
"@actions/http-client": "^1.0.3",
|
||||||
"@octokit/graphql": "^4.3.1",
|
"@octokit/graphql": "^4.3.1",
|
||||||
"@octokit/rest": "^16.43.1"
|
"@octokit/rest": "^16.43.1"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@octokit/request-error": {
|
||||||
|
"version": "1.2.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@octokit/request-error/-/request-error-1.2.1.tgz",
|
||||||
|
"integrity": "sha512-+6yDyk1EES6WK+l3viRDElw96MvwfJxCt45GvmjDUKWjYIb3PJZQkq3i46TwGwoPD4h8NmTrENmtyA1FwbmhRA==",
|
||||||
|
"requires": {
|
||||||
|
"@octokit/types": "^2.0.0",
|
||||||
|
"deprecation": "^2.0.0",
|
||||||
|
"once": "^1.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"@octokit/rest": {
|
||||||
|
"version": "16.43.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@octokit/rest/-/rest-16.43.1.tgz",
|
||||||
|
"integrity": "sha512-gfFKwRT/wFxq5qlNjnW2dh+qh74XgTQ2B179UX5K1HYCluioWj8Ndbgqw2PVqa1NnVJkGHp2ovMpVn/DImlmkw==",
|
||||||
|
"requires": {
|
||||||
|
"@octokit/auth-token": "^2.4.0",
|
||||||
|
"@octokit/plugin-paginate-rest": "^1.1.1",
|
||||||
|
"@octokit/plugin-request-log": "^1.0.0",
|
||||||
|
"@octokit/plugin-rest-endpoint-methods": "2.4.0",
|
||||||
|
"@octokit/request": "^5.2.0",
|
||||||
|
"@octokit/request-error": "^1.0.2",
|
||||||
|
"atob-lite": "^2.0.0",
|
||||||
|
"before-after-hook": "^2.0.0",
|
||||||
|
"btoa-lite": "^1.0.0",
|
||||||
|
"deprecation": "^2.0.0",
|
||||||
|
"lodash.get": "^4.4.2",
|
||||||
|
"lodash.set": "^4.3.2",
|
||||||
|
"lodash.uniq": "^4.5.0",
|
||||||
|
"octokit-pagination-methods": "^1.1.0",
|
||||||
|
"once": "^1.4.0",
|
||||||
|
"universal-user-agent": "^4.0.0"
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@actions/http-client": {
|
"@actions/http-client": {
|
||||||
"version": "1.0.8",
|
"version": "1.0.7",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.7.tgz",
|
||||||
"integrity": "sha512-G4JjJ6f9Hb3Zvejj+ewLLKLf99ZC+9v+yCxoYf9vSyH+WkzPLB2LuUtRMGNkooMqdugGBFStIKXOuvH1W+EctA==",
|
"integrity": "sha512-PY3ys/XH5WMekkHyZhYSa/scYvlE5T/TV/T++vABHuY5ZRgtiBZkn2L2tV5Pv/xDCl59lSZb9WwRuWExDyAsSg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"tunnel": "0.0.6"
|
"tunnel": "0.0.6"
|
||||||
}
|
}
|
||||||
@@ -522,23 +557,13 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@octokit/graphql": {
|
"@octokit/graphql": {
|
||||||
"version": "4.4.0",
|
"version": "4.3.1",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.4.0.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.3.1.tgz",
|
||||||
"integrity": "sha512-Du3hAaSROQ8EatmYoSAJjzAz3t79t9Opj/WY1zUgxVUGfIKn0AEjg+hlOLscF6fv6i/4y/CeUvsWgIfwMkTccw==",
|
"integrity": "sha512-hCdTjfvrK+ilU2keAdqNBWOk+gm1kai1ZcdjRfB30oA3/T6n53UVJb7w0L5cR3/rhU91xT3HSqCd+qbvH06yxA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@octokit/request": "^5.3.0",
|
"@octokit/request": "^5.3.0",
|
||||||
"@octokit/types": "^2.0.0",
|
"@octokit/types": "^2.0.0",
|
||||||
"universal-user-agent": "^5.0.0"
|
"universal-user-agent": "^4.0.0"
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"universal-user-agent": {
|
|
||||||
"version": "5.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/universal-user-agent/-/universal-user-agent-5.0.0.tgz",
|
|
||||||
"integrity": "sha512-B5TPtzZleXyPrUMKCpEHFmVhMN6EhmJYjG5PQna9s7mXeSqGTLap4OpqLl5FCEFUI3UBmllkETwKf/db66Y54Q==",
|
|
||||||
"requires": {
|
|
||||||
"os-name": "^3.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@octokit/plugin-paginate-rest": {
|
"@octokit/plugin-paginate-rest": {
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.3",
|
"@actions/core": "^1.2.3",
|
||||||
"@actions/github": "^2.2.0",
|
"@actions/github": "^2.1.1",
|
||||||
"@octokit/rest": "^16.43.1",
|
"@octokit/rest": "^16.43.1",
|
||||||
"semver": "^6.1.1"
|
"semver": "^6.1.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,230 +0,0 @@
|
|||||||
import * as core from '@actions/core';
|
|
||||||
import * as github from '@actions/github';
|
|
||||||
import {Octokit} from '@octokit/rest';
|
|
||||||
|
|
||||||
type OcotoKitIssueList = Octokit.Response<Octokit.IssuesListForRepoResponse>;
|
|
||||||
|
|
||||||
export interface Issue {
|
|
||||||
title: string;
|
|
||||||
number: number;
|
|
||||||
updated_at: string;
|
|
||||||
labels: Label[];
|
|
||||||
pull_request: any;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface Label {
|
|
||||||
name: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface IssueProcessorOptions {
|
|
||||||
repoToken: string;
|
|
||||||
staleIssueMessage: string;
|
|
||||||
stalePrMessage: string;
|
|
||||||
daysBeforeStale: number;
|
|
||||||
daysBeforeClose: number;
|
|
||||||
staleIssueLabel: string;
|
|
||||||
exemptIssueLabels: string;
|
|
||||||
stalePrLabel: string;
|
|
||||||
exemptPrLabels: string;
|
|
||||||
onlyLabels: string;
|
|
||||||
operationsPerRun: number;
|
|
||||||
debugOnly: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* Handle processing of issues for staleness/closure.
|
|
||||||
*/
|
|
||||||
export class IssueProcessor {
|
|
||||||
readonly client: github.GitHub;
|
|
||||||
readonly options: IssueProcessorOptions;
|
|
||||||
private operationsLeft: number = 0;
|
|
||||||
|
|
||||||
readonly staleIssues: Issue[] = [];
|
|
||||||
readonly closedIssues: Issue[] = [];
|
|
||||||
|
|
||||||
constructor(
|
|
||||||
options: IssueProcessorOptions,
|
|
||||||
getIssues?: (page: number) => Promise<Issue[]>
|
|
||||||
) {
|
|
||||||
this.options = options;
|
|
||||||
this.operationsLeft = options.operationsPerRun;
|
|
||||||
this.client = new github.GitHub(options.repoToken);
|
|
||||||
|
|
||||||
if (getIssues) {
|
|
||||||
this.getIssues = getIssues;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.options.debugOnly) {
|
|
||||||
core.warning(
|
|
||||||
'Executing in debug mode. Debug output will be written but no issues will be processed.'
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
|
||||||
const issues: Issue[] = await this.getIssues(page);
|
|
||||||
this.operationsLeft -= 1;
|
|
||||||
|
|
||||||
if (issues.length <= 0) {
|
|
||||||
core.debug('No more issues found to process. Exiting.');
|
|
||||||
return this.operationsLeft;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (const issue of issues.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 exemptLabels = IssueProcessor.parseCommaSeparatedString(
|
|
||||||
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
|
|
||||||
);
|
|
||||||
const issueType: string = isPr ? 'pr' : 'issue';
|
|
||||||
|
|
||||||
if (!staleMessage) {
|
|
||||||
core.debug(`Skipping ${issueType} due to empty stale message`);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (
|
|
||||||
exemptLabels.some((exemptLabel: string) =>
|
|
||||||
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 this.processIssues(page + 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// grab issues from github in baches of 100
|
|
||||||
private async getIssues(page: number): Promise<Issue[]> {
|
|
||||||
const issueResult: OcotoKitIssueList = await this.client.issues.listForRepo(
|
|
||||||
{
|
|
||||||
owner: github.context.repo.owner,
|
|
||||||
repo: github.context.repo.repo,
|
|
||||||
state: 'open',
|
|
||||||
labels: this.options.onlyLabels,
|
|
||||||
per_page: 100,
|
|
||||||
page
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return issueResult.data;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mark an issue as stale with a comment and a label
|
|
||||||
private async markStale(
|
|
||||||
issue: Issue,
|
|
||||||
staleMessage: string,
|
|
||||||
staleLabel: string
|
|
||||||
): Promise<void> {
|
|
||||||
core.debug(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
|
||||||
|
|
||||||
this.staleIssues.push(issue);
|
|
||||||
|
|
||||||
if (this.options.debugOnly) {
|
|
||||||
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
|
|
||||||
private async closeIssue(issue: Issue): Promise<void> {
|
|
||||||
core.debug(
|
|
||||||
`Closing issue #${issue.number} - ${issue.title} for being stale`
|
|
||||||
);
|
|
||||||
|
|
||||||
this.closedIssues.push(issue);
|
|
||||||
|
|
||||||
if (this.options.debugOnly) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
await this.client.issues.update({
|
|
||||||
owner: github.context.repo.owner,
|
|
||||||
repo: github.context.repo.repo,
|
|
||||||
issue_number: issue.number,
|
|
||||||
state: 'closed'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private static isLabeled(issue: Issue, label: string): boolean {
|
|
||||||
const labelComparer: (l: Label) => boolean = l =>
|
|
||||||
label.localeCompare(l.name, undefined, {sensitivity: 'accent'}) === 0;
|
|
||||||
return issue.labels.filter(labelComparer).length > 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static parseCommaSeparatedString(s: string): string[] {
|
|
||||||
// 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(',').map(l => l.trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
151
src/main.ts
151
src/main.ts
@@ -1,19 +1,155 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {IssueProcessor, IssueProcessorOptions} from './IssueProcessor';
|
import * as github from '@actions/github';
|
||||||
|
import {Octokit} from '@octokit/rest';
|
||||||
|
|
||||||
|
type Issue = Octokit.IssuesListForRepoResponseItem;
|
||||||
|
type IssueLabel = Octokit.IssuesListForRepoResponseItemLabelsItem;
|
||||||
|
|
||||||
|
interface Args {
|
||||||
|
repoToken: string;
|
||||||
|
staleIssueMessage: string;
|
||||||
|
stalePrMessage: string;
|
||||||
|
daysBeforeStale: number;
|
||||||
|
daysBeforeClose: number;
|
||||||
|
staleIssueLabel: string;
|
||||||
|
exemptIssueLabel: string;
|
||||||
|
stalePrLabel: string;
|
||||||
|
exemptPrLabel: string;
|
||||||
|
onlyLabels: string;
|
||||||
|
operationsPerRun: number;
|
||||||
|
}
|
||||||
|
|
||||||
async function run(): Promise<void> {
|
async function run(): Promise<void> {
|
||||||
try {
|
try {
|
||||||
const args = getAndValidateArgs();
|
const args = getAndValidateArgs();
|
||||||
|
|
||||||
const processor: IssueProcessor = new IssueProcessor(args);
|
const client = new github.GitHub(args.repoToken);
|
||||||
await processor.processIssues();
|
await processIssues(client, args, args.operationsPerRun);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(error);
|
core.error(error);
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAndValidateArgs(): IssueProcessorOptions {
|
async function processIssues(
|
||||||
|
client: github.GitHub,
|
||||||
|
args: Args,
|
||||||
|
operationsLeft: number,
|
||||||
|
page: number = 1
|
||||||
|
): Promise<number> {
|
||||||
|
const issues = await 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 exemptLabel = isPr ? args.exemptPrLabel : args.exemptIssueLabel;
|
||||||
|
|
||||||
|
if (exemptLabel && isLabeled(issue, exemptLabel)) {
|
||||||
|
continue;
|
||||||
|
} else if (isLabeled(issue, staleLabel)) {
|
||||||
|
if (
|
||||||
|
args.daysBeforeClose >= 0 &&
|
||||||
|
wasLastUpdatedBefore(issue, args.daysBeforeClose)
|
||||||
|
) {
|
||||||
|
operationsLeft -= await closeIssue(client, issue);
|
||||||
|
} else {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
} else if (wasLastUpdatedBefore(issue, args.daysBeforeStale)) {
|
||||||
|
operationsLeft -= await markStale(
|
||||||
|
client,
|
||||||
|
issue,
|
||||||
|
staleMessage,
|
||||||
|
staleLabel
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (operationsLeft <= 0) {
|
||||||
|
core.warning(
|
||||||
|
`performed ${args.operationsPerRun} operations, exiting to avoid rate limit`
|
||||||
|
);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return await processIssues(client, args, operationsLeft, page + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
function isLabeled(issue: Issue, label: string): boolean {
|
||||||
|
const labelComparer: (l: IssueLabel) => boolean = l =>
|
||||||
|
label.localeCompare(l.name, undefined, {sensitivity: 'accent'}) === 0;
|
||||||
|
return issue.labels.filter(labelComparer).length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function markStale(
|
||||||
|
client: github.GitHub,
|
||||||
|
issue: Issue,
|
||||||
|
staleMessage: string,
|
||||||
|
staleLabel: string
|
||||||
|
): Promise<number> {
|
||||||
|
core.debug(`marking issue${issue.title} as stale`);
|
||||||
|
|
||||||
|
await client.issues.createComment({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
body: staleMessage
|
||||||
|
});
|
||||||
|
|
||||||
|
await client.issues.addLabels({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
labels: [staleLabel]
|
||||||
|
});
|
||||||
|
|
||||||
|
return 2; // operations performed
|
||||||
|
}
|
||||||
|
|
||||||
|
async function closeIssue(
|
||||||
|
client: github.GitHub,
|
||||||
|
issue: Issue
|
||||||
|
): Promise<number> {
|
||||||
|
core.debug(`closing issue ${issue.title} for being stale`);
|
||||||
|
|
||||||
|
await client.issues.update({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
state: 'closed'
|
||||||
|
});
|
||||||
|
|
||||||
|
return 1; // operations performed
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAndValidateArgs(): Args {
|
||||||
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'),
|
||||||
@@ -25,14 +161,13 @@ 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}),
|
||||||
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(
|
operationsPerRun: parseInt(
|
||||||
core.getInput('operations-per-run', {required: true})
|
core.getInput('operations-per-run', {required: true})
|
||||||
),
|
)
|
||||||
debugOnly: core.getInput('debug-only') === 'true'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const numberInput of [
|
for (const numberInput of [
|
||||||
|
|||||||
Reference in New Issue
Block a user