mirror of
https://github.com/actions/stale.git
synced 2025-12-23 17:08:18 +00:00
Compare commits
15 Commits
v2.0.1
...
better_log
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6e01d91097 | ||
|
|
55ac880ddb | ||
|
|
bb7acbc692 | ||
|
|
6d710eccec | ||
|
|
96b682d29f | ||
|
|
5ce6b77f2c | ||
|
|
71d46bfe23 | ||
|
|
e611bf905b | ||
|
|
1e900bc060 | ||
|
|
3838b887be | ||
|
|
4f9b6a7a5c | ||
|
|
8743296016 | ||
|
|
7328f2e6e5 | ||
|
|
2b063ba4d4 | ||
|
|
ae2c5c5308 |
20
.vscode/launch.json
vendored
Normal file
20
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Debug Jest Tests",
|
||||||
|
"type": "node",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceRoot}/node_modules/jest/bin/jest",
|
||||||
|
"args": [
|
||||||
|
"-i"
|
||||||
|
],
|
||||||
|
"preLaunchTask": "tsc: build - tsconfig.json",
|
||||||
|
"internalConsoleOptions": "openOnSessionStart",
|
||||||
|
"console": "integratedTerminal",
|
||||||
|
"outFiles": [
|
||||||
|
"${workspaceRoot}/build/dist/**/*"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
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.
|
||||||
|
|||||||
@@ -14,7 +14,9 @@ function generateIssue(
|
|||||||
title: string,
|
title: string,
|
||||||
updatedAt: string,
|
updatedAt: string,
|
||||||
isPullRequest: boolean = false,
|
isPullRequest: boolean = false,
|
||||||
labels: string[] = []
|
labels: string[] = [],
|
||||||
|
isClosed: boolean = false,
|
||||||
|
isLocked: boolean = false
|
||||||
): Issue {
|
): Issue {
|
||||||
return {
|
return {
|
||||||
number: id,
|
number: id,
|
||||||
@@ -23,7 +25,9 @@ function generateIssue(
|
|||||||
}),
|
}),
|
||||||
title: title,
|
title: title,
|
||||||
updated_at: updatedAt,
|
updated_at: updatedAt,
|
||||||
pull_request: isPullRequest ? {} : null
|
pull_request: isPullRequest ? {} : null,
|
||||||
|
state: isClosed ? 'closed' : 'open',
|
||||||
|
locked: isLocked
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,18 +36,24 @@ 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',
|
||||||
exemptPrLabels: '',
|
exemptPrLabels: '',
|
||||||
onlyLabels: '',
|
onlyLabels: '',
|
||||||
operationsPerRun: 100,
|
operationsPerRun: 100,
|
||||||
debugOnly: true
|
debugOnly: true,
|
||||||
|
removeStaleWhenUpdated: false
|
||||||
};
|
};
|
||||||
|
|
||||||
test('empty issue list results in 1 operation', async () => {
|
test('empty issue list results in 1 operation', async () => {
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async () => []);
|
const processor = new IssueProcessor(
|
||||||
|
DefaultProcessorOptions,
|
||||||
|
async () => [],
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
const operationsLeft = await processor.processIssues(1);
|
const operationsLeft = await processor.processIssues(1);
|
||||||
@@ -52,13 +62,40 @@ 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, 'My first issue', '2020-01-01T17:00:00Z')
|
generateIssue(1, 'An issue with no label', '2020-01-01T17:00:00Z')
|
||||||
];
|
];
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
const processor = new IssueProcessor(
|
||||||
p == 1 ? TestIssueList : []
|
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.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
|
// process our fake issue list
|
||||||
@@ -70,11 +107,20 @@ test('processing an issue with no label will make it stale', async () => {
|
|||||||
|
|
||||||
test('processing a stale issue will close it', async () => {
|
test('processing a stale issue will close it', async () => {
|
||||||
const TestIssueList: Issue[] = [
|
const TestIssueList: Issue[] = [
|
||||||
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Stale'])
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'A stale issue that should be closed',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
false,
|
||||||
|
['Stale']
|
||||||
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
const processor = new IssueProcessor(
|
||||||
p == 1 ? TestIssueList : []
|
DefaultProcessorOptions,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -86,7 +132,143 @@ test('processing a stale issue will close it', async () => {
|
|||||||
|
|
||||||
test('processing a stale PR will close it', async () => {
|
test('processing a stale PR will close it', async () => {
|
||||||
const TestIssueList: Issue[] = [
|
const TestIssueList: Issue[] = [
|
||||||
generateIssue(1, 'My first PR', '2020-01-01T17:00:00Z', true, ['Stale'])
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'A stale PR that should be closed',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
true,
|
||||||
|
['Stale']
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
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(0);
|
||||||
|
expect(processor.closedIssues.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('closed issues will not be marked stale', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'A closed issue that will not be marked',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
false,
|
||||||
|
[],
|
||||||
|
true
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
const processor = new IssueProcessor(
|
||||||
|
DefaultProcessorOptions,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => []
|
||||||
|
);
|
||||||
|
|
||||||
|
// process our fake issue list
|
||||||
|
await processor.processIssues(1);
|
||||||
|
|
||||||
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('stale closed issues will not be closed', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'A stale closed issue',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
false,
|
||||||
|
['Stale'],
|
||||||
|
true
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
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(0);
|
||||||
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('closed prs will not be marked stale', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'A closed PR that will not be marked',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
true,
|
||||||
|
[],
|
||||||
|
true
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
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(0);
|
||||||
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('stale closed prs will not be closed', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'A stale closed PR that will not be closed again',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
true,
|
||||||
|
['Stale'],
|
||||||
|
true
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
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(0);
|
||||||
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('locked issues will not be marked stale', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'A locked issue that will not be stale',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
false,
|
||||||
|
[],
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
||||||
@@ -97,7 +279,85 @@ test('processing a stale PR will close it', async () => {
|
|||||||
await processor.processIssues(1);
|
await processor.processIssues(1);
|
||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
expect(processor.closedIssues.length).toEqual(1);
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('stale locked issues will not be closed', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'A stale locked issue that will not be closed',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
false,
|
||||||
|
['Stale'],
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
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(0);
|
||||||
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('locked prs will not be marked stale', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'A locked PR that will not be marked stale',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
true,
|
||||||
|
[],
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
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('stale locked prs will not be closed', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'A stale locked PR that will not be closed',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
true,
|
||||||
|
['Stale'],
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
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(0);
|
||||||
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('exempt issue labels will not be marked stale', async () => {
|
test('exempt issue labels will not be marked stale', async () => {
|
||||||
@@ -107,11 +367,14 @@ test('exempt issue labels will not be marked stale', async () => {
|
|||||||
])
|
])
|
||||||
];
|
];
|
||||||
|
|
||||||
let opts = DefaultProcessorOptions;
|
const opts = {...DefaultProcessorOptions};
|
||||||
opts.exemptIssueLabels = 'Exempt';
|
opts.exemptIssueLabels = 'Exempt';
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
const processor = new IssueProcessor(
|
||||||
p == 1 ? TestIssueList : []
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -126,11 +389,14 @@ test('exempt issue labels will not be marked stale (multi issue label with space
|
|||||||
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool'])
|
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool'])
|
||||||
];
|
];
|
||||||
|
|
||||||
let opts = DefaultProcessorOptions;
|
const opts = {...DefaultProcessorOptions};
|
||||||
opts.exemptIssueLabels = 'Exempt, Cool, None';
|
opts.exemptIssueLabels = 'Exempt, Cool, None';
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
const processor = new IssueProcessor(
|
||||||
p == 1 ? TestIssueList : []
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -145,11 +411,14 @@ test('exempt issue labels will not be marked stale (multi issue label)', async (
|
|||||||
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool'])
|
generateIssue(1, 'My first issue', '2020-01-01T17:00:00Z', false, ['Cool'])
|
||||||
];
|
];
|
||||||
|
|
||||||
let opts = DefaultProcessorOptions;
|
const opts = {...DefaultProcessorOptions};
|
||||||
opts.exemptIssueLabels = 'Exempt,Cool,None';
|
opts.exemptIssueLabels = 'Exempt,Cool,None';
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
const processor = new IssueProcessor(
|
||||||
p == 1 ? TestIssueList : []
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -157,6 +426,7 @@ test('exempt issue labels will not be marked stale (multi issue label)', async (
|
|||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
|
expect(processor.removedLabelIssues.length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('exempt pr labels will not be marked stale', async () => {
|
test('exempt pr labels will not be marked stale', async () => {
|
||||||
@@ -166,11 +436,14 @@ test('exempt pr labels will not be marked stale', async () => {
|
|||||||
generateIssue(3, 'Another issue', '2020-01-01T17:00:00Z', false)
|
generateIssue(3, 'Another issue', '2020-01-01T17:00:00Z', false)
|
||||||
];
|
];
|
||||||
|
|
||||||
let opts = DefaultProcessorOptions;
|
const opts = {...DefaultProcessorOptions};
|
||||||
opts.exemptIssueLabels = 'Cool';
|
opts.exemptIssueLabels = 'Cool';
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
const processor = new IssueProcessor(
|
||||||
p == 1 ? TestIssueList : []
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -188,15 +461,172 @@ test('stale issues should not be closed if days is set to -1', async () => {
|
|||||||
generateIssue(3, 'Another issue', '2020-01-01T17:00:00Z', false, ['Stale'])
|
generateIssue(3, 'Another issue', '2020-01-01T17:00:00Z', false, ['Stale'])
|
||||||
];
|
];
|
||||||
|
|
||||||
let opts = DefaultProcessorOptions;
|
const opts = {...DefaultProcessorOptions};
|
||||||
opts.daysBeforeClose = -1;
|
opts.daysBeforeClose = -1;
|
||||||
|
|
||||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
const processor = new IssueProcessor(
|
||||||
p == 1 ? TestIssueList : []
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [],
|
||||||
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
await processor.processIssues(1);
|
await processor.processIssues(1);
|
||||||
|
|
||||||
expect(processor.closedIssues.length).toEqual(0);
|
expect(processor.closedIssues.length).toEqual(0);
|
||||||
|
expect(processor.removedLabelIssues.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('stale label should be removed if a comment was added to a stale issue', async () => {
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'An issue that should un-stale',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
false,
|
||||||
|
['Stale']
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
const opts = DefaultProcessorOptions;
|
||||||
|
opts.removeStaleWhenUpdated = true;
|
||||||
|
|
||||||
|
const processor = new IssueProcessor(
|
||||||
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [{user: {login: 'notme', type: 'User'}}], // return a fake comment to indicate there was an update
|
||||||
|
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(0);
|
||||||
|
expect(processor.removedLabelIssues.length).toEqual(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('stale label should not be removed if a comment was added by the bot (and the issue should be closed)', async () => {
|
||||||
|
github.context.actor = 'abot';
|
||||||
|
const TestIssueList: Issue[] = [
|
||||||
|
generateIssue(
|
||||||
|
1,
|
||||||
|
'An issue that should stay stale',
|
||||||
|
'2020-01-01T17:00:00Z',
|
||||||
|
false,
|
||||||
|
['Stale']
|
||||||
|
)
|
||||||
|
];
|
||||||
|
|
||||||
|
const opts = DefaultProcessorOptions;
|
||||||
|
opts.removeStaleWhenUpdated = true;
|
||||||
|
|
||||||
|
const processor = new IssueProcessor(
|
||||||
|
opts,
|
||||||
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
|
async (num, dt) => [{user: {login: 'abot', type: 'User'}}], // return a fake comment to indicate there was an update by the bot
|
||||||
|
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);
|
||||||
|
expect(processor.removedLabelIssues.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
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.removedLabelIssues.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.removedLabelIssues.length).toEqual(0);
|
||||||
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('stale issues should not be closed until after the closed number of days (long)', async () => {
|
||||||
|
let lastUpdate = new Date();
|
||||||
|
lastUpdate.setDate(lastUpdate.getDate() - 10);
|
||||||
|
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 = 20; // closes after 25 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.removedLabelIssues.length).toEqual(0);
|
||||||
|
expect(processor.staleIssues.length).toEqual(1);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -33,6 +33,9 @@ inputs:
|
|||||||
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
|
||||||
|
remove-stale-when-updated:
|
||||||
|
description: 'Remove stale labels from issues when they are updated or commented on.'
|
||||||
|
default: true
|
||||||
debug-only:
|
debug-only:
|
||||||
description: 'Run the processor in debug mode without actually performing any operations on live issues.'
|
description: 'Run the processor in debug mode without actually performing any operations on live issues.'
|
||||||
default: false
|
default: false
|
||||||
|
|||||||
172
dist/index.js
vendored
172
dist/index.js
vendored
@@ -3756,6 +3756,7 @@ function getAndValidateArgs() {
|
|||||||
exemptPrLabels: core.getInput('exempt-pr-labels'),
|
exemptPrLabels: core.getInput('exempt-pr-labels'),
|
||||||
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 })),
|
||||||
|
removeStaleWhenUpdated: !(core.getInput('remove-stale-when-updated') === 'false'),
|
||||||
debugOnly: core.getInput('debug-only') === 'true'
|
debugOnly: core.getInput('debug-only') === 'true'
|
||||||
};
|
};
|
||||||
for (const numberInput of [
|
for (const numberInput of [
|
||||||
@@ -8447,36 +8448,39 @@ const github = __importStar(__webpack_require__(469));
|
|||||||
* Handle processing of issues for staleness/closure.
|
* Handle processing of issues for staleness/closure.
|
||||||
*/
|
*/
|
||||||
class IssueProcessor {
|
class IssueProcessor {
|
||||||
constructor(options, getIssues) {
|
constructor(options, getIssues, listIssueComments, getLabelCreationDate) {
|
||||||
this.operationsLeft = 0;
|
this.operationsLeft = 0;
|
||||||
this.staleIssues = [];
|
this.staleIssues = [];
|
||||||
this.closedIssues = [];
|
this.closedIssues = [];
|
||||||
|
this.removedLabelIssues = [];
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.operationsLeft = options.operationsPerRun;
|
this.operationsLeft = options.operationsPerRun;
|
||||||
this.client = new github.GitHub(options.repoToken);
|
this.client = new github.GitHub(options.repoToken);
|
||||||
if (getIssues) {
|
if (getIssues) {
|
||||||
this.getIssues = getIssues;
|
this.getIssues = getIssues;
|
||||||
}
|
}
|
||||||
|
if (listIssueComments) {
|
||||||
|
this.listIssueComments = listIssueComments;
|
||||||
|
}
|
||||||
|
if (getLabelCreationDate) {
|
||||||
|
this.getLabelCreationDate = getLabelCreationDate;
|
||||||
|
}
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
core.warning('Executing in debug mode. Debug output will be written but no issues will be processed.');
|
core.warning('Executing in debug mode. Debug output will be written but no issues will be processed.');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
processIssues(page = 1) {
|
processIssues(page = 1) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
if (this.operationsLeft <= 0) {
|
|
||||||
core.warning('Reached max number of operations to process. Exiting.');
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
// get the next batch of issues
|
// get the next batch of issues
|
||||||
const issues = yield this.getIssues(page);
|
const issues = yield this.getIssues(page);
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
if (issues.length <= 0) {
|
if (issues.length <= 0) {
|
||||||
core.debug('No more issues found to process. Exiting.');
|
core.info('No more issues found to process. Exiting.');
|
||||||
return this.operationsLeft;
|
return this.operationsLeft;
|
||||||
}
|
}
|
||||||
for (const issue of issues.values()) {
|
for (const issue of issues.values()) {
|
||||||
const isPr = !!issue.pull_request;
|
const isPr = !!issue.pull_request;
|
||||||
core.debug(`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`);
|
core.info(`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`);
|
||||||
// calculate string based messages for this issue
|
// calculate string based messages for this issue
|
||||||
const staleMessage = isPr
|
const staleMessage = isPr
|
||||||
? this.options.stalePrMessage
|
? this.options.stalePrMessage
|
||||||
@@ -8487,35 +8491,102 @@ class IssueProcessor {
|
|||||||
const exemptLabels = IssueProcessor.parseCommaSeparatedString(isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels);
|
const exemptLabels = IssueProcessor.parseCommaSeparatedString(isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels);
|
||||||
const issueType = isPr ? 'pr' : 'issue';
|
const issueType = isPr ? 'pr' : 'issue';
|
||||||
if (!staleMessage) {
|
if (!staleMessage) {
|
||||||
core.debug(`Skipping ${issueType} due to empty stale message`);
|
core.info(`Skipping ${issueType} due to empty stale message`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (issue.state === 'closed') {
|
||||||
|
core.info(`Skipping ${issueType} because it is closed`);
|
||||||
|
continue; // don't process closed issues
|
||||||
|
}
|
||||||
|
if (issue.locked) {
|
||||||
|
core.info(`Skipping ${issueType} because it is locked`);
|
||||||
|
continue; // don't process locked issues
|
||||||
|
}
|
||||||
if (exemptLabels.some((exemptLabel) => IssueProcessor.isLabeled(issue, exemptLabel))) {
|
if (exemptLabels.some((exemptLabel) => IssueProcessor.isLabeled(issue, exemptLabel))) {
|
||||||
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
core.info(`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);
|
||||||
if (this.options.daysBeforeClose >= 0 &&
|
// should this issue be marked stale?
|
||||||
IssueProcessor.wasLastUpdatedBefore(issue, this.options.daysBeforeClose)) {
|
const shouldBeStale = !IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale);
|
||||||
core.debug(`Closing ${issueType} because it was last updated on ${issue.updated_at}`);
|
// determine if this issue needs to be marked stale first
|
||||||
yield this.closeIssue(issue);
|
if (!isStale && shouldBeStale) {
|
||||||
this.operationsLeft -= 1;
|
core.info(`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`);
|
||||||
}
|
|
||||||
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);
|
yield this.markStale(issue, staleMessage, staleLabel);
|
||||||
this.operationsLeft -= 2;
|
isStale = true; // this issue is now considered stale
|
||||||
}
|
}
|
||||||
|
// process the issue if it was marked stale
|
||||||
|
if (isStale) {
|
||||||
|
core.info(`Found a stale ${issueType}`);
|
||||||
|
yield this.processStaleIssue(issue, issueType, staleLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (this.operationsLeft <= 0) {
|
||||||
|
core.warning('Reached max number of operations to process. Exiting.');
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
// do the next batch
|
// do the next batch
|
||||||
return this.processIssues(page + 1);
|
return this.processIssues(page + 1);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// handle all of the stale issue logic when we find a stale issue
|
||||||
|
processStaleIssue(issue, issueType, staleLabel) {
|
||||||
|
var _a;
|
||||||
|
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}`);
|
||||||
|
const issueHasComments = yield this.hasCommentsSince(issue, markedStaleOn);
|
||||||
|
core.info(`Issue #${issue.number} has been commented on: ${issueHasComments}`);
|
||||||
|
const issueHasUpdate = IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeClose + ((_a = this.options.daysBeforeStale) !== null && _a !== void 0 ? _a : 0));
|
||||||
|
core.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||||
|
// should we un-stale this issue?
|
||||||
|
if (this.options.removeStaleWhenUpdated && issueHasComments) {
|
||||||
|
core.info(`Issue #${issue.number} is no longer stale. Removing stale label.`);
|
||||||
|
yield this.removeLabel(issue, staleLabel);
|
||||||
|
}
|
||||||
|
// now start closing logic
|
||||||
|
if (this.options.daysBeforeClose < 0) {
|
||||||
|
return; // nothing to do because we aren't closing stale issues
|
||||||
|
}
|
||||||
|
if (!issueHasComments && !issueHasUpdate) {
|
||||||
|
core.info(`Closing ${issueType} because it was last updated on ${issue.updated_at}`);
|
||||||
|
yield this.closeIssue(issue);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
core.info(`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// checks to see if a given issue is still stale (has had activity on it)
|
||||||
|
hasCommentsSince(issue, sinceDate) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.info(`Checking for comments on issue #${issue.number} since ${sinceDate}`);
|
||||||
|
if (!sinceDate) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
// find any comments since the date
|
||||||
|
const comments = yield this.listIssueComments(issue.number, sinceDate);
|
||||||
|
const filteredComments = comments.filter(comment => comment.user.type === 'User' &&
|
||||||
|
comment.user.login !== github.context.actor);
|
||||||
|
core.info(`Comments not made by ${github.context.actor} or another bot: ${filteredComments.length}`);
|
||||||
|
// if there are any user comments returned
|
||||||
|
return filteredComments.length > 0;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// grab comments for an issue since a given date
|
||||||
|
listIssueComments(issueNumber, sinceDate) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// find any comments since date on the given issue
|
||||||
|
const comments = yield this.client.issues.listComments({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issueNumber,
|
||||||
|
since: sinceDate
|
||||||
|
});
|
||||||
|
return comments.data;
|
||||||
|
});
|
||||||
|
}
|
||||||
// grab issues from github in baches of 100
|
// grab issues from github in baches of 100
|
||||||
getIssues(page) {
|
getIssues(page) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
@@ -8533,8 +8604,9 @@ class IssueProcessor {
|
|||||||
// Mark an issue as stale with a comment and a label
|
// Mark an issue as stale with a comment and a label
|
||||||
markStale(issue, staleMessage, staleLabel) {
|
markStale(issue, staleMessage, staleLabel) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.debug(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
core.info(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
||||||
this.staleIssues.push(issue);
|
this.staleIssues.push(issue);
|
||||||
|
this.operationsLeft -= 2;
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -8552,11 +8624,12 @@ class IssueProcessor {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
/// Close an issue based on staleness
|
// Close an issue based on staleness
|
||||||
closeIssue(issue) {
|
closeIssue(issue) {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
core.debug(`Closing issue #${issue.number} - ${issue.title} for being stale`);
|
core.info(`Closing issue #${issue.number} - ${issue.title} for being stale`);
|
||||||
this.closedIssues.push(issue);
|
this.closedIssues.push(issue);
|
||||||
|
this.operationsLeft -= 1;
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -8568,14 +8641,53 @@ class IssueProcessor {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
// Remove a label from an issue
|
||||||
|
removeLabel(issue, label) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.info(`Removing label ${label} from issue #${issue.number} - ${issue.title}`);
|
||||||
|
this.removedLabelIssues.push(issue);
|
||||||
|
this.operationsLeft -= 1;
|
||||||
|
if (this.options.debugOnly) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
yield this.client.issues.removeLabel({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
name: encodeURIComponent(label) // A label can have a "?" in the name
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// returns the creation date of a given label on an issue (or nothing if no label existed)
|
||||||
|
///see https://developer.github.com/v3/activity/events/
|
||||||
|
getLabelCreationDate(issue, label) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
core.info(`Checking for label ${label} on issue #${issue.number}`);
|
||||||
|
this.operationsLeft -= 1;
|
||||||
|
const options = this.client.issues.listEvents.endpoint.merge({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
per_page: 100,
|
||||||
|
issue_number: issue.number
|
||||||
|
});
|
||||||
|
const events = yield this.client.paginate(options);
|
||||||
|
const reversedEvents = events.reverse();
|
||||||
|
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;
|
||||||
|
});
|
||||||
|
}
|
||||||
static isLabeled(issue, label) {
|
static isLabeled(issue, label) {
|
||||||
const labelComparer = l => label.localeCompare(l.name, undefined, { sensitivity: 'accent' }) === 0;
|
const labelComparer = l => label.localeCompare(l.name, undefined, { sensitivity: 'accent' }) === 0;
|
||||||
return issue.labels.filter(labelComparer).length > 0;
|
return issue.labels.filter(labelComparer).length > 0;
|
||||||
}
|
}
|
||||||
static wasLastUpdatedBefore(issue, num_days) {
|
static updatedSince(timestamp, num_days) {
|
||||||
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
||||||
const millisSinceLastUpdated = new Date().getTime() - new Date(issue.updated_at).getTime();
|
const millisSinceLastUpdated = new Date().getTime() - new Date(timestamp).getTime();
|
||||||
return millisSinceLastUpdated >= daysInMillis;
|
return millisSinceLastUpdated < daysInMillis;
|
||||||
}
|
}
|
||||||
static parseCommaSeparatedString(s) {
|
static parseCommaSeparatedString(s) {
|
||||||
// String.prototype.split defaults to [''] when called on an empty string
|
// String.prototype.split defaults to [''] when called on an empty string
|
||||||
|
|||||||
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;
|
||||||
@@ -10,6 +10,23 @@ export interface Issue {
|
|||||||
updated_at: string;
|
updated_at: string;
|
||||||
labels: Label[];
|
labels: Label[];
|
||||||
pull_request: any;
|
pull_request: any;
|
||||||
|
state: string;
|
||||||
|
locked: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface User {
|
||||||
|
type: string;
|
||||||
|
login: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Comment {
|
||||||
|
user: User;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IssueEvent {
|
||||||
|
created_at: string;
|
||||||
|
event: string;
|
||||||
|
label: Label;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Label {
|
export interface Label {
|
||||||
@@ -28,6 +45,7 @@ export interface IssueProcessorOptions {
|
|||||||
exemptPrLabels: string;
|
exemptPrLabels: string;
|
||||||
onlyLabels: string;
|
onlyLabels: string;
|
||||||
operationsPerRun: number;
|
operationsPerRun: number;
|
||||||
|
removeStaleWhenUpdated: boolean;
|
||||||
debugOnly: boolean;
|
debugOnly: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,10 +59,19 @@ export class IssueProcessor {
|
|||||||
|
|
||||||
readonly staleIssues: Issue[] = [];
|
readonly staleIssues: Issue[] = [];
|
||||||
readonly closedIssues: Issue[] = [];
|
readonly closedIssues: Issue[] = [];
|
||||||
|
readonly removedLabelIssues: Issue[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
options: IssueProcessorOptions,
|
options: IssueProcessorOptions,
|
||||||
getIssues?: (page: number) => Promise<Issue[]>
|
getIssues?: (page: number) => Promise<Issue[]>,
|
||||||
|
listIssueComments?: (
|
||||||
|
issueNumber: number,
|
||||||
|
sinceDate: string
|
||||||
|
) => Promise<Comment[]>,
|
||||||
|
getLabelCreationDate?: (
|
||||||
|
issue: Issue,
|
||||||
|
label: string
|
||||||
|
) => Promise<string | undefined>
|
||||||
) {
|
) {
|
||||||
this.options = options;
|
this.options = options;
|
||||||
this.operationsLeft = options.operationsPerRun;
|
this.operationsLeft = options.operationsPerRun;
|
||||||
@@ -54,6 +81,14 @@ export class IssueProcessor {
|
|||||||
this.getIssues = getIssues;
|
this.getIssues = getIssues;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (listIssueComments) {
|
||||||
|
this.listIssueComments = listIssueComments;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (getLabelCreationDate) {
|
||||||
|
this.getLabelCreationDate = getLabelCreationDate;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
core.warning(
|
core.warning(
|
||||||
'Executing in debug mode. Debug output will be written but no issues will be processed.'
|
'Executing in debug mode. Debug output will be written but no issues will be processed.'
|
||||||
@@ -62,24 +97,19 @@ export class IssueProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async processIssues(page: number = 1): Promise<number> {
|
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
|
// get the next batch of issues
|
||||||
const issues: Issue[] = await this.getIssues(page);
|
const issues: Issue[] = await this.getIssues(page);
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
if (issues.length <= 0) {
|
if (issues.length <= 0) {
|
||||||
core.debug('No more issues found to process. Exiting.');
|
core.info('No more issues found to process. Exiting.');
|
||||||
return this.operationsLeft;
|
return this.operationsLeft;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const issue of issues.values()) {
|
for (const issue of issues.values()) {
|
||||||
const isPr = !!issue.pull_request;
|
const isPr = !!issue.pull_request;
|
||||||
|
|
||||||
core.debug(
|
core.info(
|
||||||
`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`
|
`Found issue: issue #${issue.number} - ${issue.title} last updated ${issue.updated_at} (is pr? ${isPr})`
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -96,65 +126,168 @@ export class IssueProcessor {
|
|||||||
const issueType: string = isPr ? 'pr' : 'issue';
|
const issueType: string = isPr ? 'pr' : 'issue';
|
||||||
|
|
||||||
if (!staleMessage) {
|
if (!staleMessage) {
|
||||||
core.debug(`Skipping ${issueType} due to empty stale message`);
|
core.info(`Skipping ${issueType} due to empty stale message`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (issue.state === 'closed') {
|
||||||
|
core.info(`Skipping ${issueType} because it is closed`);
|
||||||
|
continue; // don't process closed issues
|
||||||
|
}
|
||||||
|
|
||||||
|
if (issue.locked) {
|
||||||
|
core.info(`Skipping ${issueType} because it is locked`);
|
||||||
|
continue; // don't process locked issues
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
exemptLabels.some((exemptLabel: string) =>
|
exemptLabels.some((exemptLabel: string) =>
|
||||||
IssueProcessor.isLabeled(issue, exemptLabel)
|
IssueProcessor.isLabeled(issue, exemptLabel)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
core.debug(`Skipping ${issueType} because it has an exempt label`);
|
core.info(`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);
|
||||||
if (
|
|
||||||
this.options.daysBeforeClose >= 0 &&
|
// should this issue be marked stale?
|
||||||
IssueProcessor.wasLastUpdatedBefore(
|
const shouldBeStale = !IssueProcessor.updatedSince(
|
||||||
issue,
|
issue.updated_at,
|
||||||
this.options.daysBeforeClose
|
this.options.daysBeforeStale
|
||||||
)
|
);
|
||||||
) {
|
|
||||||
core.debug(
|
// determine if this issue needs to be marked stale first
|
||||||
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
|
if (!isStale && shouldBeStale) {
|
||||||
);
|
core.info(
|
||||||
await this.closeIssue(issue);
|
`Marking ${issueType} stale because it was last updated on ${issue.updated_at} and it does not have a stale label`
|
||||||
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);
|
await this.markStale(issue, staleMessage, staleLabel);
|
||||||
this.operationsLeft -= 2;
|
isStale = true; // this issue is now considered stale
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// process the issue if it was marked stale
|
||||||
|
if (isStale) {
|
||||||
|
core.info(`Found a stale ${issueType}`);
|
||||||
|
await this.processStaleIssue(issue, issueType, staleLabel);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.operationsLeft <= 0) {
|
||||||
|
core.warning('Reached max number of operations to process. Exiting.');
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// do the next batch
|
// do the next batch
|
||||||
return this.processIssues(page + 1);
|
return this.processIssues(page + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// handle all of the stale issue logic when we find a stale issue
|
||||||
|
private async processStaleIssue(
|
||||||
|
issue: Issue,
|
||||||
|
issueType: string,
|
||||||
|
staleLabel: string
|
||||||
|
) {
|
||||||
|
const markedStaleOn: string =
|
||||||
|
(await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
||||||
|
core.info(`Issue #${issue.number} marked stale on: ${markedStaleOn}`);
|
||||||
|
|
||||||
|
const issueHasComments: boolean = await this.hasCommentsSince(
|
||||||
|
issue,
|
||||||
|
markedStaleOn
|
||||||
|
);
|
||||||
|
core.info(
|
||||||
|
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
||||||
|
);
|
||||||
|
|
||||||
|
const issueHasUpdate: boolean = IssueProcessor.updatedSince(
|
||||||
|
issue.updated_at,
|
||||||
|
this.options.daysBeforeClose + (this.options.daysBeforeStale ?? 0)
|
||||||
|
);
|
||||||
|
core.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||||
|
|
||||||
|
// should we un-stale this issue?
|
||||||
|
if (this.options.removeStaleWhenUpdated && issueHasComments) {
|
||||||
|
core.info(
|
||||||
|
`Issue #${issue.number} is no longer stale. Removing stale label.`
|
||||||
|
);
|
||||||
|
await this.removeLabel(issue, staleLabel);
|
||||||
|
}
|
||||||
|
|
||||||
|
// now start closing logic
|
||||||
|
if (this.options.daysBeforeClose < 0) {
|
||||||
|
return; // nothing to do because we aren't closing stale issues
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!issueHasComments && !issueHasUpdate) {
|
||||||
|
core.info(
|
||||||
|
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
|
||||||
|
);
|
||||||
|
await this.closeIssue(issue);
|
||||||
|
} else {
|
||||||
|
core.info(
|
||||||
|
`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// checks to see if a given issue is still stale (has had activity on it)
|
||||||
|
private async hasCommentsSince(
|
||||||
|
issue: Issue,
|
||||||
|
sinceDate: string
|
||||||
|
): Promise<boolean> {
|
||||||
|
core.info(
|
||||||
|
`Checking for comments on issue #${issue.number} since ${sinceDate}`
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!sinceDate) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// find any comments since the date
|
||||||
|
const comments = await this.listIssueComments(issue.number, sinceDate);
|
||||||
|
|
||||||
|
const filteredComments = comments.filter(
|
||||||
|
comment =>
|
||||||
|
comment.user.type === 'User' &&
|
||||||
|
comment.user.login !== github.context.actor
|
||||||
|
);
|
||||||
|
|
||||||
|
core.info(
|
||||||
|
`Comments not made by ${github.context.actor} or another bot: ${filteredComments.length}`
|
||||||
|
);
|
||||||
|
|
||||||
|
// if there are any user comments returned
|
||||||
|
return filteredComments.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// grab comments for an issue since a given date
|
||||||
|
private async listIssueComments(
|
||||||
|
issueNumber: number,
|
||||||
|
sinceDate: string
|
||||||
|
): Promise<Comment[]> {
|
||||||
|
// find any comments since date on the given issue
|
||||||
|
const comments = await this.client.issues.listComments({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issueNumber,
|
||||||
|
since: sinceDate
|
||||||
|
});
|
||||||
|
|
||||||
|
return comments.data;
|
||||||
|
}
|
||||||
|
|
||||||
// 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;
|
||||||
}
|
}
|
||||||
@@ -165,10 +298,12 @@ export class IssueProcessor {
|
|||||||
staleMessage: string,
|
staleMessage: string,
|
||||||
staleLabel: string
|
staleLabel: string
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
core.debug(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
core.info(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
||||||
|
|
||||||
this.staleIssues.push(issue);
|
this.staleIssues.push(issue);
|
||||||
|
|
||||||
|
this.operationsLeft -= 2;
|
||||||
|
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -188,14 +323,16 @@ export class IssueProcessor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Close an issue based on staleness
|
// Close an issue based on staleness
|
||||||
private async closeIssue(issue: Issue): Promise<void> {
|
private async closeIssue(issue: Issue): Promise<void> {
|
||||||
core.debug(
|
core.info(
|
||||||
`Closing issue #${issue.number} - ${issue.title} for being stale`
|
`Closing issue #${issue.number} - ${issue.title} for being stale`
|
||||||
);
|
);
|
||||||
|
|
||||||
this.closedIssues.push(issue);
|
this.closedIssues.push(issue);
|
||||||
|
|
||||||
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -208,17 +345,72 @@ export class IssueProcessor {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Remove a label from an issue
|
||||||
|
private async removeLabel(issue: Issue, label: string): Promise<void> {
|
||||||
|
core.info(
|
||||||
|
`Removing label ${label} from issue #${issue.number} - ${issue.title}`
|
||||||
|
);
|
||||||
|
|
||||||
|
this.removedLabelIssues.push(issue);
|
||||||
|
|
||||||
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
|
if (this.options.debugOnly) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
await this.client.issues.removeLabel({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
issue_number: issue.number,
|
||||||
|
name: encodeURIComponent(label) // A label can have a "?" in the name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// returns the creation date of a given label on an issue (or nothing if no label existed)
|
||||||
|
///see https://developer.github.com/v3/activity/events/
|
||||||
|
private async getLabelCreationDate(
|
||||||
|
issue: Issue,
|
||||||
|
label: string
|
||||||
|
): Promise<string | undefined> {
|
||||||
|
core.info(`Checking for label ${label} on issue #${issue.number}`);
|
||||||
|
|
||||||
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
|
const options = this.client.issues.listEvents.endpoint.merge({
|
||||||
|
owner: github.context.repo.owner,
|
||||||
|
repo: github.context.repo.repo,
|
||||||
|
per_page: 100,
|
||||||
|
issue_number: issue.number
|
||||||
|
});
|
||||||
|
|
||||||
|
const events: IssueEvent[] = await this.client.paginate(options);
|
||||||
|
const reversedEvents = events.reverse();
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
private static isLabeled(issue: Issue, label: string): boolean {
|
private static isLabeled(issue: Issue, label: string): boolean {
|
||||||
const labelComparer: (l: Label) => boolean = l =>
|
const labelComparer: (l: Label) => boolean = l =>
|
||||||
label.localeCompare(l.name, undefined, {sensitivity: 'accent'}) === 0;
|
label.localeCompare(l.name, undefined, {sensitivity: 'accent'}) === 0;
|
||||||
return issue.labels.filter(labelComparer).length > 0;
|
return issue.labels.filter(labelComparer).length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static wasLastUpdatedBefore(issue: Issue, num_days: number): boolean {
|
private static updatedSince(timestamp: string, num_days: number): boolean {
|
||||||
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
||||||
const millisSinceLastUpdated =
|
const millisSinceLastUpdated =
|
||||||
new Date().getTime() - new Date(issue.updated_at).getTime();
|
new Date().getTime() - new Date(timestamp).getTime();
|
||||||
return millisSinceLastUpdated >= daysInMillis;
|
|
||||||
|
return millisSinceLastUpdated < daysInMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static parseCommaSeparatedString(s: string): string[] {
|
private static parseCommaSeparatedString(s: string): string[] {
|
||||||
|
|||||||
@@ -32,6 +32,9 @@ function getAndValidateArgs(): IssueProcessorOptions {
|
|||||||
operationsPerRun: parseInt(
|
operationsPerRun: parseInt(
|
||||||
core.getInput('operations-per-run', {required: true})
|
core.getInput('operations-per-run', {required: true})
|
||||||
),
|
),
|
||||||
|
removeStaleWhenUpdated: !(
|
||||||
|
core.getInput('remove-stale-when-updated') === 'false'
|
||||||
|
),
|
||||||
debugOnly: core.getInput('debug-only') === 'true'
|
debugOnly: core.getInput('debug-only') === 'true'
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
"rootDir": "./src", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */
|
||||||
"strict": true, /* Enable all strict type-checking options. */
|
"strict": true, /* Enable all strict type-checking options. */
|
||||||
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
"noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */
|
||||||
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
"esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
|
||||||
|
//"sourceMap": true
|
||||||
},
|
},
|
||||||
"exclude": ["node_modules", "**/*.test.ts"]
|
"exclude": ["node_modules", "**/*.test.ts"]
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user