mirror of
https://github.com/actions/stale.git
synced 2025-12-27 10:48:18 +00:00
Compare commits
9 Commits
remove_sta
...
v3.0.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5ce6b77f2c | ||
|
|
71d46bfe23 | ||
|
|
e611bf905b | ||
|
|
1e900bc060 | ||
|
|
3838b887be | ||
|
|
4f9b6a7a5c | ||
|
|
8743296016 | ||
|
|
7328f2e6e5 | ||
|
|
2b063ba4d4 |
10
README.md
10
README.md
@@ -34,7 +34,7 @@ jobs:
|
|||||||
stale:
|
stale:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v1.1.0
|
- uses: actions/stale@v3
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
stale-issue-message: 'Message to comment on stale issues. If none provided, will not mark issues stale'
|
stale-issue-message: 'Message to comment on stale issues. If none provided, will not mark issues stale'
|
||||||
@@ -52,7 +52,7 @@ jobs:
|
|||||||
stale:
|
stale:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v1.1.0
|
- uses: actions/stale@v3
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
|
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
|
||||||
@@ -71,11 +71,11 @@ jobs:
|
|||||||
stale:
|
stale:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v1.1.0
|
- uses: actions/stale@v3
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
stale-issue-message: 'Stale issue message'
|
stale-issue-message: 'Stale issue message'
|
||||||
stale-pr-message: 'Stale issue message'
|
stale-pr-message: 'Stale pull request message'
|
||||||
stale-issue-label: 'no-issue-activity'
|
stale-issue-label: 'no-issue-activity'
|
||||||
exempt-issue-labels: 'awaiting-approval,work-in-progress'
|
exempt-issue-labels: 'awaiting-approval,work-in-progress'
|
||||||
stale-pr-label: 'no-pr-activity'
|
stale-pr-label: 'no-pr-activity'
|
||||||
@@ -84,4 +84,4 @@ jobs:
|
|||||||
|
|
||||||
### Debugging
|
### 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.
|
To see debug output 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.
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ const DefaultProcessorOptions: IssueProcessorOptions = {
|
|||||||
staleIssueMessage: 'This issue is stale',
|
staleIssueMessage: 'This issue is stale',
|
||||||
stalePrMessage: 'This PR is stale',
|
stalePrMessage: 'This PR is stale',
|
||||||
daysBeforeStale: 1,
|
daysBeforeStale: 1,
|
||||||
daysBeforeClose: 1,
|
daysBeforeClose: 30,
|
||||||
staleIssueLabel: 'Stale',
|
staleIssueLabel: 'Stale',
|
||||||
exemptIssueLabels: '',
|
exemptIssueLabels: '',
|
||||||
stalePrLabel: 'Stale',
|
stalePrLabel: 'Stale',
|
||||||
@@ -62,7 +62,7 @@ test('empty issue list results in 1 operation', async () => {
|
|||||||
expect(operationsLeft).toEqual(99);
|
expect(operationsLeft).toEqual(99);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('processing an issue with no label will make it stale', async () => {
|
test('processing an issue with no label will make it stale and close it, if it is old enough', async () => {
|
||||||
const TestIssueList: Issue[] = [
|
const TestIssueList: Issue[] = [
|
||||||
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z')
|
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z')
|
||||||
];
|
];
|
||||||
@@ -77,6 +77,30 @@ test('processing an issue with no label will make it stale', async () => {
|
|||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
await processor.processIssues(1);
|
await processor.processIssues(1);
|
||||||
|
|
||||||
|
expect(processor.staleIssues.length).toEqual(1);
|
||||||
|
expect(processor.closedIssues.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('processing an issue with no label will make it stale but not close it', async () => {
|
||||||
|
// issue should be from 2 days ago so it will be
|
||||||
|
// stale but not close-able, based on default settings
|
||||||
|
let issueDate = new Date();
|
||||||
|
issueDate.setDate(issueDate.getDate() - 2);
|
||||||
|
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(1, 'An issue with no label', issueDate.toDateString())
|
||||||
|
];
|
||||||
|
|
||||||
|
const processor = new IssueProcessor(
|
||||||
|
DefaultProcessorOptions,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
|
);
|
||||||
|
|
||||||
|
// process our fake issue list
|
||||||
|
await processor.processIssues(1);
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(1);
|
expect(processor.staleIssues.length).toEqual(1);
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
});
|
});
|
||||||
@@ -480,3 +504,64 @@ test('stale label should be removed if a comment was added to a stale issue', as
|
|||||||
expect(processor.staleIssues.length).toEqual(0);
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
expect(processor.removedLabelIssues.length).toEqual(1);
|
expect(processor.removedLabelIssues.length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('stale issues should not be closed until after the closed number of days', async () => {
|
||||||
|
let lastUpdate = new Date();
|
||||||
|
lastUpdate.setDate(lastUpdate.getDate() - 5);
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'An issue that should be marked stale but not closed',
|
||||||
|
lastUpdate.toString(),
|
||||||
|
false
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
const opts = DefaultProcessorOptions;
|
||||||
|
opts.daysBeforeStale = 5; // stale after 5 days
|
||||||
|
opts.daysBeforeClose = 1; // closes after 6 days
|
||||||
|
|
||||||
|
const processor = new IssueProcessor(
|
||||||
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
|
);
|
||||||
|
|
||||||
|
// process our fake issue list
|
||||||
|
await processor.processIssues(1);
|
||||||
|
|
||||||
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
|
expect(processor.staleIssues.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('stale issues should be closed if the closed nubmer of days (additive) is also passed', async () => {
|
||||||
|
let lastUpdate = new Date();
|
||||||
|
lastUpdate.setDate(lastUpdate.getDate() - 7);
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'An issue that should be stale and closed',
|
||||||
|
lastUpdate.toString(),
|
||||||
|
false,
|
||||||
|
['Stale']
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
const opts = DefaultProcessorOptions;
|
||||||
|
opts.daysBeforeStale = 5; // stale after 5 days
|
||||||
|
opts.daysBeforeClose = 1; // closes after 6 days
|
||||||
|
|
||||||
|
const processor = new IssueProcessor(
|
||||||
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
|
);
|
||||||
|
|
||||||
|
// process our fake issue list
|
||||||
|
await processor.processIssues(1);
|
||||||
|
|
||||||
|
expect(processor.closedIssues.length).toEqual(1);
|
||||||
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|||||||
36
dist/index.js
vendored
36
dist/index.js
vendored
@@ -8510,14 +8510,20 @@ class IssueProcessor {
|
|||||||
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
||||||
continue; // don't process exempt issues
|
continue; // don't process exempt issues
|
||||||
}
|
}
|
||||||
if (IssueProcessor.isLabeled(issue, staleLabel)) {
|
// does this issue have a stale label?
|
||||||
core.debug(`Found a stale ${issueType}`);
|
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
||||||
yield this.processStaleIssue(issue, issueType, staleLabel);
|
// determine if this issue needs to be marked stale first
|
||||||
}
|
if (!isStale &&
|
||||||
else if (!IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale)) {
|
!IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale)) {
|
||||||
core.debug(`Marking ${issueType} stale because it was last updated on ${issue.updated_at}`);
|
core.debug(`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`);
|
||||||
yield this.markStale(issue, staleMessage, staleLabel);
|
yield this.markStale(issue, staleMessage, staleLabel);
|
||||||
this.operationsLeft -= 2;
|
this.operationsLeft -= 2;
|
||||||
|
isStale = true; // this issue is now considered stale
|
||||||
|
}
|
||||||
|
// process any issues marked stale (including the issue above, if it was marked)
|
||||||
|
if (isStale) {
|
||||||
|
core.debug(`Found a stale ${issueType}`);
|
||||||
|
yield this.processStaleIssue(issue, issueType, staleLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// do the next batch
|
// do the next batch
|
||||||
@@ -8526,14 +8532,20 @@ class IssueProcessor {
|
|||||||
}
|
}
|
||||||
// handle all of the stale issue logic when we find a stale issue
|
// handle all of the stale issue logic when we find a stale issue
|
||||||
processStaleIssue(issue, issueType, staleLabel) {
|
processStaleIssue(issue, issueType, staleLabel) {
|
||||||
|
var _a;
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (this.options.daysBeforeClose < 0) {
|
if (this.options.daysBeforeClose < 0) {
|
||||||
return; // nothing to do because we aren't closing stale issues
|
return; // nothing to do because we aren't closing stale issues
|
||||||
}
|
}
|
||||||
const markedStaleOn = yield this.getLabelCreationDate(issue, staleLabel);
|
const markedStaleOn = yield this.getLabelCreationDate(issue, staleLabel);
|
||||||
const issueHasComments = yield this.isIssueStillStale(issue, markedStaleOn);
|
const issueHasComments = yield this.isIssueStillStale(issue, markedStaleOn || issue.updated_at);
|
||||||
const issueHasUpdate = IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeClose);
|
const issueHasUpdate = IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeClose + ((_a = this.options.daysBeforeStale) !== null && _a !== void 0 ? _a : 0));
|
||||||
core.debug(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
if (markedStaleOn) {
|
||||||
|
core.debug(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.debug(`Issue #${issue.number} is not marked stale, but last update of ${issue.updated_at} is older than ${this.options.daysBeforeStale} days`);
|
||||||
|
}
|
||||||
core.debug(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
core.debug(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||||
core.debug(`Issue #${issue.number} has been commented on: ${issueHasComments}`);
|
core.debug(`Issue #${issue.number} has been commented on: ${issueHasComments}`);
|
||||||
if (!issueHasComments && !issueHasUpdate) {
|
if (!issueHasComments && !issueHasUpdate) {
|
||||||
@@ -8544,7 +8556,7 @@ class IssueProcessor {
|
|||||||
if (this.options.removeStaleWhenUpdated) {
|
if (this.options.removeStaleWhenUpdated) {
|
||||||
yield this.removeLabel(issue, staleLabel);
|
yield this.removeLabel(issue, staleLabel);
|
||||||
}
|
}
|
||||||
core.debug(`Ignoring stale ${issueType} because it was updated recenlty`);
|
core.debug(`Ignoring stale ${issueType} because it was updated recently`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -8661,6 +8673,10 @@ class IssueProcessor {
|
|||||||
const events = yield this.client.paginate(options);
|
const events = yield this.client.paginate(options);
|
||||||
const reversedEvents = events.reverse();
|
const reversedEvents = events.reverse();
|
||||||
const staleLabeledEvent = reversedEvents.find(event => event.event === 'labeled' && event.label.name === label);
|
const staleLabeledEvent = reversedEvents.find(event => event.event === 'labeled' && event.label.name === label);
|
||||||
|
if (!staleLabeledEvent) {
|
||||||
|
// Must be old rather than labeled
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
return staleLabeledEvent.created_at;
|
return staleLabeledEvent.created_at;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
71
package-lock.json
generated
71
package-lock.json
generated
@@ -5,59 +5,24 @@
|
|||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.2.3",
|
"version": "1.2.4",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.4.tgz",
|
||||||
"integrity": "sha512-Wp4xnyokakM45Uuj4WLUxdsa8fJjKVl1fDTsPbTEcTcuu0Nb26IPQbOtjmnfaCPGcaoPOOqId8H9NapZ8gii4w=="
|
"integrity": "sha512-YJCEq8BE3CdN8+7HPZ/4DxJjk/OkZV2FFIf+DlZTC/4iBlzYCD5yjRR6eiOS5llO11zbRltIRuKAjMKaWTE6cg=="
|
||||||
},
|
},
|
||||||
"@actions/github": {
|
"@actions/github": {
|
||||||
"version": "2.1.1",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/github/-/github-2.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/github/-/github-2.2.0.tgz",
|
||||||
"integrity": "sha512-kAgTGUx7yf5KQCndVeHSwCNZuDBvPyxm5xKTswW2lofugeuC1AZX73nUUVDNaysnM9aKFMHv9YCdVJbg7syEyA==",
|
"integrity": "sha512-9UAZqn8ywdR70n3GwVle4N8ALosQs4z50N7XMXrSTUVOmVpaBC5kE3TRTT7qQdi3OaQV24mjGuJZsHUmhD+ZXw==",
|
||||||
"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.7",
|
"version": "1.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.7.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.8.tgz",
|
||||||
"integrity": "sha512-PY3ys/XH5WMekkHyZhYSa/scYvlE5T/TV/T++vABHuY5ZRgtiBZkn2L2tV5Pv/xDCl59lSZb9WwRuWExDyAsSg==",
|
"integrity": "sha512-G4JjJ6f9Hb3Zvejj+ewLLKLf99ZC+9v+yCxoYf9vSyH+WkzPLB2LuUtRMGNkooMqdugGBFStIKXOuvH1W+EctA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"tunnel": "0.0.6"
|
"tunnel": "0.0.6"
|
||||||
}
|
}
|
||||||
@@ -557,13 +522,23 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"@octokit/graphql": {
|
"@octokit/graphql": {
|
||||||
"version": "4.3.1",
|
"version": "4.4.0",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.3.1.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/graphql/-/graphql-4.4.0.tgz",
|
||||||
"integrity": "sha512-hCdTjfvrK+ilU2keAdqNBWOk+gm1kai1ZcdjRfB30oA3/T6n53UVJb7w0L5cR3/rhU91xT3HSqCd+qbvH06yxA==",
|
"integrity": "sha512-Du3hAaSROQ8EatmYoSAJjzAz3t79t9Opj/WY1zUgxVUGfIKn0AEjg+hlOLscF6fv6i/4y/CeUvsWgIfwMkTccw==",
|
||||||
"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": "^4.0.0"
|
"universal-user-agent": "^5.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": {
|
||||||
|
|||||||
@@ -25,8 +25,8 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.3",
|
"@actions/core": "^1.2.4",
|
||||||
"@actions/github": "^2.1.1",
|
"@actions/github": "^2.2.0",
|
||||||
"@octokit/rest": "^16.43.1",
|
"@octokit/rest": "^16.43.1",
|
||||||
"semver": "^6.1.1"
|
"semver": "^6.1.1"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ 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 OcotoKitIssueList = Octokit.Response<Octokit.IssuesListForRepoResponse>;
|
type OctoKitIssueList = Octokit.Response<Octokit.IssuesListForRepoResponse>;
|
||||||
|
|
||||||
export interface Issue {
|
export interface Issue {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -67,7 +67,10 @@ export class IssueProcessor {
|
|||||||
issueNumber: number,
|
issueNumber: number,
|
||||||
sinceDate: string
|
sinceDate: string
|
||||||
) => Promise<Comment[]>,
|
) => Promise<Comment[]>,
|
||||||
getLabelCreationDate?: (issue: Issue, label: string) => Promise<string>
|
getLabelCreationDate?: (
|
||||||
|
issue: Issue,
|
||||||
|
label: string
|
||||||
|
) => Promise<string | undefined>
|
||||||
) {
|
) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.operationsLeft = options.operationsPerRun;
|
this.operationsLeft = options.operationsPerRun;
|
||||||
@@ -150,20 +153,29 @@ export class IssueProcessor {
|
|||||||
continue; // don't process exempt issues
|
continue; // don't process exempt issues
|
||||||
}
|
}
|
||||||
|
|
||||||
if (IssueProcessor.isLabeled(issue, staleLabel)) {
|
// does this issue have a stale label?
|
||||||
core.debug(`Found a stale ${issueType}`);
|
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
||||||
await this.processStaleIssue(issue, issueType, staleLabel);
|
|
||||||
} else if (
|
// determine if this issue needs to be marked stale first
|
||||||
|
if (
|
||||||
|
!isStale &&
|
||||||
!IssueProcessor.updatedSince(
|
!IssueProcessor.updatedSince(
|
||||||
issue.updated_at,
|
issue.updated_at,
|
||||||
this.options.daysBeforeStale
|
this.options.daysBeforeStale
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
core.debug(
|
core.debug(
|
||||||
`Marking ${issueType} stale because it was last updated on ${issue.updated_at}`
|
`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`
|
||||||
);
|
);
|
||||||
await this.markStale(issue, staleMessage, staleLabel);
|
await this.markStale(issue, staleMessage, staleLabel);
|
||||||
this.operationsLeft -= 2;
|
this.operationsLeft -= 2;
|
||||||
|
isStale = true; // this issue is now considered stale
|
||||||
|
}
|
||||||
|
|
||||||
|
// process any issues marked stale (including the issue above, if it was marked)
|
||||||
|
if (isStale) {
|
||||||
|
core.debug(`Found a stale ${issueType}`);
|
||||||
|
await this.processStaleIssue(issue, issueType, staleLabel);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,21 +193,26 @@ export class IssueProcessor {
|
|||||||
return; // nothing to do because we aren't closing stale issues
|
return; // nothing to do because we aren't closing stale issues
|
||||||
}
|
}
|
||||||
|
|
||||||
const markedStaleOn: string = await this.getLabelCreationDate(
|
const markedStaleOn: string | undefined = await this.getLabelCreationDate(
|
||||||
issue,
|
issue,
|
||||||
staleLabel
|
staleLabel
|
||||||
);
|
);
|
||||||
const issueHasComments: boolean = await this.isIssueStillStale(
|
const issueHasComments: boolean = await this.isIssueStillStale(
|
||||||
issue,
|
issue,
|
||||||
markedStaleOn
|
markedStaleOn || issue.updated_at
|
||||||
);
|
);
|
||||||
|
|
||||||
const issueHasUpdate: boolean = IssueProcessor.updatedSince(
|
const issueHasUpdate: boolean = IssueProcessor.updatedSince(
|
||||||
issue.updated_at,
|
issue.updated_at,
|
||||||
this.options.daysBeforeClose
|
this.options.daysBeforeClose + (this.options.daysBeforeStale ?? 0)
|
||||||
);
|
);
|
||||||
|
|
||||||
core.debug(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
if (markedStaleOn) {
|
||||||
|
core.debug(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
||||||
|
} else {
|
||||||
|
core.debug(
|
||||||
|
`Issue #${issue.number} is not marked stale, but last update of ${issue.updated_at} is older than ${this.options.daysBeforeStale} days`
|
||||||
|
);
|
||||||
|
}
|
||||||
core.debug(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
core.debug(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||||
core.debug(
|
core.debug(
|
||||||
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
||||||
@@ -210,7 +227,7 @@ export class IssueProcessor {
|
|||||||
if (this.options.removeStaleWhenUpdated) {
|
if (this.options.removeStaleWhenUpdated) {
|
||||||
await this.removeLabel(issue, staleLabel);
|
await this.removeLabel(issue, staleLabel);
|
||||||
}
|
}
|
||||||
core.debug(`Ignoring stale ${issueType} because it was updated recenlty`);
|
core.debug(`Ignoring stale ${issueType} because it was updated recently`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -254,16 +271,14 @@ export class IssueProcessor {
|
|||||||
|
|
||||||
// grab issues from github in baches of 100
|
// grab issues from github in baches of 100
|
||||||
private async getIssues(page: number): Promise<Issue[]> {
|
private async getIssues(page: number): Promise<Issue[]> {
|
||||||
const issueResult: OcotoKitIssueList = await this.client.issues.listForRepo(
|
const issueResult: OctoKitIssueList = await this.client.issues.listForRepo({
|
||||||
{
|
owner: github.context.repo.owner,
|
||||||
owner: github.context.repo.owner,
|
repo: github.context.repo.repo,
|
||||||
repo: github.context.repo.repo,
|
state: 'open',
|
||||||
state: 'open',
|
labels: this.options.onlyLabels,
|
||||||
labels: this.options.onlyLabels,
|
per_page: 100,
|
||||||
per_page: 100,
|
page
|
||||||
page
|
});
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
return issueResult.data;
|
return issueResult.data;
|
||||||
}
|
}
|
||||||
@@ -348,7 +363,7 @@ export class IssueProcessor {
|
|||||||
private async getLabelCreationDate(
|
private async getLabelCreationDate(
|
||||||
issue: Issue,
|
issue: Issue,
|
||||||
label: string
|
label: string
|
||||||
): Promise<string> {
|
): Promise<string | undefined> {
|
||||||
core.debug(`Checking for label ${label} on issue #${issue.number}`);
|
core.debug(`Checking for label ${label} on issue #${issue.number}`);
|
||||||
|
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
@@ -367,7 +382,12 @@ export class IssueProcessor {
|
|||||||
event => event.event === 'labeled' && event.label.name === label
|
event => event.event === 'labeled' && event.label.name === label
|
||||||
);
|
);
|
||||||
|
|
||||||
return staleLabeledEvent!.created_at;
|
if (!staleLabeledEvent) {
|
||||||
|
// Must be old rather than labeled
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
return staleLabeledEvent.created_at;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static isLabeled(issue: Issue, label: string): boolean {
|
private static isLabeled(issue: Issue, label: string): boolean {
|
||||||
|
|||||||
Reference in New Issue
Block a user