mirror of
https://github.com/actions/stale.git
synced 2025-12-24 09:28:18 +00:00
Compare commits
20 Commits
v3.0.13
...
hross/fix_
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
684a5b40f8 | ||
|
|
b5b956deb3 | ||
|
|
6674e9130f | ||
|
|
73dbf86108 | ||
|
|
a0b4b61711 | ||
|
|
0f78ebc7dc | ||
|
|
b70b09d43a | ||
|
|
aca4d264ff | ||
|
|
44c3cb508b | ||
|
|
39de730f99 | ||
|
|
ddc7648635 | ||
|
|
107018c400 | ||
|
|
87c2b794b9 | ||
|
|
b7c7b1c5c3 | ||
|
|
08900ff5d1 | ||
|
|
6ea8297c81 | ||
|
|
23d5d28543 | ||
|
|
2c5799741a | ||
|
|
324009e5d0 | ||
|
|
9b82e8c1ef |
31
.github/workflows/codeql.yml
vendored
31
.github/workflows/codeql.yml
vendored
@@ -1,4 +1,4 @@
|
||||
name: "Code scanning"
|
||||
name: 'Code scanning'
|
||||
|
||||
on:
|
||||
push:
|
||||
@@ -8,29 +8,16 @@ on:
|
||||
|
||||
jobs:
|
||||
CodeQL-Build:
|
||||
|
||||
# CodeQL runs on ubuntu-latest and windows-latest
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Checkout repository
|
||||
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: Checkout repository
|
||||
uses: actions/checkout@v2
|
||||
|
||||
# If this run was triggered by a pull request event, then checkout
|
||||
# the head of the pull request instead of the merge commit.
|
||||
- run: git checkout HEAD^2
|
||||
if: ${{ github.event_name == 'pull_request' }}
|
||||
|
||||
# Initializes the CodeQL tools for scanning.
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
- name: Initialize CodeQL
|
||||
uses: github/codeql-action/init@v1
|
||||
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
- name: Autobuild
|
||||
uses: github/codeql-action/autobuild@v1
|
||||
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
- name: Perform CodeQL Analysis
|
||||
uses: github/codeql-action/analyze@v1
|
||||
|
||||
15
.github/workflows/stale.yml
vendored
15
.github/workflows/stale.yml
vendored
@@ -1,16 +1,15 @@
|
||||
name: "Stale issue handler"
|
||||
name: 'Stale issue handler'
|
||||
on:
|
||||
workflow_dispatch:
|
||||
schedule:
|
||||
- cron: "0 0 * * *"
|
||||
- cron: '0 0 * * *'
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
with:
|
||||
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'
|
||||
days-before-stale: 30
|
||||
days-before-close: 5
|
||||
- uses: actions/stale@v3
|
||||
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'
|
||||
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
|
||||
pull_request:
|
||||
push:
|
||||
@@ -10,17 +10,16 @@ jobs:
|
||||
build: # make sure build/ci work properly
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- run: |
|
||||
npm install
|
||||
npm run all
|
||||
- uses: actions/checkout@v2
|
||||
- run: |
|
||||
npm install
|
||||
npm run all
|
||||
test: # make sure the action works on a clean machine without building
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-issue-message: 'This issue is stale'
|
||||
stale-pr-message: 'This PR is stale'
|
||||
debug-only: true
|
||||
- uses: actions/checkout@v2
|
||||
- uses: ./
|
||||
with:
|
||||
stale-issue-message: 'This issue is stale'
|
||||
stale-pr-message: 'This PR is stale'
|
||||
debug-only: true
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -2,3 +2,4 @@
|
||||
node_modules/
|
||||
lib/
|
||||
__tests__/runner/*
|
||||
.idea
|
||||
|
||||
113
README.md
113
README.md
@@ -4,108 +4,111 @@ Warns and then closes issues and PRs that have had no activity for a specified a
|
||||
|
||||
### Building and testing
|
||||
|
||||
Install the dependencies
|
||||
Install the dependencies
|
||||
|
||||
```bash
|
||||
$ npm install
|
||||
```
|
||||
|
||||
Build the typescript and package it for distribution
|
||||
|
||||
```bash
|
||||
$ npm run build && npm run pack
|
||||
```
|
||||
|
||||
Run the tests :heavy_check_mark:
|
||||
Run the tests :heavy_check_mark:
|
||||
|
||||
```bash
|
||||
$ npm test
|
||||
```
|
||||
|
||||
### Arguments
|
||||
|
||||
| Input | Description | Usage |
|
||||
| :---: | :---: | :---: |
|
||||
| `repo-token` | PAT(Personal Access Token) for authorizing repository. | *Required* |
|
||||
| `days-before-stale` | Idle number of days before marking an issue/pr as stale. *Defaults to **60*** | Optional
|
||||
| `days-before-close` | Idle number of days before closing an stale issue/pr. *Defaults to **7*** | Optional
|
||||
| `stale-issue-message` | Message to post on the stale issue. | Optional
|
||||
| `stale-pr-message` | Message to post on the stale pr. | Optional
|
||||
| `close-issue-message` | Message to post on the stale issue while closing it. | Optional
|
||||
| `close-pr-message` | Message to post on the stale pr while closing it. | Optional
|
||||
| `stale-issue-label` | Label to apply on the stale issue. *Defaults to **stale*** | Optional
|
||||
| `close-issue-label` | Label to apply on closing issue. | Optional
|
||||
| `stale-pr-label` | Label to apply on the stale pr. | Optional
|
||||
| `close-pr-label` | Label to apply on the closing pr. | Optional
|
||||
| `exempt-issue-labels` | Labels on an issue exempted from being marked as stale. | Optional
|
||||
| `exempt-pr-labels` | Labels on the pr exempted from being marked as stale. | Optional
|
||||
| `only-labels` | Only labels checked for stale issue/pr. | Optional
|
||||
| `operations-per-run` | Maximum number of operations per run. *Defaults to **30*** | Optional
|
||||
| `remove-stale-when-updated` | Remove stale label from issue/pr on updates or comments. *Defaults to **true*** | Optional
|
||||
| `debug-only` | Dry-run on action. *Defaults to **false*** | Optional
|
||||
| `ascending` | Order to get issues/pr. *Defaults to **false*** | Optional
|
||||
| `skip-stale-issue-message` | Skip adding stale message on stale issue. *Defaults to **false*** | Optional
|
||||
| `skip-stale-pr-message` | Skip adding stale message on stale pr. *Defaults to **false*** | Optional
|
||||
|
||||
| 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
|
||||
|
||||
See [action.yml](./action.yml) For comprehensive list of options.
|
||||
|
||||
|
||||
Basic:
|
||||
|
||||
```yaml
|
||||
name: "Close stale issues"
|
||||
name: 'Close stale issues'
|
||||
on:
|
||||
schedule:
|
||||
- cron: "30 1 * * *"
|
||||
- cron: '30 1 * * *'
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
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'
|
||||
- uses: actions/stale@v3
|
||||
with:
|
||||
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:
|
||||
|
||||
```yaml
|
||||
name: "Close stale issues"
|
||||
name: 'Close stale issues'
|
||||
on:
|
||||
schedule:
|
||||
- cron: "30 1 * * *"
|
||||
- cron: '30 1 * * *'
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
with:
|
||||
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'
|
||||
days-before-stale: 30
|
||||
days-before-close: 5
|
||||
- uses: actions/stale@v3
|
||||
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'
|
||||
days-before-stale: 30
|
||||
days-before-close: 5
|
||||
```
|
||||
|
||||
|
||||
Configure labels:
|
||||
|
||||
```yaml
|
||||
name: "Close stale issues"
|
||||
name: 'Close stale issues'
|
||||
on:
|
||||
schedule:
|
||||
- cron: "30 1 * * *"
|
||||
- cron: '30 1 * * *'
|
||||
|
||||
jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-issue-message: 'Stale issue message'
|
||||
stale-pr-message: 'Stale pull request message'
|
||||
stale-issue-label: 'no-issue-activity'
|
||||
exempt-issue-labels: 'awaiting-approval,work-in-progress'
|
||||
stale-pr-label: 'no-pr-activity'
|
||||
exempt-pr-labels: 'awaiting-approval,work-in-progress'
|
||||
only-labels: 'awaiting-feedback,awaiting-answers'
|
||||
- uses: actions/stale@v3
|
||||
with:
|
||||
stale-issue-message: 'Stale issue message'
|
||||
stale-pr-message: 'Stale pull request message'
|
||||
stale-issue-label: 'no-issue-activity'
|
||||
exempt-issue-labels: 'awaiting-approval,work-in-progress'
|
||||
stale-pr-label: 'no-pr-activity'
|
||||
exempt-pr-labels: 'awaiting-approval,work-in-progress'
|
||||
only-labels: 'awaiting-feedback,awaiting-answers'
|
||||
```
|
||||
|
||||
### Debugging
|
||||
|
||||
@@ -1,11 +1,8 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
import {Octokit} from '@octokit/rest';
|
||||
|
||||
import {
|
||||
IssueProcessor,
|
||||
Issue,
|
||||
Label,
|
||||
IssueProcessorOptions
|
||||
} from '../src/IssueProcessor';
|
||||
|
||||
@@ -51,12 +48,14 @@ const DefaultProcessorOptions: IssueProcessorOptions = Object.freeze({
|
||||
removeStaleWhenUpdated: false,
|
||||
ascending: false,
|
||||
skipStaleIssueMessage: false,
|
||||
skipStalePrMessage: false
|
||||
skipStalePrMessage: false,
|
||||
deleteBranch: false
|
||||
});
|
||||
|
||||
test('empty issue list results in 1 operation', async () => {
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async () => [],
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -79,6 +78,7 @@ test('processing an issue with no label will make it stale and close it, if it i
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -89,6 +89,7 @@ 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.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 () => {
|
||||
@@ -101,6 +102,7 @@ test('processing an issue with no label will make it stale and not close it if d
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -126,6 +128,7 @@ test('processing an issue with no label will not make it stale if days-before-st
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -150,6 +153,7 @@ test('processing an issue with no label will make it stale but not close it', as
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -175,6 +179,69 @@ test('processing a stale issue will close it', async () => {
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
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 (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -200,6 +267,7 @@ test('processing a stale PR will close it', async () => {
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -227,6 +295,7 @@ test('processing a stale issue will close it even if configured not to mark as s
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -254,6 +323,7 @@ test('processing a stale PR will close it even if configured not to mark as stal
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -280,6 +350,7 @@ test('closed issues will not be marked stale', async () => {
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => []
|
||||
);
|
||||
@@ -305,6 +376,7 @@ test('stale closed issues will not be closed', async () => {
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -331,6 +403,7 @@ test('closed prs will not be marked stale', async () => {
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -357,9 +430,10 @@ test('stale closed prs will not be closed', async () => {
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -382,8 +456,10 @@ test('locked issues will not be marked stale', async () => {
|
||||
)
|
||||
];
|
||||
|
||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
||||
p == 1 ? TestIssueList : []
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : [])
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -408,9 +484,10 @@ test('stale locked issues will not be closed', async () => {
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -433,8 +510,10 @@ test('locked prs will not be marked stale', async () => {
|
||||
)
|
||||
];
|
||||
|
||||
const processor = new IssueProcessor(DefaultProcessorOptions, async p =>
|
||||
p == 1 ? TestIssueList : []
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : [])
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -459,9 +538,10 @@ test('stale locked prs will not be closed', async () => {
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -483,9 +563,10 @@ test('exempt issue labels will not be marked stale', async () => {
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -505,9 +586,10 @@ test('exempt issue labels will not be marked stale (multi issue label with space
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -527,9 +609,10 @@ test('exempt issue labels will not be marked stale (multi issue label)', async (
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -552,9 +635,10 @@ test('exempt pr labels will not be marked stale', async () => {
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -577,9 +661,10 @@ test('stale issues should not be closed if days is set to -1', async () => {
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -605,9 +690,10 @@ test('stale label should be removed if a comment was added to a stale issue', as
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
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()
|
||||
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
|
||||
@@ -635,9 +721,10 @@ test('stale label should not be removed if a comment was added by the bot (and t
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
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()
|
||||
async (num: number, dt: string) => [{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()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -648,6 +735,39 @@ test('stale label should not be removed if a comment was added by the bot (and t
|
||||
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 () => {
|
||||
let lastUpdate = new Date();
|
||||
lastUpdate.setDate(lastUpdate.getDate() - 5);
|
||||
@@ -666,6 +786,7 @@ test('stale issues should not be closed until after the closed number of days',
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -698,9 +819,10 @@ test('stale issues should be closed if the closed nubmer of days (additive) is a
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -729,6 +851,7 @@ test('stale issues should not be closed until after the closed number of days (l
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
@@ -761,9 +884,10 @@ test('skips stale message on issues when skip-stale-issue-message is set', async
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// for sake of testing, mocking private function
|
||||
@@ -805,9 +929,10 @@ test('skips stale message on prs when skip-stale-pr-message is set', async () =>
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
// for sake of testing, mocking private function
|
||||
@@ -850,9 +975,10 @@ test('not providing state takes precedence over skipStaleIssueMessage', async ()
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
await processor.processIssues(1);
|
||||
@@ -883,9 +1009,10 @@ test('not providing stalePrMessage takes precedence over skipStalePrMessage', as
|
||||
|
||||
const processor = new IssueProcessor(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p == 1 ? TestIssueList : []),
|
||||
async (num, dt) => [],
|
||||
async (issue, label) => new Date().toDateString()
|
||||
async (num: number, dt: string) => [],
|
||||
async (issue: Issue, label: string) => new Date().toDateString()
|
||||
);
|
||||
|
||||
await processor.processIssues(1);
|
||||
@@ -895,3 +1022,61 @@ test('not providing stalePrMessage takes precedence over skipStalePrMessage', as
|
||||
expect(processor.removedLabelIssues.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);
|
||||
});
|
||||
|
||||
@@ -4,7 +4,7 @@ author: 'GitHub'
|
||||
inputs:
|
||||
repo-token:
|
||||
description: 'Token for the repository. Can be passed in using `{{ secrets.GITHUB_TOKEN }}`.'
|
||||
required: true
|
||||
default: ${{ github.token }}
|
||||
stale-issue-message:
|
||||
description: 'The message to post on the issue when tagging it. If none provided, will not mark issues stale.'
|
||||
stale-pr-message:
|
||||
@@ -25,7 +25,7 @@ inputs:
|
||||
close-issue-label:
|
||||
description: 'The label to apply when an issue is closed.'
|
||||
exempt-issue-labels:
|
||||
description: 'The labels to apply when an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
||||
description: 'The labels that mean an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
||||
default: ''
|
||||
stale-pr-label:
|
||||
description: 'The label to apply when a pull request is stale.'
|
||||
@@ -33,7 +33,7 @@ inputs:
|
||||
close-pr-label:
|
||||
description: 'The label to apply when a pull request is closed.'
|
||||
exempt-pr-labels:
|
||||
description: 'The labels to apply when a pull request is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
||||
description: 'The labels that mean a pull request is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2")'
|
||||
default: ''
|
||||
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.'
|
||||
@@ -56,6 +56,9 @@ inputs:
|
||||
skip-stale-issue-message:
|
||||
description: 'Skip adding stale message when marking an issue as stale.'
|
||||
default: false
|
||||
delete-branch:
|
||||
description: 'Delete the git branch after closing a stale pull request.'
|
||||
default: false
|
||||
runs:
|
||||
using: 'node12'
|
||||
main: 'dist/index.js'
|
||||
|
||||
446
dist/index.js
vendored
446
dist/index.js
vendored
@@ -39,18 +39,24 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.IssueProcessor = void 0;
|
||||
const core = __importStar(__webpack_require__(186));
|
||||
const github_1 = __webpack_require__(438);
|
||||
const is_labeled_1 = __webpack_require__(792);
|
||||
const labels_to_list_1 = __webpack_require__(107);
|
||||
/***
|
||||
* Handle processing of issues for staleness/closure.
|
||||
*/
|
||||
class IssueProcessor {
|
||||
constructor(options, getIssues, listIssueComments, getLabelCreationDate) {
|
||||
constructor(options, getActor, getIssues, listIssueComments, getLabelCreationDate) {
|
||||
this.operationsLeft = 0;
|
||||
this.staleIssues = [];
|
||||
this.closedIssues = [];
|
||||
this.deletedBranchIssues = [];
|
||||
this.removedLabelIssues = [];
|
||||
this.options = options;
|
||||
this.operationsLeft = options.operationsPerRun;
|
||||
this.client = github_1.getOctokit(options.repoToken);
|
||||
if (getActor) {
|
||||
this.getActor = getActor;
|
||||
}
|
||||
if (getIssues) {
|
||||
this.getIssues = getIssues;
|
||||
}
|
||||
@@ -69,6 +75,7 @@ class IssueProcessor {
|
||||
// get the next batch of issues
|
||||
const issues = yield this.getIssues(page);
|
||||
this.operationsLeft -= 1;
|
||||
const actor = yield this.getActor();
|
||||
if (issues.length <= 0) {
|
||||
core.info('No more issues found to process. Exiting.');
|
||||
return this.operationsLeft;
|
||||
@@ -89,7 +96,7 @@ class IssueProcessor {
|
||||
const closeLabel = isPr
|
||||
? this.options.closePrLabel
|
||||
: this.options.closeIssueLabel;
|
||||
const exemptLabels = IssueProcessor.parseCommaSeparatedString(isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels);
|
||||
const exemptLabels = labels_to_list_1.labelsToList(isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels);
|
||||
const skipMessage = isPr
|
||||
? this.options.skipStalePrMessage
|
||||
: this.options.skipStaleIssueMessage;
|
||||
@@ -107,12 +114,18 @@ class IssueProcessor {
|
||||
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) => is_labeled_1.isLabeled(issue, exemptLabel))) {
|
||||
core.info(`Skipping ${issueType} because it has an exempt label`);
|
||||
continue; // don't process exempt issues
|
||||
}
|
||||
// does this issue have a stale label?
|
||||
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
||||
let isStale = is_labeled_1.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?
|
||||
const shouldBeStale = !IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeStale);
|
||||
// determine if this issue needs to be marked stale first
|
||||
@@ -124,7 +137,7 @@ class IssueProcessor {
|
||||
// process the issue if it was marked stale
|
||||
if (isStale) {
|
||||
core.info(`Found a stale ${issueType}`);
|
||||
yield this.processStaleIssue(issue, issueType, staleLabel, closeMessage, closeLabel);
|
||||
yield this.processStaleIssue(issue, issueType, staleLabel, actor, closeMessage, closeLabel);
|
||||
}
|
||||
}
|
||||
if (this.operationsLeft <= 0) {
|
||||
@@ -136,11 +149,11 @@ class IssueProcessor {
|
||||
});
|
||||
}
|
||||
// handle all of the stale issue logic when we find a stale issue
|
||||
processStaleIssue(issue, issueType, staleLabel, closeMessage, closeLabel) {
|
||||
processStaleIssue(issue, issueType, staleLabel, actor, closeMessage, closeLabel) {
|
||||
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);
|
||||
const issueHasComments = yield this.hasCommentsSince(issue, markedStaleOn, actor);
|
||||
core.info(`Issue #${issue.number} has been commented on: ${issueHasComments}`);
|
||||
const issueHasUpdate = IssueProcessor.updatedSince(issue.updated_at, this.options.daysBeforeClose);
|
||||
core.info(`Issue #${issue.number} has been updated: ${issueHasUpdate}`);
|
||||
@@ -156,14 +169,19 @@ class IssueProcessor {
|
||||
if (!issueHasComments && !issueHasUpdate) {
|
||||
core.info(`Closing ${issueType} because it was last updated on ${issue.updated_at}`);
|
||||
yield this.closeIssue(issue, closeMessage, closeLabel);
|
||||
if (this.options.deleteBranch && issue.pull_request) {
|
||||
core.info(`Deleting branch for #${issue.number} as delete-branch option was specified`);
|
||||
yield this.deleteBranch(issue);
|
||||
this.deletedBranchIssues.push(issue);
|
||||
}
|
||||
}
|
||||
else {
|
||||
core.info(`Stale ${issueType} is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate}`);
|
||||
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) {
|
||||
hasCommentsSince(issue, sinceDate, actor) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info(`Checking for comments on issue #${issue.number} since ${sinceDate}`);
|
||||
if (!sinceDate) {
|
||||
@@ -171,7 +189,7 @@ class IssueProcessor {
|
||||
}
|
||||
// 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_1.context.actor);
|
||||
const filteredComments = comments.filter(comment => comment.user.type === 'User' && comment.user.login !== actor);
|
||||
core.info(`Comments not made by actor or another bot: ${filteredComments.length}`);
|
||||
// if there are any user comments returned
|
||||
return filteredComments.length > 0;
|
||||
@@ -196,6 +214,19 @@ class IssueProcessor {
|
||||
}
|
||||
});
|
||||
}
|
||||
// get the actor from the GitHub token or context
|
||||
getActor() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let actor;
|
||||
try {
|
||||
actor = yield this.client.users.getAuthenticated();
|
||||
}
|
||||
catch (error) {
|
||||
return github_1.context.actor;
|
||||
}
|
||||
return actor.data.login;
|
||||
});
|
||||
}
|
||||
// grab issues from github in baches of 100
|
||||
getIssues(page) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
@@ -306,12 +337,56 @@ class IssueProcessor {
|
||||
}
|
||||
});
|
||||
}
|
||||
getPullRequest(pullNumber) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
this.operationsLeft -= 1;
|
||||
try {
|
||||
const pullRequest = yield this.client.pulls.get({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.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
|
||||
deleteBranch(issue) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info(`Delete branch from closed issue #${issue.number} - ${issue.title}`);
|
||||
if (this.options.debugOnly) {
|
||||
return;
|
||||
}
|
||||
const pullRequest = yield 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 {
|
||||
yield this.client.git.deleteRef({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.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
|
||||
removeLabel(issue, label) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.info(`Removing label from issue #${issue.number}`);
|
||||
core.info(`Removing label "${label}" from issue #${issue.number}`);
|
||||
this.removedLabelIssues.push(issue);
|
||||
this.operationsLeft -= 1;
|
||||
// @todo remove the debug only to be able to test the code below
|
||||
if (this.options.debugOnly) {
|
||||
return;
|
||||
}
|
||||
@@ -320,7 +395,7 @@ class IssueProcessor {
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
name: encodeURIComponent(label) // A label can have a "?" in the name
|
||||
name: label
|
||||
});
|
||||
}
|
||||
catch (error) {
|
||||
@@ -350,26 +425,82 @@ class IssueProcessor {
|
||||
return staleLabeledEvent.created_at;
|
||||
});
|
||||
}
|
||||
static isLabeled(issue, label) {
|
||||
const labelComparer = l => label.localeCompare(l.name, undefined, { sensitivity: 'accent' }) === 0;
|
||||
return issue.labels.filter(labelComparer).length > 0;
|
||||
}
|
||||
static updatedSince(timestamp, num_days) {
|
||||
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
||||
const millisSinceLastUpdated = new Date().getTime() - new Date(timestamp).getTime();
|
||||
return millisSinceLastUpdated <= daysInMillis;
|
||||
}
|
||||
static parseCommaSeparatedString(s) {
|
||||
// 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());
|
||||
}
|
||||
}
|
||||
exports.IssueProcessor = IssueProcessor;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 792:
|
||||
/***/ (function(__unused_webpack_module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.isLabeled = void 0;
|
||||
const lodash_deburr_1 = __importDefault(__webpack_require__(601));
|
||||
/**
|
||||
* @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
|
||||
*/
|
||||
function isLabeled(issue, label) {
|
||||
return !!issue.labels.find((issueLabel) => {
|
||||
return cleanLabel(label) === cleanLabel(issueLabel.name);
|
||||
});
|
||||
}
|
||||
exports.isLabeled = isLabeled;
|
||||
function cleanLabel(label) {
|
||||
return lodash_deburr_1.default(label.toLowerCase());
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 107:
|
||||
/***/ ((__unused_webpack_module, exports) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.labelsToList = void 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
|
||||
*/
|
||||
function labelsToList(labels) {
|
||||
if (!labels.length) {
|
||||
return [];
|
||||
}
|
||||
return labels.split(',').map(l => l.trim());
|
||||
}
|
||||
exports.labelsToList = labelsToList;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 109:
|
||||
@@ -423,7 +554,7 @@ function run() {
|
||||
}
|
||||
function getAndValidateArgs() {
|
||||
const args = {
|
||||
repoToken: core.getInput('repo-token', { required: true }),
|
||||
repoToken: core.getInput('repo-token'),
|
||||
staleIssueMessage: core.getInput('stale-issue-message'),
|
||||
stalePrMessage: core.getInput('stale-pr-message'),
|
||||
closeIssueMessage: core.getInput('close-issue-message'),
|
||||
@@ -442,7 +573,8 @@ function getAndValidateArgs() {
|
||||
debugOnly: core.getInput('debug-only') === 'true',
|
||||
ascending: core.getInput('ascending') === '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'
|
||||
};
|
||||
for (const numberInput of [
|
||||
'days-before-stale',
|
||||
@@ -4208,6 +4340,270 @@ function isPlainObject(o) {
|
||||
module.exports = isPlainObject;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 601:
|
||||
/***/ ((module) => {
|
||||
|
||||
/**
|
||||
* lodash (Custom Build) <https://lodash.com/>
|
||||
* Build: `lodash modularize exports="npm" -o ./`
|
||||
* Copyright jQuery Foundation and other contributors <https://jquery.org/>
|
||||
* Released under MIT license <https://lodash.com/license>
|
||||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
||||
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
||||
*/
|
||||
|
||||
/** Used as references for various `Number` constants. */
|
||||
var INFINITY = 1 / 0;
|
||||
|
||||
/** `Object#toString` result references. */
|
||||
var symbolTag = '[object Symbol]';
|
||||
|
||||
/** Used to match Latin Unicode letters (excluding mathematical operators). */
|
||||
var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
|
||||
|
||||
/** Used to compose unicode character classes. */
|
||||
var rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
|
||||
rsComboSymbolsRange = '\\u20d0-\\u20f0';
|
||||
|
||||
/** Used to compose unicode capture groups. */
|
||||
var rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']';
|
||||
|
||||
/**
|
||||
* Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
|
||||
* [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
|
||||
*/
|
||||
var reComboMark = RegExp(rsCombo, 'g');
|
||||
|
||||
/** Used to map Latin Unicode letters to basic Latin letters. */
|
||||
var deburredLetters = {
|
||||
// Latin-1 Supplement block.
|
||||
'\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
|
||||
'\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
|
||||
'\xc7': 'C', '\xe7': 'c',
|
||||
'\xd0': 'D', '\xf0': 'd',
|
||||
'\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
|
||||
'\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
|
||||
'\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
|
||||
'\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
|
||||
'\xd1': 'N', '\xf1': 'n',
|
||||
'\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
|
||||
'\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
|
||||
'\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
|
||||
'\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
|
||||
'\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
|
||||
'\xc6': 'Ae', '\xe6': 'ae',
|
||||
'\xde': 'Th', '\xfe': 'th',
|
||||
'\xdf': 'ss',
|
||||
// Latin Extended-A block.
|
||||
'\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
|
||||
'\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
|
||||
'\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
|
||||
'\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
|
||||
'\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
|
||||
'\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
|
||||
'\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
|
||||
'\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
|
||||
'\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
|
||||
'\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
|
||||
'\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
|
||||
'\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
|
||||
'\u0134': 'J', '\u0135': 'j',
|
||||
'\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
|
||||
'\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
|
||||
'\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
|
||||
'\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
|
||||
'\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
|
||||
'\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
|
||||
'\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
|
||||
'\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
|
||||
'\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
|
||||
'\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
|
||||
'\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
|
||||
'\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
|
||||
'\u0163': 't', '\u0165': 't', '\u0167': 't',
|
||||
'\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
|
||||
'\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
|
||||
'\u0174': 'W', '\u0175': 'w',
|
||||
'\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
|
||||
'\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
|
||||
'\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
|
||||
'\u0132': 'IJ', '\u0133': 'ij',
|
||||
'\u0152': 'Oe', '\u0153': 'oe',
|
||||
'\u0149': "'n", '\u017f': 'ss'
|
||||
};
|
||||
|
||||
/** Detect free variable `global` from Node.js. */
|
||||
var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
|
||||
|
||||
/** Detect free variable `self`. */
|
||||
var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
|
||||
|
||||
/** Used as a reference to the global object. */
|
||||
var root = freeGlobal || freeSelf || Function('return this')();
|
||||
|
||||
/**
|
||||
* The base implementation of `_.propertyOf` without support for deep paths.
|
||||
*
|
||||
* @private
|
||||
* @param {Object} object The object to query.
|
||||
* @returns {Function} Returns the new accessor function.
|
||||
*/
|
||||
function basePropertyOf(object) {
|
||||
return function(key) {
|
||||
return object == null ? undefined : object[key];
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
|
||||
* letters to basic Latin letters.
|
||||
*
|
||||
* @private
|
||||
* @param {string} letter The matched letter to deburr.
|
||||
* @returns {string} Returns the deburred letter.
|
||||
*/
|
||||
var deburrLetter = basePropertyOf(deburredLetters);
|
||||
|
||||
/** Used for built-in method references. */
|
||||
var objectProto = Object.prototype;
|
||||
|
||||
/**
|
||||
* Used to resolve the
|
||||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
|
||||
* of values.
|
||||
*/
|
||||
var objectToString = objectProto.toString;
|
||||
|
||||
/** Built-in value references. */
|
||||
var Symbol = root.Symbol;
|
||||
|
||||
/** Used to convert symbols to primitives and strings. */
|
||||
var symbolProto = Symbol ? Symbol.prototype : undefined,
|
||||
symbolToString = symbolProto ? symbolProto.toString : undefined;
|
||||
|
||||
/**
|
||||
* The base implementation of `_.toString` which doesn't convert nullish
|
||||
* values to empty strings.
|
||||
*
|
||||
* @private
|
||||
* @param {*} value The value to process.
|
||||
* @returns {string} Returns the string.
|
||||
*/
|
||||
function baseToString(value) {
|
||||
// Exit early for strings to avoid a performance hit in some environments.
|
||||
if (typeof value == 'string') {
|
||||
return value;
|
||||
}
|
||||
if (isSymbol(value)) {
|
||||
return symbolToString ? symbolToString.call(value) : '';
|
||||
}
|
||||
var result = (value + '');
|
||||
return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `value` is object-like. A value is object-like if it's not `null`
|
||||
* and has a `typeof` result of "object".
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.0.0
|
||||
* @category Lang
|
||||
* @param {*} value The value to check.
|
||||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`.
|
||||
* @example
|
||||
*
|
||||
* _.isObjectLike({});
|
||||
* // => true
|
||||
*
|
||||
* _.isObjectLike([1, 2, 3]);
|
||||
* // => true
|
||||
*
|
||||
* _.isObjectLike(_.noop);
|
||||
* // => false
|
||||
*
|
||||
* _.isObjectLike(null);
|
||||
* // => false
|
||||
*/
|
||||
function isObjectLike(value) {
|
||||
return !!value && typeof value == 'object';
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks if `value` is classified as a `Symbol` primitive or object.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.0.0
|
||||
* @category Lang
|
||||
* @param {*} value The value to check.
|
||||
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
|
||||
* @example
|
||||
*
|
||||
* _.isSymbol(Symbol.iterator);
|
||||
* // => true
|
||||
*
|
||||
* _.isSymbol('abc');
|
||||
* // => false
|
||||
*/
|
||||
function isSymbol(value) {
|
||||
return typeof value == 'symbol' ||
|
||||
(isObjectLike(value) && objectToString.call(value) == symbolTag);
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts `value` to a string. An empty string is returned for `null`
|
||||
* and `undefined` values. The sign of `-0` is preserved.
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 4.0.0
|
||||
* @category Lang
|
||||
* @param {*} value The value to process.
|
||||
* @returns {string} Returns the string.
|
||||
* @example
|
||||
*
|
||||
* _.toString(null);
|
||||
* // => ''
|
||||
*
|
||||
* _.toString(-0);
|
||||
* // => '-0'
|
||||
*
|
||||
* _.toString([1, 2, 3]);
|
||||
* // => '1,2,3'
|
||||
*/
|
||||
function toString(value) {
|
||||
return value == null ? '' : baseToString(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Deburrs `string` by converting
|
||||
* [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
|
||||
* and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
|
||||
* letters to basic Latin letters and removing
|
||||
* [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
|
||||
*
|
||||
* @static
|
||||
* @memberOf _
|
||||
* @since 3.0.0
|
||||
* @category String
|
||||
* @param {string} [string=''] The string to deburr.
|
||||
* @returns {string} Returns the deburred string.
|
||||
* @example
|
||||
*
|
||||
* _.deburr('déjà vu');
|
||||
* // => 'deja vu'
|
||||
*/
|
||||
function deburr(string) {
|
||||
string = toString(string);
|
||||
return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
|
||||
}
|
||||
|
||||
module.exports = deburr;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 467:
|
||||
|
||||
@@ -2,10 +2,10 @@ module.exports = {
|
||||
clearMocks: true,
|
||||
moduleFileExtensions: ['js', 'ts'],
|
||||
testEnvironment: 'node',
|
||||
testMatch: ['**/*.test.ts'],
|
||||
testMatch: ['**/*.test.ts', '**/*.spec.ts'],
|
||||
testRunner: 'jest-circus/runner',
|
||||
transform: {
|
||||
'^.+\\.ts$': 'ts-jest'
|
||||
},
|
||||
verbose: true
|
||||
}
|
||||
};
|
||||
|
||||
1599
package-lock.json
generated
1599
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@@ -9,6 +9,7 @@
|
||||
"format": "prettier --write **/*.ts",
|
||||
"format-check": "prettier --check **/*.ts",
|
||||
"lint": "eslint src/**/*.ts",
|
||||
"lint:fix": "eslint src/**/*.ts --fix",
|
||||
"pack": "ncc build",
|
||||
"test": "jest",
|
||||
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
|
||||
@@ -27,23 +28,25 @@
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.2.6",
|
||||
"@actions/github": "^4.0.0",
|
||||
"@octokit/rest": "^18.0.4",
|
||||
"@octokit/rest": "^18.0.9",
|
||||
"lodash.deburr": "^4.1.0",
|
||||
"semver": "^7.3.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/semver": "^7.3.1",
|
||||
"@types/jest": "^26.0.10",
|
||||
"@types/jest": "^26.0.15",
|
||||
"@types/lodash.deburr": "^4.1.6",
|
||||
"@types/node": "^14.10.0",
|
||||
"@typescript-eslint/parser": "^3.10.1",
|
||||
"@vercel/ncc": "^0.24.0",
|
||||
"eslint": "^7.7.0",
|
||||
"@types/semver": "^7.3.4",
|
||||
"@typescript-eslint/parser": "^4.8.1",
|
||||
"@vercel/ncc": "^0.27.0",
|
||||
"eslint": "^7.17.0",
|
||||
"eslint-plugin-github": "^4.0.1",
|
||||
"eslint-plugin-jest": "^23.20.0",
|
||||
"eslint-plugin-jest": "^24.1.3",
|
||||
"jest": "^24.9.0",
|
||||
"jest-circus": "^26.4.2",
|
||||
"jest-circus": "^26.6.3",
|
||||
"js-yaml": "^3.14.0",
|
||||
"prettier": "^2.1.1",
|
||||
"prettier": "^2.2.1",
|
||||
"ts-jest": "^24.2.0",
|
||||
"typescript": "^4.0.2"
|
||||
"typescript": "^4.1.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
import * as core from '@actions/core';
|
||||
import {context, getOctokit} from '@actions/github';
|
||||
import {GitHub} from '@actions/github/lib/utils';
|
||||
import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
|
||||
import {isLabeled} from './functions/is-labeled';
|
||||
import {labelsToList} from './functions/labels-to-list';
|
||||
|
||||
export interface Issue {
|
||||
title: string;
|
||||
@@ -12,6 +15,13 @@ export interface Issue {
|
||||
locked: boolean;
|
||||
}
|
||||
|
||||
export interface PullRequest {
|
||||
number: number;
|
||||
head: {
|
||||
ref: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface User {
|
||||
type: string;
|
||||
login: string;
|
||||
@@ -52,22 +62,25 @@ export interface IssueProcessorOptions {
|
||||
ascending: boolean;
|
||||
skipStaleIssueMessage: boolean;
|
||||
skipStalePrMessage: boolean;
|
||||
deleteBranch: boolean;
|
||||
}
|
||||
|
||||
/***
|
||||
* Handle processing of issues for staleness/closure.
|
||||
*/
|
||||
export class IssueProcessor {
|
||||
readonly client: any; // need to make this the correct type
|
||||
readonly client: InstanceType<typeof GitHub>;
|
||||
readonly options: IssueProcessorOptions;
|
||||
private operationsLeft = 0;
|
||||
|
||||
readonly staleIssues: Issue[] = [];
|
||||
readonly closedIssues: Issue[] = [];
|
||||
readonly deletedBranchIssues: Issue[] = [];
|
||||
readonly removedLabelIssues: Issue[] = [];
|
||||
|
||||
constructor(
|
||||
options: IssueProcessorOptions,
|
||||
getActor?: () => Promise<string>,
|
||||
getIssues?: (page: number) => Promise<Issue[]>,
|
||||
listIssueComments?: (
|
||||
issueNumber: number,
|
||||
@@ -82,6 +95,10 @@ export class IssueProcessor {
|
||||
this.operationsLeft = options.operationsPerRun;
|
||||
this.client = getOctokit(options.repoToken);
|
||||
|
||||
if (getActor) {
|
||||
this.getActor = getActor;
|
||||
}
|
||||
|
||||
if (getIssues) {
|
||||
this.getIssues = getIssues;
|
||||
}
|
||||
@@ -106,6 +123,8 @@ export class IssueProcessor {
|
||||
const issues: Issue[] = await this.getIssues(page);
|
||||
this.operationsLeft -= 1;
|
||||
|
||||
const actor: string = await this.getActor();
|
||||
|
||||
if (issues.length <= 0) {
|
||||
core.info('No more issues found to process. Exiting.');
|
||||
return this.operationsLeft;
|
||||
@@ -131,7 +150,7 @@ export class IssueProcessor {
|
||||
const closeLabel: string = isPr
|
||||
? this.options.closePrLabel
|
||||
: this.options.closeIssueLabel;
|
||||
const exemptLabels = IssueProcessor.parseCommaSeparatedString(
|
||||
const exemptLabels: string[] = labelsToList(
|
||||
isPr ? this.options.exemptPrLabels : this.options.exemptIssueLabels
|
||||
);
|
||||
const skipMessage = isPr
|
||||
@@ -157,7 +176,7 @@ export class IssueProcessor {
|
||||
|
||||
if (
|
||||
exemptLabels.some((exemptLabel: string) =>
|
||||
IssueProcessor.isLabeled(issue, exemptLabel)
|
||||
isLabeled(issue, exemptLabel)
|
||||
)
|
||||
) {
|
||||
core.info(`Skipping ${issueType} because it has an exempt label`);
|
||||
@@ -165,7 +184,13 @@ export class IssueProcessor {
|
||||
}
|
||||
|
||||
// does this issue have a stale label?
|
||||
let isStale = IssueProcessor.isLabeled(issue, staleLabel);
|
||||
let isStale: boolean = 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?
|
||||
const shouldBeStale = !IssueProcessor.updatedSince(
|
||||
@@ -189,6 +214,7 @@ export class IssueProcessor {
|
||||
issue,
|
||||
issueType,
|
||||
staleLabel,
|
||||
actor,
|
||||
closeMessage,
|
||||
closeLabel
|
||||
);
|
||||
@@ -209,6 +235,7 @@ export class IssueProcessor {
|
||||
issue: Issue,
|
||||
issueType: string,
|
||||
staleLabel: string,
|
||||
actor: string,
|
||||
closeMessage?: string,
|
||||
closeLabel?: string
|
||||
) {
|
||||
@@ -218,7 +245,8 @@ export class IssueProcessor {
|
||||
|
||||
const issueHasComments: boolean = await this.hasCommentsSince(
|
||||
issue,
|
||||
markedStaleOn
|
||||
markedStaleOn,
|
||||
actor
|
||||
);
|
||||
core.info(
|
||||
`Issue #${issue.number} has been commented on: ${issueHasComments}`
|
||||
@@ -248,9 +276,17 @@ export class IssueProcessor {
|
||||
`Closing ${issueType} because it was last updated on ${issue.updated_at}`
|
||||
);
|
||||
await this.closeIssue(issue, closeMessage, closeLabel);
|
||||
|
||||
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 {
|
||||
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})`
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -258,7 +294,8 @@ export class IssueProcessor {
|
||||
// checks to see if a given issue is still stale (has had activity on it)
|
||||
private async hasCommentsSince(
|
||||
issue: Issue,
|
||||
sinceDate: string
|
||||
sinceDate: string,
|
||||
actor: string
|
||||
): Promise<boolean> {
|
||||
core.info(
|
||||
`Checking for comments on issue #${issue.number} since ${sinceDate}`
|
||||
@@ -272,8 +309,7 @@ export class IssueProcessor {
|
||||
const comments = await this.listIssueComments(issue.number, sinceDate);
|
||||
|
||||
const filteredComments = comments.filter(
|
||||
comment =>
|
||||
comment.user.type === 'User' && comment.user.login !== context.actor
|
||||
comment => comment.user.type === 'User' && comment.user.login !== actor
|
||||
);
|
||||
|
||||
core.info(
|
||||
@@ -304,6 +340,18 @@ 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
|
||||
private async getIssues(page: number): Promise<Issue[]> {
|
||||
// generate type for response
|
||||
@@ -430,14 +478,70 @@ 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
|
||||
private async removeLabel(issue: Issue, label: string): Promise<void> {
|
||||
core.info(`Removing label from issue #${issue.number}`);
|
||||
core.info(`Removing label "${label}" from issue #${issue.number}`);
|
||||
|
||||
this.removedLabelIssues.push(issue);
|
||||
|
||||
this.operationsLeft -= 1;
|
||||
|
||||
// @todo remove the debug only to be able to test the code below
|
||||
if (this.options.debugOnly) {
|
||||
return;
|
||||
}
|
||||
@@ -447,7 +551,7 @@ export class IssueProcessor {
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
issue_number: issue.number,
|
||||
name: encodeURIComponent(label) // A label can have a "?" in the name
|
||||
name: label
|
||||
});
|
||||
} catch (error) {
|
||||
core.error(`Error removing a label: ${error.message}`);
|
||||
@@ -486,12 +590,6 @@ export class IssueProcessor {
|
||||
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 {
|
||||
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
|
||||
const millisSinceLastUpdated =
|
||||
@@ -499,11 +597,4 @@ export class IssueProcessor {
|
||||
|
||||
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());
|
||||
}
|
||||
}
|
||||
|
||||
187
src/functions/is-labeled.spec.ts
Normal file
187
src/functions/is-labeled.spec.ts
Normal file
@@ -0,0 +1,187 @@
|
||||
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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
26
src/functions/is-labeled.ts
Normal file
26
src/functions/is-labeled.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
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());
|
||||
}
|
||||
141
src/functions/labels-to-list.spec.ts
Normal file
141
src/functions/labels-to-list.spec.ts
Normal file
@@ -0,0 +1,141 @@
|
||||
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'
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
23
src/functions/labels-to-list.ts
Normal file
23
src/functions/labels-to-list.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* @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 {
|
||||
const args = {
|
||||
repoToken: core.getInput('repo-token', {required: true}),
|
||||
repoToken: core.getInput('repo-token'),
|
||||
staleIssueMessage: core.getInput('stale-issue-message'),
|
||||
stalePrMessage: core.getInput('stale-pr-message'),
|
||||
closeIssueMessage: core.getInput('close-issue-message'),
|
||||
@@ -42,7 +42,8 @@ function getAndValidateArgs(): IssueProcessorOptions {
|
||||
debugOnly: core.getInput('debug-only') === 'true',
|
||||
ascending: core.getInput('ascending') === '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'
|
||||
};
|
||||
|
||||
for (const numberInput of [
|
||||
|
||||
Reference in New Issue
Block a user