mirror of
https://github.com/actions/stale.git
synced 2025-12-28 11:08:18 +00:00
Compare commits
5 Commits
hross/upda
...
hross-proc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dcf19effbe | ||
|
|
2392a086f1 | ||
|
|
c52e87c95b | ||
|
|
990266dda6 | ||
|
|
5e528060cc |
31
.github/workflows/codeql.yml
vendored
31
.github/workflows/codeql.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: 'Code scanning'
|
name: "Code scanning"
|
||||||
|
|
||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
@@ -8,16 +8,29 @@ on:
|
|||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
CodeQL-Build:
|
CodeQL-Build:
|
||||||
|
|
||||||
|
# CodeQL runs on ubuntu-latest and windows-latest
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- name: Checkout repository
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
with:
|
||||||
|
# We must fetch at least the immediate parents so that if this is
|
||||||
|
# a pull request then we can checkout the head.
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
- name: Initialize CodeQL
|
# If this run was triggered by a pull request event, then checkout
|
||||||
uses: github/codeql-action/init@v1
|
# the head of the pull request instead of the merge commit.
|
||||||
|
- run: git checkout HEAD^2
|
||||||
|
if: ${{ github.event_name == 'pull_request' }}
|
||||||
|
|
||||||
- name: Autobuild
|
# Initializes the CodeQL tools for scanning.
|
||||||
uses: github/codeql-action/autobuild@v1
|
- name: Initialize CodeQL
|
||||||
|
uses: github/codeql-action/init@v1
|
||||||
|
|
||||||
- name: Perform CodeQL Analysis
|
- name: Autobuild
|
||||||
uses: github/codeql-action/analyze@v1
|
uses: github/codeql-action/autobuild@v1
|
||||||
|
|
||||||
|
- name: Perform CodeQL Analysis
|
||||||
|
uses: github/codeql-action/analyze@v1
|
||||||
|
|||||||
15
.github/workflows/stale.yml
vendored
15
.github/workflows/stale.yml
vendored
@@ -1,15 +1,16 @@
|
|||||||
name: 'Stale issue handler'
|
name: "Stale issue handler"
|
||||||
on:
|
on:
|
||||||
workflow_dispatch:
|
workflow_dispatch:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '0 0 * * *'
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v3
|
- uses: actions/stale@v3
|
||||||
with:
|
with:
|
||||||
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'
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
days-before-stale: 30
|
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'
|
||||||
days-before-close: 5
|
days-before-stale: 30
|
||||||
|
days-before-close: 5
|
||||||
|
|||||||
23
.github/workflows/test.yml
vendored
23
.github/workflows/test.yml
vendored
@@ -1,4 +1,4 @@
|
|||||||
name: 'Build'
|
name: "Build"
|
||||||
on: # rebuild any PRs and main branch changes
|
on: # rebuild any PRs and main branch changes
|
||||||
pull_request:
|
pull_request:
|
||||||
push:
|
push:
|
||||||
@@ -10,16 +10,17 @@ jobs:
|
|||||||
build: # make sure build/ci work properly
|
build: # make sure build/ci work properly
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- run: |
|
- run: |
|
||||||
npm install
|
npm install
|
||||||
npm run all
|
npm run all
|
||||||
test: # make sure the action works on a clean machine without building
|
test: # make sure the action works on a clean machine without building
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- uses: ./
|
- uses: ./
|
||||||
with:
|
with:
|
||||||
stale-issue-message: 'This issue is stale'
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
stale-pr-message: 'This PR is stale'
|
stale-issue-message: 'This issue is stale'
|
||||||
debug-only: true
|
stale-pr-message: 'This PR is stale'
|
||||||
|
debug-only: true
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,4 +2,3 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
lib/
|
lib/
|
||||||
__tests__/runner/*
|
__tests__/runner/*
|
||||||
.idea
|
|
||||||
|
|||||||
82
README.md
82
README.md
@@ -5,110 +5,82 @@ Warns and then closes issues and PRs that have had no activity for a specified a
|
|||||||
### Building and testing
|
### Building and testing
|
||||||
|
|
||||||
Install the dependencies
|
Install the dependencies
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm install
|
$ npm install
|
||||||
```
|
```
|
||||||
|
|
||||||
Build the typescript and package it for distribution
|
Build the typescript and package it for distribution
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm run build && npm run pack
|
$ npm run build && npm run pack
|
||||||
```
|
```
|
||||||
|
|
||||||
Run the tests :heavy_check_mark:
|
Run the tests :heavy_check_mark:
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
$ npm test
|
$ npm test
|
||||||
```
|
```
|
||||||
|
|
||||||
### Arguments
|
|
||||||
|
|
||||||
| Input | Description | Usage |
|
|
||||||
| :-------------------------: | :-------------------------------------------------------------------------------: | :------: |
|
|
||||||
| `repo-token` | PAT(Personal Access Token) for authorizing repository. | Optional |
|
|
||||||
| `days-before-stale` | Idle number of days before marking an issue/pr as stale. \*Defaults to **60\*** | Optional |
|
|
||||||
| `days-before-close` | Idle number of days before closing an stale issue/pr. \*Defaults to **7\*** | Optional |
|
|
||||||
| `stale-issue-message` | Message to post on the stale issue. | Optional |
|
|
||||||
| `stale-pr-message` | Message to post on the stale pr. | Optional |
|
|
||||||
| `close-issue-message` | Message to post on the stale issue while closing it. | Optional |
|
|
||||||
| `close-pr-message` | Message to post on the stale pr while closing it. | Optional |
|
|
||||||
| `stale-issue-label` | Label to apply on the stale issue. \*Defaults to **stale\*** | Optional |
|
|
||||||
| `close-issue-label` | Label to apply on closing issue. | Optional |
|
|
||||||
| `stale-pr-label` | Label to apply on the stale pr. | Optional |
|
|
||||||
| `close-pr-label` | Label to apply on the closing pr. | Optional |
|
|
||||||
| `exempt-issue-labels` | Labels on an issue exempted from being marked as stale. | Optional |
|
|
||||||
| `exempt-pr-labels` | Labels on the pr exempted from being marked as stale. | Optional |
|
|
||||||
| `only-labels` | Only labels checked for stale issue/pr. | Optional |
|
|
||||||
| `operations-per-run` | Maximum number of operations per run. \*Defaults to **30\*** | Optional |
|
|
||||||
| `remove-stale-when-updated` | Remove stale label from issue/pr on updates or comments. \*Defaults to **true\*** | Optional |
|
|
||||||
| `debug-only` | Dry-run on action. \*Defaults to **false\*** | Optional |
|
|
||||||
| `ascending` | Order to get issues/pr. \*Defaults to **false\*** | Optional |
|
|
||||||
| `skip-stale-issue-message` | Skip adding stale message on stale issue. \*Defaults to **false\*** | Optional |
|
|
||||||
| `skip-stale-pr-message` | Skip adding stale message on stale pr. \*Defaults to **false\*** | Optional |
|
|
||||||
|
|
||||||
### Usage
|
### Usage
|
||||||
|
|
||||||
See [action.yml](./action.yml) For comprehensive list of options.
|
See [action.yml](./action.yml) For comprehensive list of options.
|
||||||
|
|
||||||
Basic:
|
Basic:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: 'Close stale issues'
|
name: "Close stale issues"
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '30 1 * * *'
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v3
|
- uses: actions/stale@v3
|
||||||
with:
|
with:
|
||||||
stale-issue-message: 'Message to comment on stale issues. If none provided, will not mark issues stale'
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
stale-pr-message: 'Message to comment on stale PRs. If none provided, will not mark PRs stale'
|
stale-issue-message: 'Message to comment on stale issues. If none provided, will not mark issues stale'
|
||||||
|
stale-pr-message: 'Message to comment on stale PRs. If none provided, will not mark PRs stale'
|
||||||
```
|
```
|
||||||
|
|
||||||
Configure stale timeouts:
|
Configure stale timeouts:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: 'Close stale issues'
|
name: "Close stale issues"
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '30 1 * * *'
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v3
|
- uses: actions/stale@v3
|
||||||
with:
|
with:
|
||||||
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'
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
days-before-stale: 30
|
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'
|
||||||
days-before-close: 5
|
days-before-stale: 30
|
||||||
|
days-before-close: 5
|
||||||
```
|
```
|
||||||
|
|
||||||
Configure labels:
|
Configure labels:
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
name: 'Close stale issues'
|
name: "Close stale issues"
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron: '30 1 * * *'
|
- cron: "0 0 * * *"
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
stale:
|
stale:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v3
|
- uses: actions/stale@v3
|
||||||
with:
|
with:
|
||||||
stale-issue-message: 'Stale issue message'
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
stale-pr-message: 'Stale pull request message'
|
stale-issue-message: 'Stale issue message'
|
||||||
stale-issue-label: 'no-issue-activity'
|
stale-pr-message: 'Stale pull request message'
|
||||||
exempt-issue-labels: 'awaiting-approval,work-in-progress'
|
stale-issue-label: 'no-issue-activity'
|
||||||
stale-pr-label: 'no-pr-activity'
|
exempt-issue-labels: 'awaiting-approval,work-in-progress'
|
||||||
exempt-pr-labels: 'awaiting-approval,work-in-progress'
|
stale-pr-label: 'no-pr-activity'
|
||||||
only-labels: 'awaiting-feedback,awaiting-answers'
|
exempt-pr-labels: 'awaiting-approval,work-in-progress'
|
||||||
|
only-labels: 'awaiting-feedback,awaiting-answers'
|
||||||
```
|
```
|
||||||
|
|
||||||
### Debugging
|
### Debugging
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
|
import * as core from '@actions/core';
|
||||||
import * as github from '@actions/github';
|
import * as github from '@actions/github';
|
||||||
|
import {Octokit} from '@octokit/rest';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
IssueProcessor,
|
IssueProcessor,
|
||||||
Issue,
|
Issue,
|
||||||
|
Label,
|
||||||
IssueProcessorOptions
|
IssueProcessorOptions
|
||||||
} from '../src/IssueProcessor';
|
} from '../src/IssueProcessor';
|
||||||
|
|
||||||
@@ -37,10 +40,8 @@ const DefaultProcessorOptions: IssueProcessorOptions = Object.freeze({
|
|||||||
daysBeforeStale: 1,
|
daysBeforeStale: 1,
|
||||||
daysBeforeClose: 30,
|
daysBeforeClose: 30,
|
||||||
staleIssueLabel: 'Stale',
|
staleIssueLabel: 'Stale',
|
||||||
closeIssueLabel: '',
|
|
||||||
exemptIssueLabels: '',
|
exemptIssueLabels: '',
|
||||||
stalePrLabel: 'Stale',
|
stalePrLabel: 'Stale',
|
||||||
closePrLabel: '',
|
|
||||||
exemptPrLabels: '',
|
exemptPrLabels: '',
|
||||||
onlyLabels: '',
|
onlyLabels: '',
|
||||||
operationsPerRun: 100,
|
operationsPerRun: 100,
|
||||||
@@ -48,14 +49,12 @@ const DefaultProcessorOptions: IssueProcessorOptions = Object.freeze({
|
|||||||
removeStaleWhenUpdated: false,
|
removeStaleWhenUpdated: false,
|
||||||
ascending: false,
|
ascending: false,
|
||||||
skipStaleIssueMessage: false,
|
skipStaleIssueMessage: false,
|
||||||
skipStalePrMessage: false,
|
skipStalePrMessage: false
|
||||||
deleteBranch: false
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('empty issue list results in 1 operation', async () => {
|
test('empty issue list results in 1 operation', async () => {
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async () => 'abot',
|
|
||||||
async () => [],
|
async () => [],
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -78,7 +77,6 @@ test('processing an issue with no label will make it stale and close it, if it i
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -89,7 +87,6 @@ test('processing an issue with no label will make it stale and close it, if it i
|
|||||||
|
|
||||||
expect(processor.staleIssues.length).toEqual(1);
|
expect(processor.staleIssues.length).toEqual(1);
|
||||||
expect(processor.closedIssues.length).toEqual(1);
|
expect(processor.closedIssues.length).toEqual(1);
|
||||||
expect(processor.deletedBranchIssues.length).toEqual(0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('processing an issue with no label will make it stale and not close it if days-before-close is set to > 0', async () => {
|
test('processing an issue with no label will make it stale and not close it if days-before-close is set to > 0', async () => {
|
||||||
@@ -102,7 +99,6 @@ test('processing an issue with no label will make it stale and not close it if d
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -128,7 +124,6 @@ test('processing an issue with no label will not make it stale if days-before-st
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -153,7 +148,6 @@ test('processing an issue with no label will make it stale but not close it', as
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -179,69 +173,6 @@ test('processing a stale issue will close it', async () => {
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async () => 'abot',
|
|
||||||
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('processing a stale issue containing a space in the label will close it', async () => {
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(
|
|
||||||
1,
|
|
||||||
'A stale issue that should be closed',
|
|
||||||
'2020-01-01T17:00:00Z',
|
|
||||||
false,
|
|
||||||
['state: stale']
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
const opts: IssueProcessorOptions = {
|
|
||||||
...DefaultProcessorOptions,
|
|
||||||
staleIssueLabel: 'state: stale'
|
|
||||||
};
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
|
||||||
opts,
|
|
||||||
async () => 'abot',
|
|
||||||
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('processing a stale issue containing a slash in the label will close it', async () => {
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(
|
|
||||||
1,
|
|
||||||
'A stale issue that should be closed',
|
|
||||||
'2020-01-01T17:00:00Z',
|
|
||||||
false,
|
|
||||||
['lifecycle/stale']
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
const opts: IssueProcessorOptions = {
|
|
||||||
...DefaultProcessorOptions,
|
|
||||||
staleIssueLabel: 'lifecycle/stale'
|
|
||||||
};
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
|
||||||
opts,
|
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -267,7 +198,6 @@ test('processing a stale PR will close it', async () => {
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -295,7 +225,6 @@ test('processing a stale issue will close it even if configured not to mark as s
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -323,7 +252,6 @@ test('processing a stale PR will close it even if configured not to mark as stal
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -350,7 +278,6 @@ test('closed issues will not be marked stale', async () => {
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => []
|
async (num, dt) => []
|
||||||
);
|
);
|
||||||
@@ -376,7 +303,6 @@ test('stale closed issues will not be closed', async () => {
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -403,7 +329,6 @@ test('closed prs will not be marked stale', async () => {
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -430,10 +355,9 @@ test('stale closed prs will not be closed', async () => {
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -456,10 +380,8 @@ test('locked issues will not be marked stale', async () => {
|
|||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
||||||
DefaultProcessorOptions,
|
p == 1 ? TestIssueList : []
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : [])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -484,10 +406,9 @@ test('stale locked issues will not be closed', async () => {
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -510,10 +431,8 @@ test('locked prs will not be marked stale', async () => {
|
|||||||
)
|
)
|
||||||
];
|
];
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
||||||
DefaultProcessorOptions,
|
p == 1 ? TestIssueList : []
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : [])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -538,10 +457,9 @@ test('stale locked prs will not be closed', async () => {
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
DefaultProcessorOptions,
|
DefaultProcessorOptions,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -563,10 +481,9 @@ test('exempt issue labels will not be marked stale', async () => {
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -586,10 +503,9 @@ test('exempt issue labels will not be marked stale (multi issue label with space
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -609,10 +525,9 @@ test('exempt issue labels will not be marked stale (multi issue label)', async (
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -635,10 +550,9 @@ test('exempt pr labels will not be marked stale', async () => {
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -661,10 +575,9 @@ test('stale issues should not be closed if days is set to -1', async () => {
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -690,10 +603,9 @@ test('stale label should be removed if a comment was added to a stale issue', as
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [{user: {login: 'notme', type: 'User'}}], // return a fake comment to indicate there was an update
|
async (num, dt) => [{user: {login: 'notme', type: 'User'}}], // return a fake comment to indicate there was an update
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -721,10 +633,9 @@ test('stale label should not be removed if a comment was added by the bot (and t
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [{user: {login: 'abot', type: 'User'}}], // return a fake comment to indicate there was an update by the bot
|
async (num, dt) => [{user: {login: 'abot', type: 'User'}}], // return a fake comment to indicate there was an update by the bot
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -735,39 +646,6 @@ test('stale label should not be removed if a comment was added by the bot (and t
|
|||||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
expect(processor.removedLabelIssues.length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('stale label containing a space 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,
|
|
||||||
['stat: stale']
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
const opts: IssueProcessorOptions = {
|
|
||||||
...DefaultProcessorOptions,
|
|
||||||
removeStaleWhenUpdated: true,
|
|
||||||
staleIssueLabel: 'stat: stale'
|
|
||||||
};
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
|
||||||
opts,
|
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
|
||||||
async (num: number, dt: string) => [{user: {login: 'notme', type: 'User'}}], // return a fake comment to indicate there was an update
|
|
||||||
async (issue: Issue, label: string) => 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 issues should not be closed until after the closed number of days', async () => {
|
test('stale issues should not be closed until after the closed number of days', async () => {
|
||||||
let lastUpdate = new Date();
|
let lastUpdate = new Date();
|
||||||
lastUpdate.setDate(lastUpdate.getDate() - 5);
|
lastUpdate.setDate(lastUpdate.getDate() - 5);
|
||||||
@@ -786,7 +664,6 @@ test('stale issues should not be closed until after the closed number of days',
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -819,10 +696,9 @@ test('stale issues should be closed if the closed nubmer of days (additive) is a
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// process our fake issue list
|
// process our fake issue list
|
||||||
@@ -851,7 +727,6 @@ test('stale issues should not be closed until after the closed number of days (l
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num, dt) => [],
|
async (num, dt) => [],
|
||||||
async (issue, label) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
@@ -884,10 +759,9 @@ test('skips stale message on issues when skip-stale-issue-message is set', async
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// for sake of testing, mocking private function
|
// for sake of testing, mocking private function
|
||||||
@@ -929,10 +803,9 @@ test('skips stale message on prs when skip-stale-pr-message is set', async () =>
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
// for sake of testing, mocking private function
|
// for sake of testing, mocking private function
|
||||||
@@ -975,10 +848,9 @@ test('not providing state takes precedence over skipStaleIssueMessage', async ()
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
await processor.processIssues(1);
|
await processor.processIssues(1);
|
||||||
@@ -1009,10 +881,9 @@ test('not providing stalePrMessage takes precedence over skipStalePrMessage', as
|
|||||||
|
|
||||||
const processor = new IssueProcessor(
|
const processor = new IssueProcessor(
|
||||||
opts,
|
opts,
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
async p => (p == 1 ? TestIssueList : []),
|
||||||
async (num: number, dt: string) => [],
|
async (num, dt) => [],
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
async (issue, label) => new Date().toDateString()
|
||||||
);
|
);
|
||||||
|
|
||||||
await processor.processIssues(1);
|
await processor.processIssues(1);
|
||||||
@@ -1022,61 +893,3 @@ test('not providing stalePrMessage takes precedence over skipStalePrMessage', as
|
|||||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
expect(processor.removedLabelIssues.length).toEqual(0);
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
expect(processor.staleIssues.length).toEqual(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('git branch is deleted when option is enabled', async () => {
|
|
||||||
const opts = {...DefaultProcessorOptions, deleteBranch: true};
|
|
||||||
const isPullRequest = true;
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(
|
|
||||||
1,
|
|
||||||
'An issue that should have its branch deleted',
|
|
||||||
'2020-01-01T17:00:00Z',
|
|
||||||
isPullRequest,
|
|
||||||
['Stale']
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
|
||||||
opts,
|
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
|
||||||
async (num: number, dt: string) => [],
|
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
|
||||||
);
|
|
||||||
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.closedIssues.length).toEqual(1);
|
|
||||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
|
||||||
expect(processor.deletedBranchIssues.length).toEqual(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('git branch is not deleted when issue is not pull request', async () => {
|
|
||||||
const opts = {...DefaultProcessorOptions, deleteBranch: true};
|
|
||||||
const isPullRequest = false;
|
|
||||||
const TestIssueList: Issue[] = [
|
|
||||||
generateIssue(
|
|
||||||
1,
|
|
||||||
'An issue that should not have its branch deleted',
|
|
||||||
'2020-01-01T17:00:00Z',
|
|
||||||
isPullRequest,
|
|
||||||
['Stale']
|
|
||||||
)
|
|
||||||
];
|
|
||||||
|
|
||||||
const processor = new IssueProcessor(
|
|
||||||
opts,
|
|
||||||
async () => 'abot',
|
|
||||||
async p => (p == 1 ? TestIssueList : []),
|
|
||||||
async (num: number, dt: string) => [],
|
|
||||||
async (issue: Issue, label: string) => new Date().toDateString()
|
|
||||||
);
|
|
||||||
|
|
||||||
await processor.processIssues(1);
|
|
||||||
|
|
||||||
expect(processor.closedIssues.length).toEqual(1);
|
|
||||||
expect(processor.removedLabelIssues.length).toEqual(0);
|
|
||||||
expect(processor.staleIssues.length).toEqual(0);
|
|
||||||
expect(processor.deletedBranchIssues.length).toEqual(0);
|
|
||||||
});
|
|
||||||
|
|||||||
14
action.yml
14
action.yml
@@ -4,7 +4,7 @@ author: 'GitHub'
|
|||||||
inputs:
|
inputs:
|
||||||
repo-token:
|
repo-token:
|
||||||
description: 'Token for the repository. Can be passed in using `{{ secrets.GITHUB_TOKEN }}`.'
|
description: 'Token for the repository. Can be passed in using `{{ secrets.GITHUB_TOKEN }}`.'
|
||||||
default: ${{ github.token }}
|
required: true
|
||||||
stale-issue-message:
|
stale-issue-message:
|
||||||
description: 'The message to post on the issue when tagging it. If none provided, will not mark issues stale.'
|
description: 'The message to post on the issue when tagging it. If none provided, will not mark issues stale.'
|
||||||
stale-pr-message:
|
stale-pr-message:
|
||||||
@@ -22,18 +22,14 @@ inputs:
|
|||||||
stale-issue-label:
|
stale-issue-label:
|
||||||
description: 'The label to apply when an issue is stale.'
|
description: 'The label to apply when an issue is stale.'
|
||||||
default: 'Stale'
|
default: 'Stale'
|
||||||
close-issue-label:
|
|
||||||
description: 'The label to apply when an issue is closed.'
|
|
||||||
exempt-issue-labels:
|
exempt-issue-labels:
|
||||||
description: 'The labels that mean an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
description: 'The labels to apply when an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
||||||
default: ''
|
default: ''
|
||||||
stale-pr-label:
|
stale-pr-label:
|
||||||
description: 'The label to apply when a pull request is stale.'
|
description: 'The label to apply when a pull request is stale.'
|
||||||
default: 'Stale'
|
default: 'Stale'
|
||||||
close-pr-label:
|
|
||||||
description: 'The label to apply when a pull request is closed.'
|
|
||||||
exempt-pr-labels:
|
exempt-pr-labels:
|
||||||
description: 'The labels that mean a pull request is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
description: 'The labels to apply when a pull request is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
||||||
default: ''
|
default: ''
|
||||||
only-labels:
|
only-labels:
|
||||||
description: 'Only issues or pull requests with all of these labels are checked if stale. Defaults to `[]` (disabled) and can be a comma-separated list of labels.'
|
description: 'Only issues or pull requests with all of these labels are checked if stale. Defaults to `[]` (disabled) and can be a comma-separated list of labels.'
|
||||||
@@ -56,8 +52,8 @@ inputs:
|
|||||||
skip-stale-issue-message:
|
skip-stale-issue-message:
|
||||||
description: 'Skip adding stale message when marking an issue as stale.'
|
description: 'Skip adding stale message when marking an issue as stale.'
|
||||||
default: false
|
default: false
|
||||||
delete-branch:
|
process-drafts:
|
||||||
description: 'Delete the git branch after closing a stale pull request.'
|
description: 'Should the draft PRs be marked stale? If set to true, draft PRs will be included in processing.'
|
||||||
default: false
|
default: false
|
||||||
runs:
|
runs:
|
||||||
using: 'node12'
|
using: 'node12'
|
||||||
|
|||||||
6776
dist/index.js
vendored
6776
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
@@ -2,10 +2,10 @@ module.exports = {
|
|||||||
clearMocks: true,
|
clearMocks: true,
|
||||||
moduleFileExtensions: ['js', 'ts'],
|
moduleFileExtensions: ['js', 'ts'],
|
||||||
testEnvironment: 'node',
|
testEnvironment: 'node',
|
||||||
testMatch: ['**/*.test.ts', '**/*.spec.ts'],
|
testMatch: ['**/*.test.ts'],
|
||||||
testRunner: 'jest-circus/runner',
|
testRunner: 'jest-circus/runner',
|
||||||
transform: {
|
transform: {
|
||||||
'^.+\\.ts$': 'ts-jest'
|
'^.+\\.ts$': 'ts-jest'
|
||||||
},
|
},
|
||||||
verbose: true
|
verbose: true
|
||||||
};
|
}
|
||||||
5894
package-lock.json
generated
5894
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
31
package.json
31
package.json
@@ -9,7 +9,6 @@
|
|||||||
"format": "prettier --write **/*.ts",
|
"format": "prettier --write **/*.ts",
|
||||||
"format-check": "prettier --check **/*.ts",
|
"format-check": "prettier --check **/*.ts",
|
||||||
"lint": "eslint src/**/*.ts",
|
"lint": "eslint src/**/*.ts",
|
||||||
"lint:fix": "eslint src/**/*.ts --fix",
|
|
||||||
"pack": "ncc build",
|
"pack": "ncc build",
|
||||||
"test": "jest",
|
"test": "jest",
|
||||||
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
|
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
|
||||||
@@ -26,27 +25,25 @@
|
|||||||
"author": "GitHub",
|
"author": "GitHub",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.2.6",
|
"@actions/core": "^1.2.4",
|
||||||
"@actions/github": "^4.0.0",
|
"@actions/github": "^4.0.0",
|
||||||
"@octokit/rest": "^18.0.9",
|
"@octokit/rest": "^18.0.4",
|
||||||
"lodash.deburr": "^4.1.0",
|
|
||||||
"semver": "^7.3.2"
|
"semver": "^7.3.2"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^26.0.15",
|
"@types/semver": "^7.3.1",
|
||||||
"@types/lodash.deburr": "^4.1.6",
|
"@types/jest": "^26.0.10",
|
||||||
"@types/node": "^14.10.0",
|
"@types/node": "^14.6.0",
|
||||||
"@types/semver": "^7.3.4",
|
"@typescript-eslint/parser": "^3.10.1",
|
||||||
"@typescript-eslint/parser": "^4.8.1",
|
"@vercel/ncc": "^0.23.0",
|
||||||
"@vercel/ncc": "^0.27.0",
|
"eslint": "^7.7.0",
|
||||||
"eslint": "^7.17.0",
|
|
||||||
"eslint-plugin-github": "^4.0.1",
|
"eslint-plugin-github": "^4.0.1",
|
||||||
"eslint-plugin-jest": "^24.1.3",
|
"eslint-plugin-jest": "^23.20.0",
|
||||||
"jest": "^26.6.3",
|
"jest": "^24.9.0",
|
||||||
"jest-circus": "^26.6.3",
|
"jest-circus": "^26.1.0",
|
||||||
"js-yaml": "^3.14.0",
|
"js-yaml": "^3.14.0",
|
||||||
"prettier": "^2.2.1",
|
"prettier": "^2.0.5",
|
||||||
"ts-jest": "^26.4.4",
|
"ts-jest": "^24.2.0",
|
||||||
"typescript": "^4.1.3"
|
"typescript": "^4.0.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import {context, getOctokit} from '@actions/github';
|
import {context, getOctokit} from '@actions/github';
|
||||||
import {GitHub} from '@actions/github/lib/utils';
|
|
||||||
import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
|
import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
|
||||||
import {isLabeled} from './functions/is-labeled';
|
|
||||||
import {labelsToList} from './functions/labels-to-list';
|
|
||||||
|
|
||||||
export interface Issue {
|
export interface Issue {
|
||||||
title: string;
|
title: string;
|
||||||
@@ -13,13 +10,7 @@ export interface Issue {
|
|||||||
pull_request: any;
|
pull_request: any;
|
||||||
state: string;
|
state: string;
|
||||||
locked: boolean;
|
locked: boolean;
|
||||||
}
|
draft: boolean;
|
||||||
|
|
||||||
export interface PullRequest {
|
|
||||||
number: number;
|
|
||||||
head: {
|
|
||||||
ref: string;
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface User {
|
export interface User {
|
||||||
@@ -50,10 +41,8 @@ export interface IssueProcessorOptions {
|
|||||||
daysBeforeStale: number;
|
daysBeforeStale: number;
|
||||||
daysBeforeClose: number;
|
daysBeforeClose: number;
|
||||||
staleIssueLabel: string;
|
staleIssueLabel: string;
|
||||||
closeIssueLabel: string;
|
|
||||||
exemptIssueLabels: string;
|
exemptIssueLabels: string;
|
||||||
stalePrLabel: string;
|
stalePrLabel: string;
|
||||||
closePrLabel: string;
|
|
||||||
exemptPrLabels: string;
|
exemptPrLabels: string;
|
||||||
onlyLabels: string;
|
onlyLabels: string;
|
||||||
operationsPerRun: number;
|
operationsPerRun: number;
|
||||||
@@ -62,25 +51,23 @@ export interface IssueProcessorOptions {
|
|||||||
ascending: boolean;
|
ascending: boolean;
|
||||||
skipStaleIssueMessage: boolean;
|
skipStaleIssueMessage: boolean;
|
||||||
skipStalePrMessage: boolean;
|
skipStalePrMessage: boolean;
|
||||||
deleteBranch: boolean;
|
processDrafts: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Handle processing of issues for staleness/closure.
|
* Handle processing of issues for staleness/closure.
|
||||||
*/
|
*/
|
||||||
export class IssueProcessor {
|
export class IssueProcessor {
|
||||||
readonly client: InstanceType<typeof GitHub>;
|
readonly client: any; // need to make this the correct type
|
||||||
readonly options: IssueProcessorOptions;
|
readonly options: IssueProcessorOptions;
|
||||||
private operationsLeft = 0;
|
private operationsLeft = 0;
|
||||||
|
|
||||||
readonly staleIssues: Issue[] = [];
|
readonly staleIssues: Issue[] = [];
|
||||||
readonly closedIssues: Issue[] = [];
|
readonly closedIssues: Issue[] = [];
|
||||||
readonly deletedBranchIssues: Issue[] = [];
|
|
||||||
readonly removedLabelIssues: Issue[] = [];
|
readonly removedLabelIssues: Issue[] = [];
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
options: IssueProcessorOptions,
|
options: IssueProcessorOptions,
|
||||||
getActor?: () => Promise<string>,
|
|
||||||
getIssues?: (page: number) => Promise<Issue[]>,
|
getIssues?: (page: number) => Promise<Issue[]>,
|
||||||
listIssueComments?: (
|
listIssueComments?: (
|
||||||
issueNumber: number,
|
issueNumber: number,
|
||||||
@@ -95,10 +82,6 @@ export class IssueProcessor {
|
|||||||
this.operationsLeft = options.operationsPerRun;
|
this.operationsLeft = options.operationsPerRun;
|
||||||
this.client = getOctokit(options.repoToken);
|
this.client = getOctokit(options.repoToken);
|
||||||
|
|
||||||
if (getActor) {
|
|
||||||
this.getActor = getActor;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (getIssues) {
|
if (getIssues) {
|
||||||
this.getIssues = getIssues;
|
this.getIssues = getIssues;
|
||||||
}
|
}
|
||||||
@@ -123,8 +106,6 @@ export class IssueProcessor {
|
|||||||
const issues: Issue[] = await this.getIssues(page);
|
const issues: Issue[] = await this.getIssues(page);
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
const actor: string = await this.getActor();
|
|
||||||
|
|
||||||
if (issues.length <= 0) {
|
if (issues.length <= 0) {
|
||||||
core.info('No more issues found to process. Exiting.');
|
core.info('No more issues found to process. Exiting.');
|
||||||
return this.operationsLeft;
|
return this.operationsLeft;
|
||||||
@@ -134,7 +115,7 @@ export class IssueProcessor {
|
|||||||
const isPr = !!issue.pull_request;
|
const isPr = !!issue.pull_request;
|
||||||
|
|
||||||
core.info(
|
core.info(
|
||||||
`Found issue: issue #${issue.number} last updated ${issue.updated_at} (is pr? ${isPr})`
|
`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
|
||||||
@@ -147,10 +128,7 @@ export class IssueProcessor {
|
|||||||
const staleLabel: string = isPr
|
const staleLabel: string = isPr
|
||||||
? this.options.stalePrLabel
|
? this.options.stalePrLabel
|
||||||
: this.options.staleIssueLabel;
|
: this.options.staleIssueLabel;
|
||||||
const closeLabel: string = isPr
|
const exemptLabels = IssueProcessor.parseCommaSeparatedString(
|
||||||
? this.options.closePrLabel
|
|
||||||
: this.options.closeIssueLabel;
|
|
||||||
const exemptLabels: string[] = labelsToList(
|
|
||||||
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
|
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
|
||||||
);
|
);
|
||||||
const skipMessage = isPr
|
const skipMessage = isPr
|
||||||
@@ -174,9 +152,14 @@ export class IssueProcessor {
|
|||||||
continue; // don't process locked issues
|
continue; // don't process locked issues
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (issue.draft && !this.options.processDrafts) {
|
||||||
|
core.info(`Skipping ${issueType} because it is a draft`);
|
||||||
|
continue; // don't process drafts
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
exemptLabels.some((exemptLabel: string) =>
|
exemptLabels.some((exemptLabel: string) =>
|
||||||
isLabeled(issue, exemptLabel)
|
IssueProcessor.isLabeled(issue, exemptLabel)
|
||||||
)
|
)
|
||||||
) {
|
) {
|
||||||
core.info(`Skipping ${issueType} because it has an exempt label`);
|
core.info(`Skipping ${issueType} because it has an exempt label`);
|
||||||
@@ -184,13 +167,7 @@ export class IssueProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// does this issue have a stale label?
|
// does this issue have a stale label?
|
||||||
let isStale: boolean = isLabeled(issue, staleLabel);
|
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
||||||
|
|
||||||
if (isStale) {
|
|
||||||
core.info(`This issue has a stale label`);
|
|
||||||
} else {
|
|
||||||
core.info(`This issue hasn't a stale label`);
|
|
||||||
}
|
|
||||||
|
|
||||||
// should this issue be marked stale?
|
// should this issue be marked stale?
|
||||||
const shouldBeStale = !IssueProcessor.updatedSince(
|
const shouldBeStale = !IssueProcessor.updatedSince(
|
||||||
@@ -214,9 +191,7 @@ export class IssueProcessor {
|
|||||||
issue,
|
issue,
|
||||||
issueType,
|
issueType,
|
||||||
staleLabel,
|
staleLabel,
|
||||||
actor,
|
closeMessage
|
||||||
closeMessage,
|
|
||||||
closeLabel
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -235,9 +210,7 @@ export class IssueProcessor {
|
|||||||
issue: Issue,
|
issue: Issue,
|
||||||
issueType: string,
|
issueType: string,
|
||||||
staleLabel: string,
|
staleLabel: string,
|
||||||
actor: string,
|
closeMessage?: string
|
||||||
closeMessage?: string,
|
|
||||||
closeLabel?: string
|
|
||||||
) {
|
) {
|
||||||
const markedStaleOn: string =
|
const markedStaleOn: string =
|
||||||
(await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
(await this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
||||||
@@ -245,8 +218,7 @@ export class IssueProcessor {
|
|||||||
|
|
||||||
const issueHasComments: boolean = await this.hasCommentsSince(
|
const issueHasComments: boolean = await this.hasCommentsSince(
|
||||||
issue,
|
issue,
|
||||||
markedStaleOn,
|
markedStaleOn
|
||||||
actor
|
|
||||||
);
|
);
|
||||||
core.info(
|
core.info(
|
||||||
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
||||||
@@ -275,18 +247,10 @@ export class IssueProcessor {
|
|||||||
core.info(
|
core.info(
|
||||||
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
|
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
|
||||||
);
|
);
|
||||||
await this.closeIssue(issue, closeMessage, closeLabel);
|
await this.closeIssue(issue, closeMessage);
|
||||||
|
|
||||||
if (this.options.deleteBranch && issue.pull_request) {
|
|
||||||
core.info(
|
|
||||||
`Deleting branch for #${issue.number} as delete-branch option was specified`
|
|
||||||
);
|
|
||||||
await this.deleteBranch(issue);
|
|
||||||
this.deletedBranchIssues.push(issue);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
core.info(
|
core.info(
|
||||||
`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate})`
|
`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -294,8 +258,7 @@ export class IssueProcessor {
|
|||||||
// checks to see if a given issue is still stale (has had activity on it)
|
// checks to see if a given issue is still stale (has had activity on it)
|
||||||
private async hasCommentsSince(
|
private async hasCommentsSince(
|
||||||
issue: Issue,
|
issue: Issue,
|
||||||
sinceDate: string,
|
sinceDate: string
|
||||||
actor: string
|
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
core.info(
|
core.info(
|
||||||
`Checking for comments on issue #${issue.number} since ${sinceDate}`
|
`Checking for comments on issue #${issue.number} since ${sinceDate}`
|
||||||
@@ -309,11 +272,12 @@ export class IssueProcessor {
|
|||||||
const comments = await this.listIssueComments(issue.number, sinceDate);
|
const comments = await this.listIssueComments(issue.number, sinceDate);
|
||||||
|
|
||||||
const filteredComments = comments.filter(
|
const filteredComments = comments.filter(
|
||||||
comment => comment.user.type === 'User' && comment.user.login !== actor
|
comment =>
|
||||||
|
comment.user.type === 'User' && comment.user.login !== context.actor
|
||||||
);
|
);
|
||||||
|
|
||||||
core.info(
|
core.info(
|
||||||
`Comments not made by actor or another bot: ${filteredComments.length}`
|
`Comments not made by ${context.actor} or another bot: ${filteredComments.length}`
|
||||||
);
|
);
|
||||||
|
|
||||||
// if there are any user comments returned
|
// if there are any user comments returned
|
||||||
@@ -340,18 +304,6 @@ export class IssueProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the actor from the GitHub token or context
|
|
||||||
private async getActor(): Promise<string> {
|
|
||||||
let actor;
|
|
||||||
try {
|
|
||||||
actor = await this.client.users.getAuthenticated();
|
|
||||||
} catch (error) {
|
|
||||||
return context.actor;
|
|
||||||
}
|
|
||||||
|
|
||||||
return actor.data.login;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 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[]> {
|
||||||
// generate type for response
|
// generate type for response
|
||||||
@@ -370,6 +322,8 @@ export class IssueProcessor {
|
|||||||
page
|
page
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
core.info(`issue data: ${JSON.stringify(issueResult.data)}`);
|
||||||
return issueResult.data;
|
return issueResult.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(`Get issues for repo error: ${error.message}`);
|
core.error(`Get issues for repo error: ${error.message}`);
|
||||||
@@ -384,7 +338,7 @@ export class IssueProcessor {
|
|||||||
staleLabel: string,
|
staleLabel: string,
|
||||||
skipMessage: boolean
|
skipMessage: boolean
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
core.info(`Marking issue #${issue.number} as stale`);
|
core.info(`Marking issue #${issue.number} - ${issue.title} as stale`);
|
||||||
|
|
||||||
this.staleIssues.push(issue);
|
this.staleIssues.push(issue);
|
||||||
|
|
||||||
@@ -425,12 +379,10 @@ export class IssueProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Close an issue based on staleness
|
// Close an issue based on staleness
|
||||||
private async closeIssue(
|
private async closeIssue(issue: Issue, closeMessage?: string): Promise<void> {
|
||||||
issue: Issue,
|
core.info(
|
||||||
closeMessage?: string,
|
`Closing issue #${issue.number} - ${issue.title} for being stale`
|
||||||
closeLabel?: string
|
);
|
||||||
): Promise<void> {
|
|
||||||
core.info(`Closing issue #${issue.number} for being stale`);
|
|
||||||
|
|
||||||
this.closedIssues.push(issue);
|
this.closedIssues.push(issue);
|
||||||
|
|
||||||
@@ -453,19 +405,6 @@ export class IssueProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (closeLabel) {
|
|
||||||
try {
|
|
||||||
await this.client.issues.addLabels({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
issue_number: issue.number,
|
|
||||||
labels: [closeLabel]
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
core.error(`Error adding a label: ${error.message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.client.issues.update({
|
await this.client.issues.update({
|
||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
@@ -478,70 +417,16 @@ export class IssueProcessor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async getPullRequest(
|
|
||||||
pullNumber: number
|
|
||||||
): Promise<PullRequest | undefined> {
|
|
||||||
this.operationsLeft -= 1;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const pullRequest = await this.client.pulls.get({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
pull_number: pullNumber
|
|
||||||
});
|
|
||||||
|
|
||||||
return pullRequest.data;
|
|
||||||
} catch (error) {
|
|
||||||
core.error(`Error getting pull request ${pullNumber}: ${error.message}`);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete the branch on closed pull request
|
|
||||||
private async deleteBranch(issue: Issue): Promise<void> {
|
|
||||||
core.info(
|
|
||||||
`Delete branch from closed issue #${issue.number} - ${issue.title}`
|
|
||||||
);
|
|
||||||
|
|
||||||
if (this.options.debugOnly) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const pullRequest = await this.getPullRequest(issue.number);
|
|
||||||
|
|
||||||
if (!pullRequest) {
|
|
||||||
core.info(
|
|
||||||
`Not deleting branch as pull request not found for issue ${issue.number}`
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const branch = pullRequest.head.ref;
|
|
||||||
core.info(`Deleting branch ${branch} from closed issue #${issue.number}`);
|
|
||||||
|
|
||||||
this.operationsLeft -= 1;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.client.git.deleteRef({
|
|
||||||
owner: context.repo.owner,
|
|
||||||
repo: context.repo.repo,
|
|
||||||
ref: `heads/${branch}`
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
core.error(
|
|
||||||
`Error deleting branch ${branch} from issue #${issue.number}: ${error.message}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove a label from an issue
|
// Remove a label from an issue
|
||||||
private async removeLabel(issue: Issue, label: string): Promise<void> {
|
private async removeLabel(issue: Issue, label: string): Promise<void> {
|
||||||
core.info(`Removing label "${label}" from issue #${issue.number}`);
|
core.info(
|
||||||
|
`Removing label ${label} from issue #${issue.number} - ${issue.title}`
|
||||||
|
);
|
||||||
|
|
||||||
this.removedLabelIssues.push(issue);
|
this.removedLabelIssues.push(issue);
|
||||||
|
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
// @todo remove the debug only to be able to test the code below
|
|
||||||
if (this.options.debugOnly) {
|
if (this.options.debugOnly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -551,7 +436,7 @@ export class IssueProcessor {
|
|||||||
owner: context.repo.owner,
|
owner: context.repo.owner,
|
||||||
repo: context.repo.repo,
|
repo: context.repo.repo,
|
||||||
issue_number: issue.number,
|
issue_number: issue.number,
|
||||||
name: label
|
name: encodeURIComponent(label) // A label can have a "?" in the name
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.error(`Error removing a label: ${error.message}`);
|
core.error(`Error removing a label: ${error.message}`);
|
||||||
@@ -564,7 +449,7 @@ export class IssueProcessor {
|
|||||||
issue: Issue,
|
issue: Issue,
|
||||||
label: string
|
label: string
|
||||||
): Promise<string | undefined> {
|
): Promise<string | undefined> {
|
||||||
core.info(`Checking for label on issue #${issue.number}`);
|
core.info(`Checking for label ${label} on issue #${issue.number}`);
|
||||||
|
|
||||||
this.operationsLeft -= 1;
|
this.operationsLeft -= 1;
|
||||||
|
|
||||||
@@ -590,6 +475,12 @@ export class IssueProcessor {
|
|||||||
return staleLabeledEvent.created_at;
|
return staleLabeledEvent.created_at;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static isLabeled(issue: Issue, label: string): boolean {
|
||||||
|
const labelComparer: (l: Label) => boolean = l =>
|
||||||
|
label.localeCompare(l.name, undefined, {sensitivity: 'accent'}) === 0;
|
||||||
|
return issue.labels.filter(labelComparer).length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
private static updatedSince(timestamp: string, 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 =
|
||||||
@@ -597,4 +488,11 @@ export class IssueProcessor {
|
|||||||
|
|
||||||
return millisSinceLastUpdated <= daysInMillis;
|
return millisSinceLastUpdated <= daysInMillis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static parseCommaSeparatedString(s: string): string[] {
|
||||||
|
// String.prototype.split defaults to [''] when called on an empty string
|
||||||
|
// In this case, we'd prefer to just return an empty array indicating no labels
|
||||||
|
if (!s.length) return [];
|
||||||
|
return s.split(',').map(l => l.trim());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,187 +0,0 @@
|
|||||||
import {Issue} from '../IssueProcessor';
|
|
||||||
import {isLabeled} from './is-labeled';
|
|
||||||
|
|
||||||
describe('isLabeled()', (): void => {
|
|
||||||
let issue: Issue;
|
|
||||||
let label: string;
|
|
||||||
|
|
||||||
describe('when the given issue contains no label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
issue = ({
|
|
||||||
labels: []
|
|
||||||
} as unknown) as Issue;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given label is a simple label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
label = 'label';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return false', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = isLabeled(issue, label);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given issue contains a simple label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
issue = {
|
|
||||||
labels: [
|
|
||||||
{
|
|
||||||
name: 'label'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
} as Issue;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given label is a simple label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
label = 'label';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = isLabeled(issue, label);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given issue contains a kebab case label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
issue = {
|
|
||||||
labels: [
|
|
||||||
{
|
|
||||||
name: 'kebab-case-label'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
} as Issue;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given label is a kebab case label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
label = 'kebab-case-label';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = isLabeled(issue, label);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given issue contains a multiple word label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
issue = {
|
|
||||||
labels: [
|
|
||||||
{
|
|
||||||
name: 'label like a sentence'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
} as Issue;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given label is a multiple word label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
label = 'label like a sentence';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = isLabeled(issue, label);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given issue contains a multiple word label with %20 spaces', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
issue = {
|
|
||||||
labels: [
|
|
||||||
{
|
|
||||||
name: 'label%20like%20a%20sentence'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
} as Issue;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given label is a multiple word label with %20 spaces', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
label = 'label%20like%20a%20sentence';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = isLabeled(issue, label);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given issue contains a label wih diacritical marks', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
issue = {
|
|
||||||
labels: [
|
|
||||||
{
|
|
||||||
name: 'déjà vu'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
} as Issue;
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given issue contains a label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
label = 'deja vu';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = isLabeled(issue, label);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given issue contains an uppercase label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
label = 'DEJA VU';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = isLabeled(issue, label);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given issue contains a label wih diacritical marks', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
label = 'déjà vu';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return true', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = isLabeled(issue, label);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(true);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import deburr from 'lodash.deburr';
|
|
||||||
import {Issue, Label} from '../IssueProcessor';
|
|
||||||
|
|
||||||
type CleanLabel = string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description
|
|
||||||
* Check if the label is listed as a label of the issue
|
|
||||||
*
|
|
||||||
* @param {Readonly<Issue>} issue A GitHub issue containing some labels
|
|
||||||
* @param {Readonly<string>} label The label to check the presence with
|
|
||||||
*
|
|
||||||
* @return {boolean} Return true when the given label is also in the issue labels
|
|
||||||
*/
|
|
||||||
export function isLabeled(
|
|
||||||
issue: Readonly<Issue>,
|
|
||||||
label: Readonly<string>
|
|
||||||
): boolean {
|
|
||||||
return !!issue.labels.find((issueLabel: Readonly<Label>): boolean => {
|
|
||||||
return cleanLabel(label) === cleanLabel(issueLabel.name);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function cleanLabel(label: Readonly<string>): CleanLabel {
|
|
||||||
return deburr(label.toLowerCase());
|
|
||||||
}
|
|
||||||
@@ -1,141 +0,0 @@
|
|||||||
import {labelsToList} from './labels-to-list';
|
|
||||||
|
|
||||||
describe('labelsToList()', (): void => {
|
|
||||||
let labels: string;
|
|
||||||
|
|
||||||
describe('when the given labels is empty', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
labels = '';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return an empty list of labels', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = labelsToList(labels);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual([]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given labels is a simple label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
labels = 'label';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a list of one label', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = labelsToList(labels);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(['label']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given labels is a label with extra spaces before and after', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
labels = ' label ';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a list of one label and remove all spaces before and after', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = labelsToList(labels);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(['label']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given labels is a kebab case label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
labels = 'kebab-case-label';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a list of one label', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = labelsToList(labels);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(['kebab-case-label']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given labels is two kebab case labels separated with a comma', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
labels = 'kebab-case-label-1,kebab-case-label-2';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a list of two labels', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = labelsToList(labels);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual([
|
|
||||||
'kebab-case-label-1',
|
|
||||||
'kebab-case-label-2'
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given labels is a multiple word label', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
labels = 'label like a sentence';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a list of one label', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = labelsToList(labels);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(['label like a sentence']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given labels is two multiple word labels separated with a comma', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
labels = 'label like a sentence, another label like a sentence';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a list of two labels', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = labelsToList(labels);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual([
|
|
||||||
'label like a sentence',
|
|
||||||
'another label like a sentence'
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given labels is a multiple word label with %20 spaces', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
labels = 'label%20like%20a%20sentence';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a list of one label', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = labelsToList(labels);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual(['label%20like%20a%20sentence']);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('when the given labels is two multiple word labels with %20 spaces separated with a comma', (): void => {
|
|
||||||
beforeEach((): void => {
|
|
||||||
labels =
|
|
||||||
'label%20like%20a%20sentence,another%20label%20like%20a%20sentence';
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a list of two labels', (): void => {
|
|
||||||
expect.assertions(1);
|
|
||||||
|
|
||||||
const result = labelsToList(labels);
|
|
||||||
|
|
||||||
expect(result).toStrictEqual([
|
|
||||||
'label%20like%20a%20sentence',
|
|
||||||
'another%20label%20like%20a%20sentence'
|
|
||||||
]);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
/**
|
|
||||||
* @description
|
|
||||||
* Transform a string of comma separated labels
|
|
||||||
* to an array of labels
|
|
||||||
*
|
|
||||||
* @example
|
|
||||||
* labelsToList('label') => ['label']
|
|
||||||
* labelsToList('label,label') => ['label', 'label']
|
|
||||||
* labelsToList('kebab-label') => ['kebab-label']
|
|
||||||
* labelsToList('kebab%20label') => ['kebab%20label']
|
|
||||||
* labelsToList('label with words') => ['label with words']
|
|
||||||
*
|
|
||||||
* @param {Readonly<string>} labels A string of comma separated labels
|
|
||||||
*
|
|
||||||
* @return {string[]} A list of labels
|
|
||||||
*/
|
|
||||||
export function labelsToList(labels: Readonly<string>): string[] {
|
|
||||||
if (!labels.length) {
|
|
||||||
return [];
|
|
||||||
}
|
|
||||||
|
|
||||||
return labels.split(',').map(l => l.trim());
|
|
||||||
}
|
|
||||||
@@ -15,7 +15,7 @@ async function run(): Promise<void> {
|
|||||||
|
|
||||||
function getAndValidateArgs(): IssueProcessorOptions {
|
function getAndValidateArgs(): IssueProcessorOptions {
|
||||||
const args = {
|
const args = {
|
||||||
repoToken: core.getInput('repo-token'),
|
repoToken: core.getInput('repo-token', {required: true}),
|
||||||
staleIssueMessage: core.getInput('stale-issue-message'),
|
staleIssueMessage: core.getInput('stale-issue-message'),
|
||||||
stalePrMessage: core.getInput('stale-pr-message'),
|
stalePrMessage: core.getInput('stale-pr-message'),
|
||||||
closeIssueMessage: core.getInput('close-issue-message'),
|
closeIssueMessage: core.getInput('close-issue-message'),
|
||||||
@@ -27,10 +27,8 @@ function getAndValidateArgs(): IssueProcessorOptions {
|
|||||||
core.getInput('days-before-close', {required: true})
|
core.getInput('days-before-close', {required: true})
|
||||||
),
|
),
|
||||||
staleIssueLabel: core.getInput('stale-issue-label', {required: true}),
|
staleIssueLabel: core.getInput('stale-issue-label', {required: true}),
|
||||||
closeIssueLabel: core.getInput('close-issue-label'),
|
|
||||||
exemptIssueLabels: core.getInput('exempt-issue-labels'),
|
exemptIssueLabels: core.getInput('exempt-issue-labels'),
|
||||||
stalePrLabel: core.getInput('stale-pr-label', {required: true}),
|
stalePrLabel: core.getInput('stale-pr-label', {required: true}),
|
||||||
closePrLabel: core.getInput('close-pr-label'),
|
|
||||||
exemptPrLabels: core.getInput('exempt-pr-labels'),
|
exemptPrLabels: core.getInput('exempt-pr-labels'),
|
||||||
onlyLabels: core.getInput('only-labels'),
|
onlyLabels: core.getInput('only-labels'),
|
||||||
operationsPerRun: parseInt(
|
operationsPerRun: parseInt(
|
||||||
@@ -43,7 +41,7 @@ function getAndValidateArgs(): IssueProcessorOptions {
|
|||||||
ascending: core.getInput('ascending') === 'true',
|
ascending: core.getInput('ascending') === 'true',
|
||||||
skipStalePrMessage: core.getInput('skip-stale-pr-message') === 'true',
|
skipStalePrMessage: core.getInput('skip-stale-pr-message') === 'true',
|
||||||
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true',
|
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true',
|
||||||
deleteBranch: core.getInput('delete-branch') === 'true'
|
processDrafts: core.getInput('process-drafts') === 'true'
|
||||||
};
|
};
|
||||||
|
|
||||||
for (const numberInput of [
|
for (const numberInput of [
|
||||||
|
|||||||
Reference in New Issue
Block a user