Compare commits

...

31 Commits

Author SHA1 Message Date
Luke Tomlinson
cdf15f641a Prep for v4 (#510)
* Update dist for v4 release

* Create CHANGELOG.md

* Update CHANGELOG.md

Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>

* Update CHANGELOG.md

Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>

* Update CHANGELOG.md

Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>

* Update CHANGELOG.md

Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>

* Update CHANGELOG.md

Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>

* Update CHANGELOG.md

* Update index.js

Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>
2021-07-14 10:21:39 -04:00
Luke Tomlinson
a78d0b721e Make label comparison case insensitive (#517)
* Make label comparison case insensitive

* PR Feedback
2021-07-12 13:56:58 -04:00
Luke Tomlinson
d901397e11 Filter comments by content instead of actor (#519)
* Filter comments by content instead of actor

* Remove dead actor code

* WIP fix tests

* Fix test
2021-07-12 10:37:47 -04:00
Geoffrey Testelin
678bfc7a59 docs(readme): update the permissions docs to reflect the requirements of the default config (#512)
Fixes #511
2021-06-24 16:30:27 -04:00
Geoffrey Testelin
d3bfc50685 Revert "feat(options): add new options to avoid stale base on comments (#494)" (#507)
This reverts commit 1efddcbe9f.
2021-06-15 17:16:31 -04:00
dependabot[bot]
f2ae27a59b build(deps-dev): bump @typescript-eslint/parser from 4.22.1 to 4.26.1 (#496)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 4.22.1 to 4.26.1.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/parser/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.26.1/packages/parser)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/parser"
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-14 10:07:58 -04:00
dependabot[bot]
4d1e45b796 build(deps-dev): bump typescript from 4.2.4 to 4.3.2 (#490)
Bumps [typescript](https://github.com/Microsoft/TypeScript) from 4.2.4 to 4.3.2.
- [Release notes](https://github.com/Microsoft/TypeScript/releases)
- [Commits](https://github.com/Microsoft/TypeScript/compare/v4.2.4...v4.3.2)

---
updated-dependencies:
- dependency-name: typescript
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-14 10:07:33 -04:00
Falk Puschner
92d4fc69d8 📝 Add requested permissions (#492)
* 📝 add requested permissions

* 📝 add minor improvement

* 📝 add required/recommended perimissions

* 📝 fix typo

Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>

* 📝 update recommended permissions

* 📝 update required permissions

* 📝 change permissions

* 📝 update recommended permissions

* ✏️ remove typo

Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>

Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>
2021-06-14 10:05:16 -04:00
Geoffrey Testelin
1efddcbe9f feat(options): add new options to avoid stale base on comments (#494)
* feat(options): add new options to avoid stale based on comments

Helping to close #441, #470, #435?
Closes #390 due to no activity

BREAKING CHANGES: the options related to remove-stale-when-updated will only check the updates, not the comment. It is only impactint the configurations using the value at false

* style(readme): fix table syntax due to rebase

* docs(readme): add permissions only for the new options
2021-06-14 09:56:55 -04:00
Geoffrey Testelin
f1017f33dd fix(dry-run): forbid mutations in dry-run (#500)
Bring back the dry-run by default for the tests - bad idea to disable it sorry
Fix bad documentation array format
Fixes #499
2021-06-10 10:14:45 -04:00
Ben Villalobos
b1da9e1fb1 Add support for adding & removing labels when no longer stale (#468)
* Add support for adding & removing labels when no longer stale

* Add remove/addLabelsWhenUpdatedFromStale to relevant spec files. Modify arguments to remove ambiguity in 'labels' var & parameter

* Change parameters for clarity, let autoformat do its thing

* PR feedback: More useful logging when removing labels

* Wrap client calls in try catches

* Use Unstale in variable names

* Don't run add label logic under debug

* Add test for labels added to unstale issues

* PR Feedback: logging

* Update README

* Rename vars to labels-to-add/remove-when-unstale

* Apply doc suggestions from code review

Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>

* PR Feedback

Co-authored-by: Geoffrey Testelin <geoffrey.testelin@gmail.com>
2021-06-08 09:31:20 -04:00
Falk Puschner
52f5648db3 🎨 Add message grouping (#483)
* 🎨 add message grouping

* ⚗️ try output

* 🔥 remove unnecessary code

* ⬆️ bump deps

* 🎨 build project

* ⬆️ bump deps

* 🎨 formatting code

* ⬇️ revert bumps

* 🎨 using logger service

* 🎨 using package lock version 1

* 🎨 add engines keyword

* ♻️ create processIssue method

*  add grouping method

* 🎨 build project

* 🎨 update engine declaration

* 💚 fix merge conflicts
2021-06-07 17:22:55 -04:00
Geoffrey Testelin
5f6f311ca6 fix(operations): fail fast the current batch to respect the operations limit (#474)
* fix(operations): fail fast the current batch to respect the operations limit

Instead of processing an entire batch of 100 issues before checking the operations left, simply do it before processing an issue so that we respect as expected the limitation of the operations per run
Fixes #466

* test(debug): disable the dry-run for the test by default

we will be able to test the operations per run and have more complete logs that could help us debug the workflow

* chore(logs): also display the stats when the operations per run stopped the workflow

* chore(stats): fix a bad stats related to the consumed operations

* test(operations-per-run): add coverage

* chore: update index
2021-06-07 15:20:11 -04:00
dependabot[bot]
8deaf75055 build(deps-dev): bump eslint from 7.21.0 to 7.28.0 (#486)
Bumps [eslint](https://github.com/eslint/eslint) from 7.21.0 to 7.28.0.
- [Release notes](https://github.com/eslint/eslint/releases)
- [Changelog](https://github.com/eslint/eslint/blob/master/CHANGELOG.md)
- [Commits](https://github.com/eslint/eslint/compare/v7.21.0...v7.28.0)

---
updated-dependencies:
- dependency-name: eslint
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-07 11:02:21 -04:00
dependabot[bot]
50571d3fa3 build(deps-dev): bump prettier from 2.2.1 to 2.3.1 (#485)
Bumps [prettier](https://github.com/prettier/prettier) from 2.2.1 to 2.3.1.
- [Release notes](https://github.com/prettier/prettier/releases)
- [Changelog](https://github.com/prettier/prettier/blob/main/CHANGELOG.md)
- [Commits](https://github.com/prettier/prettier/compare/2.2.1...2.3.1)

---
updated-dependencies:
- dependency-name: prettier
  dependency-type: direct:development
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-07 10:59:57 -04:00
Geoffrey Testelin
77a1abc9e8 chore(logs): add more logs and better dry-run (#463)
* feat(logs): improve the logs when removing the close label

A log was missing when the option was configured but the close label was not present on the issue/PR
Change the log about not removing the close label to explicitly mention that this behaviour occur because the option is not configured
Fixes #462

* feat(dry-run): display the logs and count the operations

the dry-run checks were cancelling way sooner the workflow
the logs and the count of operations could not occur in dry run due to this
the goal of the dry run is just to skip some logic regarding the api calls to avoid altering the repos but the goal IMO is to also make them reflect the real world run so this change allow this
BTW it also allow now to test the consumed operations
Fixes #461

* feat(logs): add more logs to debug the stale label removal

* chore(index): update index

* chore(dry-run): fix bad dry-run conditions
2021-06-07 09:49:49 -04:00
Ori Arditi
965862c5a6 minor fix (#487) 2021-06-07 09:27:59 -04:00
Falk Puschner
8e70fa8dee 🎨 Print outputs (#484)
* 🎨 print outputs

* 🎨 add missing identifier

* 🎨 capitalize step names
2021-06-07 08:56:40 -04:00
dependabot[bot]
9a928a1355 build(deps-dev): bump js-yaml from 4.0.0 to 4.1.0 (#448)
Bumps [js-yaml](https://github.com/nodeca/js-yaml) from 4.0.0 to 4.1.0.
- [Release notes](https://github.com/nodeca/js-yaml/releases)
- [Changelog](https://github.com/nodeca/js-yaml/blob/master/CHANGELOG.md)
- [Commits](https://github.com/nodeca/js-yaml/compare/4.0.0...4.1.0)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-04 16:47:10 -04:00
dependabot[bot]
39b3616748 build(deps): bump ws from 7.4.0 to 7.4.6 (#471)
Bumps [ws](https://github.com/websockets/ws) from 7.4.0 to 7.4.6.
- [Release notes](https://github.com/websockets/ws/releases)
- [Commits](https://github.com/websockets/ws/compare/7.4.0...7.4.6)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-04 16:45:30 -04:00
dependabot[bot]
4310353e56 build(deps-dev): bump @types/jest from 26.0.20 to 26.0.23 (#478)
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 26.0.20 to 26.0.23.
- [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases)
- [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/jest)

---
updated-dependencies:
- dependency-name: "@types/jest"
  dependency-type: direct:development
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-03 13:45:19 -04:00
dependabot[bot]
1e82956100 build(deps-dev): bump @typescript-eslint/eslint-plugin (#472)
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 4.16.1 to 4.26.0.
- [Release notes](https://github.com/typescript-eslint/typescript-eslint/releases)
- [Changelog](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/CHANGELOG.md)
- [Commits](https://github.com/typescript-eslint/typescript-eslint/commits/v4.26.0/packages/eslint-plugin)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-03 10:11:37 -04:00
dependabot[bot]
2347805002 build(deps-dev): bump ts-jest from 26.5.3 to 26.5.6 (#446)
Bumps [ts-jest](https://github.com/kulshekhar/ts-jest) from 26.5.3 to 26.5.6.
- [Release notes](https://github.com/kulshekhar/ts-jest/releases)
- [Changelog](https://github.com/kulshekhar/ts-jest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/kulshekhar/ts-jest/compare/v26.5.3...v26.5.6)

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-06-03 10:11:00 -04:00
Falk Puschner
3e6d35b685 feat(output): print output parameters (#458)
*  print output parameters

* 📝 add output table

* ⚗️ try output parameters

* ⚗️ stringify output

* ⚗️ try test output

* 🔥 remove test output

* 💚 build and lint code

* 🔥 remove output test

* 🔒 fix vulnerabilities

* 🎨 renaming staled variables

* 🎨 build code

* 📝 update contributing commands
2021-06-03 09:18:48 -04:00
Bryan Jenks
1648064648 use YAML comment syntax for comment in code chunk (#469) 2021-06-02 18:01:01 -04:00
Geoffrey Testelin
c2acfb4dd3 chore(release): provide a way to create a local release with less grunt work (#429)
* docs(contributing): add information to update the changelog

* docs(changelog): add a first draft

it needs to contain the new PRs and only contains a not very nice version of the previous release to have an example

* chore(release): propose a way to locally generate a release
2021-06-02 17:06:55 -04:00
Geoffrey Testelin
5fbbfba142 fix(logs): coloured logs (#465)
* refactor(logs): replace chalk by ansi-styles

* test(logs): fix the failing tests due to ansi styles

I was not able to disable or mock ansi-styles so instead I found a way to make the tests pass
it's not perfect but it's still nice because the logs will keep their trustful colour when running through the tests

* refactor(logs): simplify the syntax to colour the logs

* chore(rebase): update files due to rebase

* refactor(logger): reduce code duplication
2021-06-02 17:04:34 -04:00
Geoffrey Testelin
e884599072 docs(readme): add a brief summary for the default behaviour (#467)
@luketomlinson I think that we don't even need to change something in the default config due to the PR removing the skip comment options
2021-05-25 15:02:32 -04:00
Geoffrey Testelin
6ec637d238 feat(options): simplify config by removing skip stale message options (#457)
* feat(options): simplify config by removing skip stale message options

Closes #405
Closes #455

BREAKING CHANGES: remove skip-stale-issue-message and skip-stale-pr-message options. If you used this option, replace it by an empty message for the options stale-issue-message and stale-pr-message

* build(dist): update dist

also lint some files

* docs(readme): update the docs by removing the skip options
2021-05-25 14:14:22 -04:00
Geoffrey Testelin
16dfaa2c02 docs(overhaul): provide a very detailed documentation for the options (#456)
* docs: add doc for repo-token and fix a bunch of typo

* docs: add doc for days-before-stale

Closes #362

* docs: add doc for days-before-issue-stale

Closes #362

* docs: add doc for days-before-pr-stale

Closes #362

* docs: add doc for days-before-close options

Closes #362

* docs: add doc for stale-message options

Closes #362

* docs: add doc for close-message options

Closes #362

* docs: add doc for label options

Closes #362

* docs: add doc for exempt label options

Closes #362

* docs: add doc for only labels options

Closes #362

* docs: add doc for any of labels options

Closes #362

* docs: add doc for enable-statistics option

Closes #362

* docs: add doc for exempt milestones options

Closes #362

* docs: add doc for exempt all milestones options

Closes #362

* docs: add doc for assignees options

Closes #362

* docs: add doc for remove-stale-when-updated options

Closes #362

* docs: add doc for debug-only option

Closes #362

* docs: add doc for ascending option

Closes #362

* docs: add doc for skip-stale-message options

Closes #362

* docs: add doc for start-date option

Closes #362

* docs: add doc for delete-branch option

Closes #362

* docs: remove duplicated row

* docs: shorten the description in the array

* docs(readme): apply suggestion

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

* docs(readme): apply suggestion

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

* docs(readme): apply suggestion

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

* docs(readme): apply suggestion

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

* docs(readme): apply suggestion

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

* docs(readme): apply suggestion

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

* docs(readme): apply suggestion

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

* docs(readme): apply suggestion

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

* docs(readme): apply suggestion

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

* chore(readme): enhance typo

* chore(readme): enhance typo

* chore(readme): enhance typo

* docs(readme): apply suggestion

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>

* chore(readme): enhance typo

* chore(readme): enhance typo

* chore(readme): enhance typo

* chore(readme): enhance typo

* docs(readme): add more information for days-before-stale option

* docs(readme): apply suggestion

* docs(readme): remove duplicated entry

nice catch @luketomlinson

Co-authored-by: HonkingGoose <34918129+HonkingGoose@users.noreply.github.com>
2021-05-25 13:25:52 -04:00
Geoffrey Testelin
4586dc972d chore(issue): add a feature request template when opening an issue (#454)
Closes #453
2021-05-24 10:38:06 -04:00
43 changed files with 4216 additions and 3351 deletions

View File

@@ -28,7 +28,7 @@
"@typescript-eslint/no-array-constructor": "error",
"@typescript-eslint/no-empty-interface": "error",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/no-extraneous-class": "error",
"@typescript-eslint/no-extraneous-class": "off",
"@typescript-eslint/no-for-in-array": "error",
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/no-misused-new": "error",

View File

@@ -0,0 +1,11 @@
---
name: Feature request
about: Propose a new feature or an enhancement
title: ''
labels: enhancement
assignees: ''
---
## The problem
## The solution

View File

@@ -20,8 +20,7 @@ jobs:
runs-on: ...
steps:
- uses: actions/stale@...
with:
...
with: ...
```
## Further context

View File

@@ -1,5 +1,7 @@
<!-- List the change(s) you're making with this PR. -->
## Changes
- [x] ...
## Context

View File

@@ -9,8 +9,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@main
id: stale
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
exempt-issue-labels: 'blocked,must,should,keep'
- name: Print outputs
run: echo ${{ join(steps.stale.outputs.*, ',') }}

View File

@@ -19,7 +19,10 @@ jobs:
steps:
- uses: actions/checkout@v2
- uses: ./
id: stale
with:
stale-issue-message: 'This issue is stale'
stale-pr-message: 'This PR is stale'
debug-only: true
- name: Print outputs
run: echo ${{ join(steps.stale.outputs.*, ',') }}

3
.versionrc.json Normal file
View File

@@ -0,0 +1,3 @@
{
"header": "### Actions Stale Changelog\n"
}

24
CHANGELOG.md Normal file
View File

@@ -0,0 +1,24 @@
# Changelog
Starting in version 4.0.0 we will maintain a changelog
## [4.0.0](https://github.com/actions/stale/compare/v3.0.19...v4.0.0) (2021-07-14)
### Features
* **options:** simplify config by removing skip stale message options ([#457](https://github.com/actions/stale/issues/457)) ([6ec637d](https://github.com/actions/stale/commit/6ec637d238067ab8cc96c9289dcdac280bbd3f4a)), closes [#405](https://github.com/actions/stale/issues/405) [#455](https://github.com/actions/stale/issues/455)
* **output:** print output parameters ([#458](https://github.com/actions/stale/issues/458)) ([3e6d35b](https://github.com/actions/stale/commit/3e6d35b685f0b2fa1a69be893fa07d3d85e05ee0))
### Bug Fixes
* **dry-run:** forbid mutations in dry-run ([#500](https://github.com/actions/stale/issues/500)) ([f1017f3](https://github.com/actions/stale/commit/f1017f33dd159ea51366375120c3e6981d7c3097)), closes [#499](https://github.com/actions/stale/issues/499)
* **logs:** coloured logs ([#465](https://github.com/actions/stale/issues/465)) ([5fbbfba](https://github.com/actions/stale/commit/5fbbfba142860ea6512549e96e36e3540c314132))
* **operations:** fail fast the current batch to respect the operations limit ([#474](https://github.com/actions/stale/issues/474)) ([5f6f311](https://github.com/actions/stale/commit/5f6f311ca6aa75babadfc7bac6edf5d85fa3f35d)), closes [#466](https://github.com/actions/stale/issues/466)
* **label comparison**: make label comparison case insensitive [#517](https://github.com/actions/stale/pull/517), closes [#516](https://github.com/actions/stale/pull/516)
* **filtering comments by actor could have strange behavior**: "stale" comments are now detected based on if the message is the stale message not _who_ made the comment([#519](https://github.com/actions/stale/pull/519)), fixes [#441](https://github.com/actions/stale/pull/441), [#509](https://github.com/actions/stale/pull/509), [#518](https://github.com/actions/stale/pull/518)
### Breaking Changes
* The options `skip-stale-issue-message` and `skip-stale-pr-message` were removed. Instead, setting the options `stale-issue-message` and `stale-pr-message` will be enough to let the stale workflow add a comment. If the options are unset, a comment will not be added which was the equivalent of setting `skip-stale-issue-message` to `false`.
* The `operations-per-run` option will be more effective. After migrating, you could face a failed-fast process workflow if you let the default value (30) or set it to a small number. In that case, you will see a warning at the end of the logs (if enabled) indicating that the workflow was stopped sooner to avoid consuming too much API calls. In most cases, you can just increase this limit to make sure to process everything in a single run.

View File

@@ -1,4 +1,4 @@
### Building and testing
# Building and testing
Install the dependencies.
@@ -21,25 +21,47 @@ $ npm test
Run the tests and display only the first failing tests :heavy_check_mark:
```bash
$ npm test:only-errors
$ npm run test:only-errors
```
Run the tests with the watch mode :heavy_check_mark:
```bash
$ npm test:watch
$ npm run test:watch
```
Run the linter and fix (almost) every issue for you :heavy_check_mark:
```bash
$ npm lint:all:fix
$ npm run lint:all:fix
```
### Before creating a PR
# Before creating a PR
## Build and quality checks
Build, lint, package and test everything.
```bash
$ npm all
$ npm run all
```
# Release
Based on [standard-version](https://github.com/conventional-changelog/standard-version).
## Define the new version
You can run `npm run release:dry-run` to create a dry-run, or you can directly run `npm run release` to create a new local release.
It will run `prerelease` beforehand to build and pack everything.
If the `prerelease` succeeded, a bump of version will happen based on the unreleased commits.
It will:
- Update the _package.json_ version field
- Update the _package-lock.json_ version field
- Update the _CHANGELOG.md_ to include the release notes of the new version
- Create a local tag
- Create a commit
If everything generated seems ok for you, you can push your tag by running `git push --follow-tags origin {your-branch-name}`.

509
README.md
View File

@@ -2,71 +2,302 @@
Warns and then closes issues and PRs that have had no activity for a specified amount of time.
The default configuration will:
- Add a label "Stale" on issues and pull requests after 60 days of inactivity
- Close the stale issues and pull requests after 7 days of inactivity
- If an update/comment occur on stale issues or pull requests, the stale label will be removed and the timer will restart
## Recommended permissions
For the execution of this action, it must be able to fetch all issues and pull requests from your repository.
In addition, based on the provided configuration, the action could require more permission(s) (e.g.: add label, remove label, comment, close, etc.).
This can be achieved with the following [configuration in the action](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#permissions) if the permissions are restricted:
```yaml
permissions:
issues: write
pull-requests: write
```
You can find more information about the required permissions under the corresponding options that you wish to use.
## All options
### List of options
### List of input options
Every argument is optional.
| Input | Description |
| --------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `repo-token` | PAT (Personal Access Token) for authorizing the repository.<br>_Defaults to **${{ github.token }}**_. |
| `days-before-stale` | Idle number of days before marking an issue/PR as stale.<br>_Defaults to **60**_. |
| `days-before-issue-stale` | Idle number of days before marking an issue as stale.<br>_Override `days-before-stale`_. |
| `days-before-pr-stale` | Idle number of days before marking a PR as stale.<br>_Override `days-before-stale`_. |
| `days-before-close` | Idle number of days before closing a stale issue/PR.<br>_Defaults to **7**_. |
| `days-before-issue-close` | Idle number of days before closing a stale issue.<br>_Override `days-before-close`_. |
| `days-before-pr-close` | Idle number of days before closing a stale PR.<br>_Override `days-before-close`_. |
| `stale-issue-message` | Message to post on the stale issue. |
| `stale-pr-message` | Message to post on the stale PR. |
| `close-issue-message` | Message to post on the stale issue while closing it. |
| `close-pr-message` | Message to post on the stale PR while closing it. |
| `stale-issue-label` | Label to apply on the stale issue.<br>_Defaults to **Stale**_. |
| `close-issue-label` | Label to apply on closing issue.<br>Automatically removed if no longer closed nor locked). |
| `stale-pr-label` | Label to apply on the stale PR.<br>_Defaults to **Stale**_. |
| `close-pr-label` | Label to apply on the closing PR.<br>Automatically removed if no longer closed nor locked). |
| `exempt-issue-labels` | Labels on an issue exempted from being marked as stale. |
| `exempt-pr-labels` | Labels on the PR exempted from being marked as stale. |
| `only-labels` | Only issues and PRs with ALL these labels are checked.<br>Separate multiple labels with commas (eg. "question,answered"). |
| `only-issue-labels` | Only issues with ALL these labels are checked.<br>Separate multiple labels with commas (eg. "question,answered").<br>_Override `only-labels`_. |
| `only-pr-labels` | Only PRs with ALL these labels are checked.<br>Separate multiple labels with commas (eg. "question,answered").<br>_Override `only-labels`_. |
| `any-of-labels` | Only issues and PRs with ANY of these labels are checked.<br>Separate multiple labels with commas (eg. "incomplete,waiting-feedback"). |
| `any-of-issue-labels` | Only issues with ANY of these labels are checked.<br>Separate multiple labels with commas (eg. "incomplete,waiting-feedback").<br>_Override `any-of-labels`_. |
| `any-of-pr-labels` | Only PRs with ANY of these labels are checked.<br>Separate multiple labels with commas (eg. "incomplete,waiting-feedback").<br>_Override `any-of-labels`_. |
| `operations-per-run` | Maximum number of operations per run.<br>GitHub API CRUD related.<br>_Defaults to **30**_. |
| `remove-stale-when-updated` | Remove stale label from issue/PR on updates or comments.<br>_Defaults to **true**_. |
| `remove-issue-stale-when-updated` | Remove stale label from issue on updates or comments.<br>_Defaults to **true**_.<br>_Override `remove-stale-when-updated`_. |
| `remove-pr-stale-when-updated` | Remove stale label from PR on updates or comments.<br>_Defaults to **true**_.<br>_Override `remove-stale-when-updated`_. |
| `remove-issue-stale-when-updated` | Remove stale label from issue on updates or comments.<br>_Defaults to **true**_.<br>_Override `remove-stale-when-updated`_. |
| `remove-pr-stale-when-updated` | Remove stale label from PR on updates or comments.<br>_Defaults to **true**_.<br>_Override `remove-stale-when-updated`_. |
| `debug-only` | Dry-run on action.<br>_Defaults to **false**_. |
| `ascending` | Order to get issues/PR.<br>`true` is ascending, `false` is descending.<br>_Defaults to **false**_. |
| `skip-stale-issue-message` | Skip adding stale message on stale issue.<br>_Defaults to **false**_. |
| `skip-stale-pr-message` | Skip adding stale message on stale PR.<br>_Defaults to **false**_. |
| `start-date` | The date used to skip the stale action on issue/PR created before it.<br>ISO 8601 or RFC 2822. |
| `delete-branch` | Delete the git branch after closing a stale pull request.<br>_Defaults to **false**_. |
| `exempt-milestones` | Milestones on an issue or a PR exempted from being marked as stale. |
| `exempt-issue-milestones` | Milestones on an issue exempted from being marked as stale.<br>_Override `exempt-milestones`_. |
| `exempt-pr-milestones` | Milestones on the PR exempted from being marked as stale.<br>_Override `exempt-milestones`_. |
| `exempt-all-milestones` | Exempt all issues and PRs with milestones from being marked as stale.<br>_Priority over `exempt-milestones` rules_. |
| `exempt-all-issue-milestones` | Exempt all issues with milestones from being marked as stale.<br>_Override `exempt-all-milestones`_. |
| `exempt-all-pr-milestones` | Exempt all PRs with milestones from being marked as stale.<br>_Override `exempt-all-milestones`_. |
| `exempt-assignees` | Assignees on an issue or a PR exempted from being marked as stale. |
| `exempt-issue-assignees` | Assignees on an issue exempted from being marked as stale.<br>_Override `exempt-assignees`_. |
| `exempt-pr-assignees` | Assignees on the PR exempted from being marked as stale.<br>_Override `exempt-assignees`_. |
| `exempt-all-assignees` | Exempt all issues and PRs with assignees from being marked as stale.<br>_Priority over `exempt-assignees` rules_. |
| `exempt-all-issue-assignees` | Exempt all issues with assignees from being marked as stale.<br>_Override `exempt-all-assignees`_. |
| `exempt-all-pr-assignees` | Exempt all PRs with assignees from being marked as stale.<br>_Override `exempt-all-assignees`_. |
| `enable-statistics` | Display some statistics at the end of the logs regarding the stale workflow.<br>Only when the logs are enabled.<br>_Defaults to **true**_. |
| Input | Description | Default |
| ------------------------------------------------------------------- | ------------------------------------------------------------------------ | --------------------- |
| [repo-token](#repo-token) | PAT for GitHub API authentication | `${{ github.token }}` |
| [days-before-stale](#days-before-stale) | Idle number of days before marking issues/PRs stale | `60` |
| [days-before-issue-stale](#days-before-issue-stale) | Override [days-before-stale](#days-before-stale) for issues only | |
| [days-before-pr-stale](#days-before-pr-stale) | Override [days-before-stale](#days-before-stale) for PRs only | |
| [days-before-close](#days-before-close) | Idle number of days before closing stale issues/PRs | `7` |
| [days-before-issue-close](#days-before-issue-close) | Override [days-before-close](#days-before-close) for issues only | |
| [days-before-pr-close](#days-before-pr-close) | Override [days-before-close](#days-before-close) for PRs only | |
| [stale-issue-message](#stale-issue-message) | Comment on the staled issues | |
| [stale-pr-message](#stale-pr-message) | Comment on the staled PRs | |
| [close-issue-message](#close-issue-message) | Comment on the staled issues while closed | |
| [close-pr-message](#close-pr-message) | Comment on the staled PRs while closed | |
| [stale-issue-label](#stale-issue-label) | Label to apply on staled issues | `Stale` |
| [close-issue-label](#close-issue-label) | Label to apply on closed issues | |
| [stale-pr-label](#stale-pr-label) | Label to apply on staled PRs | `Stale` |
| [close-pr-label](#close-pr-label) | Label to apply on closed PRs | |
| [exempt-issue-labels](#exempt-issue-labels) | Labels on issues exempted from stale | |
| [exempt-pr-labels](#exempt-pr-labels) | Labels on PRs exempted from stale | |
| [only-labels](#only-labels) | Only issues/PRs with ALL these labels are checked | |
| [only-issue-labels](#only-issue-labels) | Only issues with ALL these labels are checked | |
| [only-pr-labels](#only-pr-labels) | Only PRs with ALL these labels are checked | |
| [any-of-labels](#any-of-labels) | Only issues/PRs with ANY of these labels are checked | |
| [any-of-issue-labels](#any-of-issue-labels) | Only issues with ANY of these labels are checked | |
| [any-of-pr-labels](#any-of-pr-labels) | Only PRs with ANY of these labels are checked | |
| [operations-per-run](#operations-per-run) | Max number of operations per run | `30` |
| [remove-stale-when-updated](#remove-stale-when-updated) | Remove stale label from issues/PRs on updates/comments | `true` |
| [remove-issue-stale-when-updated](#remove-issue-stale-when-updated) | Remove stale label from issues on updates/comments | |
| [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | |
| [labels-to-add-when-unstale](#labels-to-add-when-unstale) | Add specified labels from issues/PRs when they become unstale | |
| [labels-to-remove-when-unstale](#labels-to-remove-when-unstale) | Remove specified labels from issues/PRs when they become unstale | |
| [debug-only](#debug-only) | Dry-run | `false` |
| [ascending](#ascending) | Order to get issues/PRs | `false` |
| [start-date](#start-date) | Skip stale action for issues/PRs created before it | |
| [delete-branch](#delete-branch) | Delete branch after closing a stale PR | `false` |
| [exempt-milestones](#exempt-milestones) | Milestones on issues/PRs exempted from stale | |
| [exempt-issue-milestones](#exempt-issue-milestones) | Override [exempt-milestones](#exempt-milestones) for issues only | |
| [exempt-pr-milestones](#exempt-pr-milestones) | Override [exempt-milestones](#exempt-milestones) for PRs only | |
| [exempt-all-milestones](#exempt-all-milestones) | Exempt all issues/PRs with milestones from stale | |
| [exempt-all-issue-milestones](#exempt-all-issue-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for issues only | |
| [exempt-all-pr-milestones](#exempt-all-pr-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for PRs only | |
| [exempt-assignees](#exempt-assignees) | Assignees on issues/PRs exempted from stale | |
| [exempt-issue-assignees](#exempt-issue-assignees) | Override [exempt-assignees](#exempt-assignees) for issues only | |
| [exempt-pr-assignees](#exempt-pr-assignees) | Override [exempt-assignees](#exempt-assignees) for PRs only | |
| [exempt-all-assignees](#exempt-all-assignees) | Exempt all issues/PRs with assignees from stale | |
| [exempt-all-issue-assignees](#exempt-all-issue-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for issues only | |
| [exempt-all-pr-assignees](#exempt-all-pr-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for PRs only | |
| [enable-statistics](#enable-statistics) | Display statistics in the logs | `true` |
### List of output options
| Output | Description |
| ----------------- | -------------------------------------------- |
| staled-issues-prs | List of all staled issues and pull requests. |
| closed-issues-prs | List of all closed issues and pull requests. |
### Detailed options
#### repo-token
Personal Access Token (PAT) that allows the stale workflow to authenticate and perform API calls to GitHub.
Under the hood, it uses the [@actions/github](https://www.npmjs.com/package/@actions/github) package.
Default value: `${{ github.token }}`
#### days-before-stale
The idle number of days before marking the issues or the pull requests as stale (by adding a label).
The issues or the pull requests will be marked as stale if the last update (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) is older than the idle number of days.
If set to a negative number like `-1`, no issues or pull requests will be marked as stale automatically.
In that case, you can still add the stale label manually to mark as stale.
The label used to stale is defined by these two options:
- [stale-issue-label](#stale-issue-label)
- [stale-pr-label](#stale-pr-label)
A comment can also be added to notify about the stale and is defined by these two options:
- [stale-issue-message](#stale-issue-message)
- [stale-pr-message](#stale-pr-message)
You can fine tune which issues or pull requests should be marked as stale based on the milestones, the assignees, the creation date and the missing/present labels from these options:
- [exempt-issue-labels](#exempt-issue-labels)
- [exempt-pr-labels](#exempt-pr-labels)
- [only-labels](#only-labels)
- [any-of-labels](#any-of-labels)
- [start-date](#start-date)
- [exempt-milestones](#exempt-milestones)
- [exempt-all-milestones](#exempt-all-milestones)
- [exempt-assignees](#exempt-assignees)
- [exempt-all-assignees](#exempt-all-assignees)
Default value: `60`
#### days-before-issue-stale
Useful to override [days-before-stale](#days-before-stale) but only for the idle number of days before marking the issues as stale.
Default value: unset
#### days-before-pr-stale
Useful to override [days-before-stale](#days-before-stale) but only for the idle number of days before marking the pull requests as stale.
Default value: unset
#### days-before-close
The idle number of days before closing the stale issues or the stale pull requests (due to the stale label).
The issues or the pull requests will be closed if the last update (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) is older than the idle number of days.
Since adding the stale label will alter the last update date, we can calculate the number of days from this date.
If set to a negative number like `-1`, the issues or the pull requests will never be closed automatically.
The label used to stale is defined by these two options:
- [stale-issue-label](#stale-issue-label)
- [stale-pr-label](#stale-pr-label)
Default value: `7`
#### days-before-issue-close
Override [days-before-close](#days-before-close) but only for the idle number of days before closing the stale issues.
Default value: unset
#### days-before-pr-close
Override [days-before-close](#days-before-close) but only for the idle number of days before closing the stale pull requests.
Default value: unset
#### stale-issue-message
The message that will be added as a comment to the issues when the stale workflow marks it automatically as stale with a label.
You can skip the comment sending by omitting the option or by passing an empty string.
Default value: unset
Required Permission: `issues: write`
#### stale-pr-message
The message that will be added as a comment to the pull requests when the stale workflow marks it automatically as stale with a label.
You can skip the comment sending by omitting the option or by passing an empty string.
Default value: unset
Required Permission: `pull-requests: write`
#### close-issue-message
The message that will be added as a comment to the issues when the stale workflow closes it automatically after being stale for too long.
Default value: unset
Required Permission: `issues: write`
#### close-pr-message
The message that will be added as a comment to the pull requests when the stale workflow closes it automatically after being stale for too long.
Default value: unset
Required Permission: `pull-requests: write`
#### stale-issue-label
The label that will be added to the issues when automatically marked as stale.
If you wish to speedup the stale workflow for the issues, you can add this label manually to mark as stale.
Default value: `Stale`
Required Permission: `issues: write`
#### close-issue-label
The label that will be added to the issues when closed automatically.
It will be automatically removed if the issues are no longer closed nor locked.
Default value: unset
Required Permission: `issues: write`
#### stale-pr-label
The label that will be added to the pull requests when automatically marked as stale.
If you wish to speedup the stale workflow for the pull requests, you can add this label manually to mark as stale.
Default value: `Stale`
Required Permission: `pull-requests: write`
#### close-pr-label
The label that will be added to the pull requests when closed automatically.
It will be automatically removed if the pull requests are no longer closed nor locked.
Default value: unset
Required Permission: `pull-requests: write`
#### exempt-issue-labels
The label(s) that can exempt to automatically mark as stale the issues.
It can be a comma separated list of labels (e.g: `question,bug`).
If unset (or an empty string), this option will not alter the stale workflow.
Default value: unset
#### exempt-pr-labels
The label(s) that can exempt to automatically mark as stale the pull requests.
It can be a comma separated list of labels (e.g: `need-help,WIP`).
If unset (or an empty string), this option will not alter the stale workflow.
Default value: unset
#### only-labels
An allow-list of label(s) to only process the issues or the pull requests that contain all these label(s).
It can be a comma separated list of labels (e.g: `answered,needs-rebase`).
If unset (or an empty string), this option will not alter the stale workflow.
If you wish to only check that the issues or the pull requests contain one of these label(s), use instead [any-of-labels](#any-of-labels).
Default value: unset
#### only-issue-labels
Override [only-labels](#only-labels) but only to process the issues that contain all these label(s).
Default value: unset
#### only-pr-labels
Override [only-labels](#only-labels) but only to process the pull requests that contain all these label(s).
Default value: unset
#### any-of-labels
An allow-list of label(s) to only process the issues or the pull requests that contain one of these label(s).
It can be a comma separated list of labels (e.g: `answered,needs-rebase`).
If unset (or an empty string), this option will not alter the stale workflow.
If you wish to only check that the issues or the pull requests contain all these label(s), use instead [only-labels](#only-labels).
Default value: unset
#### any-of-issue-labels
Override [any-of-labels](#any-of-labels) but only to process the issues that contain one of these label(s).
Default value: unset
#### any-of-pr-labels
Override [any-of-labels](#any-of-labels) but only to process the pull requests that contain one of these label(s).
Default value: unset
#### operations-per-run
_Context:_
This action performs some API calls to GitHub to fetch or close issues and pull requests, set or update labels, add comments, delete branches, etc.
These operations are made in a very short period of time - because the action is very fast to run - and can be numerous based on your project action configuration and the quantity of issues and pull requests within it.
GitHub has a [rate limit](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting) and if reached will block all of these API calls for one hour (or API calls from other actions using the same user (a.k.a: the github-token from the [repo-token](#repo-token) option)).
These operations are made in a very short period of time because the action is very fast to run and can be numerous based on your project action configuration and the quantity of issues and pull requests within it.
GitHub has a [rate limit](https://docs.github.com/en/rest/overview/resources-in-the-rest-api#rate-limiting) and if reached will block these API calls for one hour (or API calls from other actions using the same user (a.k.a.: the github-token from the [repo-token](#repo-token) option)).
This option helps you to stay within the GitHub rate limits, as you can use this option to limit the number of operations for a single run.
_Purpose:_
@@ -75,13 +306,173 @@ This option aims to limit the number of operations made with the GitHub API to a
Based on your project, your GitHub business plan and the date of the cron job you set for this action, you can increase this limit to a higher number.
If you are not sure which is the right value for you or if the default value is good enough, you could enable the logs and look at the end of the stale action.
If you reached the limit, you will see a warning message in the logs, telling you that you should increase the number of operations.
If you choose not to increase the limit, you might end up with un-processed issues or pull requests after a stale action run.
If you choose not to increase the limit, you might end up with unprocessed issues or pull requests after a stale action run.
When [debugging](#Debugging), you can set it to a much higher number like `1000` since there will be fewer operations made with the GitHub API.
Only the [actor](#repo-token) and the batch of issues (100 per batch) will consume the operations.
Default value: `30`
#### remove-stale-when-updated
Automatically remove the stale label when the issues or the pull requests are updated (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) or commented.
Default value: `true`
Required Permission: `issues: write` and `pull-requests: write`
#### remove-issue-stale-when-updated
Override [remove-stale-when-updated](#remove-stale-when-updated) but only to automatically remove the stale label when the issues are updated (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) or commented.
Default value: unset
Required Permission: `issues: write`
#### remove-pr-stale-when-updated
Override [remove-stale-when-updated](#remove-stale-when-updated) but only to automatically remove the stale label when the pull requests are updated (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) or commented.
Default value: unset
#### labels-to-add-when-unstale
A comma delimited list of labels to add when a stale issue or pull request receives activity and has the [stale-issue-label](#stale-issue-label) or [stale-pr-label](#stale-pr-label) removed from it.
Default value: unset
#### labels-to-remove-when-unstale
A comma delimited list of labels to remove when a stale issue or pull request receives activity and has the [stale-issue-label](#stale-issue-label) or [stale-pr-label](#stale-pr-label) removed from it.
Warning: each label results in a unique API call which can drastically consume the limit of [operations-per-run](#operations-per-run).
Default value: unset
Required Permission: `pull-requests: write`
#### debug-only
Run the stale workflow as dry-run.
No GitHub API calls that can alter your issues and pull requests will happen.
Useful to debug or when you want to configure the stale workflow safely.
Default value: `false`
#### ascending
Change the order used to fetch the issues and pull requests from GitHub:
- `true` is for ascending.
- `false` is for descending.
It can be useful if your repository is processing so many issues and pull requests that you reach the [operations-per-run](#operations-per-run) limit.
Based on the order, you could prefer to focus on the new content or on the old content of your repository.
Default value: `false`
#### start-date
The start date is used to ignore the issues and pull requests created before the start date.
Particularly useful when you wish to add this stale workflow on an existing repository and only wish to stale the new issues and pull requests.
If set, the date must be formatted following the `ISO 8601` or `RFC 2822` standard.
Default value: unset
#### delete-branch
If set to `true`, the stale workflow will automatically delete the GitHub branches related to the pull requests automatically closed by the stale workflow.
Default value: `false`
Required Permission: `pull-requests: write`
#### exempt-milestones
A white-list of milestone(s) to only process the issues or the pull requests that does not contain one of these milestone(s).
It can be a comma separated list of milestones (e.g: `V1,next`).
If unset (or an empty string), this option will not alter the stale workflow.
Default value: unset
#### exempt-issue-milestones
Override [exempt-milestones](#exempt-milestones) but only to process the issues that does not contain one of these milestone(s).
Default value: unset
#### exempt-pr-milestones
Override [exempt-milestones](#exempt-milestones) but only to process the pull requests that does not contain one of these milestone(s).
Default value: unset
#### exempt-all-milestones
If set to `true`, the issues or the pull requests with a milestone will not be marked as stale automatically.
Priority over [exempt-milestones](#exempt-milestones).
Default value: `false`
#### exempt-all-issue-milestones
Override [exempt-all-milestones](#exempt-all-milestones) but only to exempt the issues with a milestone to be marked as stale automatically.
Default value: unset
#### exempt-all-pr-milestones
Override [exempt-all-milestones](#exempt-all-milestones) but only to exempt the pull requests with a milestone to be marked as stale automatically.
Default value: unset
#### exempt-assignees
An allow-list of assignee(s) to only process the issues or the pull requests that does not contain one of these assignee(s).
It can be a comma separated list of assignees (e.g: `marco,polo`).
If unset (or an empty string), this option will not alter the stale workflow.
Default value: unset
#### exempt-issue-assignees
Override [exempt-assignees](#exempt-assignees) but only to process the issues that does not contain one of these assignee(s).
Default value: unset
#### exempt-pr-assignees
Override [exempt-assignees](#exempt-assignees) but only to process the pull requests that does not contain one of these assignee(s).
Default value: unset
#### exempt-all-assignees
If set to `true`, the issues or the pull requests with an assignee will not be marked as stale automatically.
Priority over [exempt-assignees](#exempt-assignees).
Default value: `false`
#### exempt-all-issue-assignees
Override [exempt-all-assignees](#exempt-all-assignees) but only to exempt the issues with an assignee to be marked as stale automatically.
Default value: unset
#### exempt-all-pr-assignees
Override [exempt-all-assignees](#exempt-all-assignees) but only to exempt the pull requests with an assignee to be marked as stale automatically.
Default value: unset
#### enable-statistics
Collects and display statistics at the end of the stale workflow logs to get a summary of what happened during the run.
This option is only useful if the debug output secret `ACTIONS_STEP_DEBUG` is set to `true` in your repository to display the logs.
Default value: `true`
### Usage
See also [action.yml](./action.yml) for a comprehensive list of all the options.
@@ -208,7 +599,7 @@ jobs:
steps:
- uses: actions/stale@v3
with:
start-date: '2020-18-04T00:00:00Z' // ISO 8601 or RFC 2822
start-date: '2020-18-04T00:00:00Z' # ISO 8601 or RFC 2822
```
Avoid stale for specific milestones:
@@ -304,7 +695,7 @@ jobs:
**Logs:**
To see the debug output from this action, you must set the secret `ACTIONS_STEP_DEBUG` to `true` in your repository.
There is a lot of logs so this can be very helpful!
There are many logs, so this can be very helpful!
**Statistics:**
If the logs are enabled, you can also enable the statistics log which will be visible at the end of the logs once all issues were processed.
@@ -320,9 +711,9 @@ If the `debug-only` option is enabled, this is very helpful because the workflow
**Job frequency:**
You could change the cron job frequency in the stale workflow to run the stale workflow more often.
Usually this is not very helpful though.
Usually, this is not very helpful though.
### Contributing
You wish to contribute?
Check out the [contributing](CONTRIBUTING.md) file before helping us.
We welcome contributions!
Please read the [contributing](CONTRIBUTING.md) file before starting your work.

View File

@@ -1112,14 +1112,12 @@ class IssuesProcessorBuilder {
issues(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: null
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: null
};
})
);
return this;
@@ -1127,14 +1125,12 @@ class IssuesProcessorBuilder {
prs(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: {key: 'value'}
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: {key: 'value'}
};
})
);
return this;
@@ -1143,7 +1139,6 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
async () => 'abot',
async p => (p === 1 ? this._issues : []),
async () => [],
async () => new Date().toDateString()

View File

@@ -48,7 +48,6 @@ describe('assignees options', (): void => {
const setProcessor = () => {
processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? testIssueList : []),
async () => [],
async () => new Date().toDateString()

View File

@@ -6,7 +6,6 @@ import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-opt
export class IssuesProcessorMock extends IssuesProcessor {
constructor(
options: IIssuesProcessorOptions,
getActor?: () => Promise<string>,
getIssues?: (page: number) => Promise<Issue[]>,
listIssueComments?: (
issueNumber: number,
@@ -19,10 +18,6 @@ export class IssuesProcessorMock extends IssuesProcessor {
) {
super(options);
if (getActor) {
this.getActor = getActor;
}
if (getIssues) {
this.getIssues = getIssues;
}

View File

@@ -30,8 +30,6 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined,
ascending: false,
skipStaleIssueMessage: false,
skipStalePrMessage: false,
deleteBranch: false,
startDate: '',
exemptMilestones: '',
@@ -46,5 +44,7 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
exemptAllAssignees: false,
exemptAllIssueAssignees: undefined,
exemptAllPrAssignees: undefined,
enableStatistics: true
enableStatistics: true,
labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: ''
});

View File

@@ -32,12 +32,10 @@ export function generateIssue(
title: milestone
}
: undefined,
assignees: assignees.map(
(assignee: Readonly<string>): IAssignee => {
return {
login: assignee
};
}
)
assignees: assignees.map((assignee: Readonly<string>): IAssignee => {
return {
login: assignee
};
})
});
}

View File

@@ -16,7 +16,6 @@ test('processing an issue with no label will make it stale and close it, if it i
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -48,7 +47,6 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -80,7 +78,6 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -112,7 +109,6 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -144,7 +140,6 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -176,7 +171,6 @@ test('processing an issue with no label and a start date as ISO 8601 being befor
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -208,7 +202,6 @@ test('processing an issue with no label and a start date as ISO 8601 being after
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -240,7 +233,6 @@ test('processing an issue with no label and a start date as RFC 2822 being befor
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -272,7 +264,6 @@ test('processing an issue with no label and a start date as RFC 2822 being after
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -296,7 +287,6 @@ test('processing an issue with no label will make it stale and close it, if it i
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -321,7 +311,6 @@ test('processing an issue with no label will make it stale and not close it, if
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -344,7 +333,6 @@ test('processing an issue with no label will make it stale and not close it if d
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -368,7 +356,6 @@ test('processing an issue with no label will make it stale and not close it if d
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -392,7 +379,6 @@ test('processing an issue with no label will not make it stale if days-before-st
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -417,7 +403,6 @@ test('processing an issue with no label will not make it stale if days-before-st
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -445,7 +430,6 @@ test('processing an issue with no label will make it stale but not close it', as
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -476,7 +460,6 @@ test('processing a stale issue will close it', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -507,7 +490,6 @@ test('processing a stale issue containing a space in the label will close it', a
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -538,7 +520,6 @@ test('processing a stale issue containing a slash in the label will close it', a
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -570,7 +551,6 @@ test('processing a stale issue will close it when days-before-issue-stale overri
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -601,7 +581,6 @@ test('processing a stale PR will close it', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -633,7 +612,6 @@ test('processing a stale PR will close it when days-before-pr-stale override day
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -665,7 +643,6 @@ test('processing a stale issue will close it even if configured not to mark as s
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -698,7 +675,6 @@ test('processing a stale issue will close it even if configured not to mark as s
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -730,7 +706,6 @@ test('processing a stale PR will close it even if configured not to mark as stal
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -763,7 +738,6 @@ test('processing a stale PR will close it even if configured not to mark as stal
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -791,7 +765,6 @@ test('closed issues will not be marked stale', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => []
);
@@ -818,7 +791,6 @@ test('stale closed issues will not be closed', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -846,7 +818,6 @@ test('closed prs will not be marked stale', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -874,7 +845,6 @@ test('stale closed prs will not be closed', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -901,10 +871,8 @@ test('locked issues will not be marked stale', async () => {
true
)
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : [])
const processor = new IssuesProcessorMock(DefaultProcessorOptions, async p =>
p === 1 ? TestIssueList : []
);
// process our fake issue list
@@ -930,7 +898,6 @@ test('stale locked issues will not be closed', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -957,10 +924,8 @@ test('locked prs will not be marked stale', async () => {
true
)
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : [])
const processor = new IssuesProcessorMock(DefaultProcessorOptions, async p =>
p === 1 ? TestIssueList : []
);
// process our fake issue list
@@ -986,7 +951,6 @@ test('stale locked prs will not be closed', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1016,7 +980,6 @@ test('exempt issue labels will not be marked stale', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1046,7 +1009,6 @@ test('exempt issue labels will not be marked stale (multi issue label with space
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1075,7 +1037,6 @@ test('exempt issue labels will not be marked stale (multi issue label)', async (
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1122,7 +1083,6 @@ test('exempt pr labels will not be marked stale', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1151,14 +1111,14 @@ test('exempt issue labels will not be marked stale and will remove the existing
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [
{
user: {
login: 'notme',
type: 'User'
}
},
body: 'Body'
}
], // return a fake comment to indicate there was an update
async () => new Date().toDateString()
@@ -1206,7 +1166,6 @@ test('stale issues should not be closed if days is set to -1', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1234,14 +1193,14 @@ test('stale label should be removed if a comment was added to a stale issue', as
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [
{
user: {
login: 'notme',
type: 'User'
}
},
body: 'Body'
}
], // return a fake comment to indicate there was an update
async () => new Date().toDateString()
@@ -1255,6 +1214,50 @@ test('stale label should be removed if a comment was added to a stale issue', as
expect(processor.removedLabelIssues).toHaveLength(1);
});
test('when the option "labelsToAddWhenUnstale" is set, the labels should be added when unstale', async () => {
expect.assertions(4);
const opts = {
...DefaultProcessorOptions,
removeStaleWhenUpdated: true,
labelsToAddWhenUnstale: 'test'
};
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue that should have labels added to it when unstale',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
['Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [
{
user: {
login: 'notme',
type: 'User'
},
body: 'Body'
}
], // return a fake comment to indicate there was an update
async () => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.closedIssues).toHaveLength(0);
expect(processor.staleIssues).toHaveLength(0);
// Stale should have been removed
expect(processor.removedLabelIssues).toHaveLength(1);
// Some label should have been added
expect(processor.addedLabelIssues).toHaveLength(1);
});
test('stale label should not be removed if a comment was added by the bot (and the issue should be closed)', async () => {
const opts = {...DefaultProcessorOptions, removeStaleWhenUpdated: true};
github.context.actor = 'abot';
@@ -1271,14 +1274,14 @@ test('stale label should not be removed if a comment was added by the bot (and t
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [
{
user: {
login: 'abot',
type: 'User'
}
},
body: 'This issue is stale'
}
], // return a fake comment to indicate there was an update by the bot
async () => new Date().toDateString()
@@ -1311,9 +1314,8 @@ test('stale label containing a space should be removed if a comment was added to
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [{user: {login: 'notme', type: 'User'}}], // return a fake comment to indicate there was an update
async () => [{user: {login: 'notme', type: 'User'}, body: 'Body'}], // return a fake comment to indicate there was an update
async () => new Date().toDateString()
);
@@ -1343,7 +1345,6 @@ test('stale issues should not be closed until after the closed number of days',
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1376,7 +1377,6 @@ test('stale issues should be closed if the closed nubmer of days (additive) is a
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1408,7 +1408,6 @@ test('stale issues should not be closed until after the closed number of days (l
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1422,11 +1421,11 @@ test('stale issues should not be closed until after the closed number of days (l
expect(processor.staleIssues).toHaveLength(1);
});
test('skips stale message on issues when skip-stale-issue-message is set', async () => {
test('skips stale message on issues when stale-issue-message is empty', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 20; // closes after 25 days
opts.skipStaleIssueMessage = true;
opts.staleIssueMessage = '';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
const TestIssueList: Issue[] = [
@@ -1441,7 +1440,6 @@ test('skips stale message on issues when skip-stale-issue-message is set', async
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1467,11 +1465,55 @@ test('skips stale message on issues when skip-stale-issue-message is set', async
);
});
test('skips stale message on prs when skip-stale-pr-message is set', async () => {
test('send stale message on issues when stale-issue-message is not empty', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 20; // closes after 25 days
opts.skipStalePrMessage = true;
opts.staleIssueMessage = 'dummy issue message';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue that should be marked stale but not closed',
lastUpdate.toString(),
lastUpdate.toString(),
false
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
// for sake of testing, mocking private function
const markSpy = jest.spyOn(processor as any, '_markStale');
await processor.processIssues(1);
// issue should be staled
expect(processor.closedIssues).toHaveLength(0);
expect(processor.removedLabelIssues).toHaveLength(0);
expect(processor.staleIssues).toHaveLength(1);
// comment should not be created
expect(markSpy).toHaveBeenCalledWith(
TestIssueList[0],
opts.staleIssueMessage,
opts.staleIssueLabel,
// this option is skipMessage
false
);
});
test('skips stale message on prs when stale-pr-message is empty', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 20; // closes after 25 days
opts.stalePrMessage = '';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
const TestIssueList: Issue[] = [
@@ -1486,7 +1528,6 @@ test('skips stale message on prs when skip-stale-pr-message is set', async () =>
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1512,46 +1553,11 @@ test('skips stale message on prs when skip-stale-pr-message is set', async () =>
);
});
test('not providing state takes precedence over skipStaleIssueMessage', async () => {
test('send stale message on prs when stale-pr-message is not empty', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 20; // closes after 25 days
opts.skipStalePrMessage = true;
opts.staleIssueMessage = '';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue that should be marked stale but not closed',
lastUpdate.toString(),
lastUpdate.toString(),
false
)
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
await processor.processIssues(1);
// issue should be staled
expect(processor.closedIssues).toHaveLength(0);
expect(processor.removedLabelIssues).toHaveLength(0);
expect(processor.staleIssues).toHaveLength(0);
});
test('not providing stalePrMessage takes precedence over skipStalePrMessage', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeStale = 5; // stale after 5 days
opts.daysBeforeClose = 20; // closes after 25 days
opts.skipStalePrMessage = true;
opts.stalePrMessage = '';
opts.stalePrMessage = 'dummy pr message';
const lastUpdate = new Date();
lastUpdate.setDate(lastUpdate.getDate() - 10);
const TestIssueList: Issue[] = [
@@ -1566,18 +1572,29 @@ test('not providing stalePrMessage takes precedence over skipStalePrMessage', as
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
// for sake of testing, mocking private function
const markSpy = jest.spyOn(processor as any, '_markStale');
await processor.processIssues(1);
// issue should be staled
expect(processor.closedIssues).toHaveLength(0);
expect(processor.removedLabelIssues).toHaveLength(0);
expect(processor.staleIssues).toHaveLength(0);
expect(processor.staleIssues).toHaveLength(1);
// comment should not be created
expect(markSpy).toHaveBeenCalledWith(
TestIssueList[0],
opts.stalePrMessage,
opts.stalePrLabel,
// this option is skipMessage
false
);
});
test('git branch is deleted when option is enabled', async () => {
@@ -1596,7 +1613,6 @@ test('git branch is deleted when option is enabled', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1626,7 +1642,6 @@ test('git branch is not deleted when issue is not pull request', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1658,7 +1673,6 @@ test('an issue without a milestone will be marked as stale', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1692,7 +1706,6 @@ test('an issue without an exempted milestone will be marked as stale', async ()
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1726,7 +1739,6 @@ test('an issue with an exempted milestone will not be marked as stale', async ()
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1760,7 +1772,6 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1794,7 +1805,6 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1829,7 +1839,6 @@ test('an issue with an exempted milestone but without an exempted issue mileston
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1864,7 +1873,6 @@ test('an issue with an exempted milestone but with another exempted issue milest
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1899,7 +1907,6 @@ test('an issue with an exempted milestone and with an exempted issue milestone w
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1927,7 +1934,6 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1954,7 +1960,6 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1981,7 +1986,6 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2015,7 +2019,6 @@ test('processing a pull request opened since 2 days and with the option "daysBef
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2049,7 +2052,6 @@ test('processing a pull request opened since 2 days and with the option "daysBef
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2083,7 +2085,6 @@ test('processing a pull request opened since 2 days and with the option "daysBef
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2120,7 +2121,6 @@ test('processing a previously closed issue with a close label will remove the cl
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2156,7 +2156,6 @@ test('processing a closed issue with a close label will not remove the close lab
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2192,7 +2191,6 @@ test('processing a locked issue with a close label will not remove the close lab
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2232,7 +2230,6 @@ test('processing an issue stale since less than the daysBeforeStale with a stale
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async (): Promise<IComment[]> => Promise.resolve([]),
async () => labelCreatedAt.toDateString()
@@ -2273,7 +2270,6 @@ test('processing an issue stale since less than the daysBeforeStale without a st
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async (): Promise<IComment[]> => Promise.resolve([]),
async () => new Date().toDateString()

View File

@@ -39,7 +39,6 @@ describe('milestones options', (): void => {
const setProcessor = () => {
processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? testIssueList : []),
async () => [],
async () => new Date().toDateString()

View File

@@ -1112,14 +1112,12 @@ class IssuesProcessorBuilder {
issues(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: null
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: null
};
})
);
return this;
@@ -1127,14 +1125,12 @@ class IssuesProcessorBuilder {
prs(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: {key: 'value'}
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: {key: 'value'}
};
})
);
return this;
@@ -1143,7 +1139,6 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
async () => 'abot',
async p => (p === 1 ? this._issues : []),
async () => [],
async () => new Date().toDateString()

View File

@@ -0,0 +1,227 @@
import {Issue} from '../src/classes/issue';
import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options';
import {IsoDateString} from '../src/types/iso-date-string';
import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue';
describe('operations per run option', (): void => {
let sut: SUT;
beforeEach((): void => {
sut = new SUT();
});
describe('when one issue should be stale within 10 days and updated 20 days ago', (): void => {
beforeEach((): void => {
sut.staleIn(10).newIssue().updated(20);
});
describe('when the operations per run option is set to 1', (): void => {
beforeEach((): void => {
sut.operationsPerRun(1);
});
it('should consume 1 operation (stale label)', async () => {
expect.assertions(2);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(
sut.processor.operations.getConsumedOperationsCount()
).toStrictEqual(1);
});
});
});
describe('when one issue should be stale within 10 days and updated 20 days ago and a comment should be added when stale', (): void => {
beforeEach((): void => {
sut.staleIn(10).commentOnStale().newIssue().updated(20);
});
describe('when the operations per run option is set to 2', (): void => {
beforeEach((): void => {
sut.operationsPerRun(2);
});
it('should consume 2 operations (stale label, comment)', async () => {
expect.assertions(2);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(
sut.processor.operations.getConsumedOperationsCount()
).toStrictEqual(2);
});
});
// Special case were we continue the issue processing even if the operations per run is reached
describe('when the operations per run option is set to 1', (): void => {
beforeEach((): void => {
sut.operationsPerRun(1);
});
it('should consume 2 operations (stale label, comment)', async () => {
expect.assertions(2);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(
sut.processor.operations.getConsumedOperationsCount()
).toStrictEqual(2);
});
});
});
describe('when two issues should be stale within 10 days and updated 20 days ago and a comment should be added when stale', (): void => {
beforeEach((): void => {
sut.staleIn(10).commentOnStale();
sut.newIssue().updated(20);
sut.newIssue().updated(20);
});
describe('when the operations per run option is set to 3', (): void => {
beforeEach((): void => {
sut.operationsPerRun(3);
});
it('should consume 4 operations (stale label, comment)', async () => {
expect.assertions(2);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(2);
expect(
sut.processor.operations.getConsumedOperationsCount()
).toStrictEqual(4);
});
});
describe('when the operations per run option is set to 2', (): void => {
beforeEach((): void => {
sut.operationsPerRun(2);
});
it('should consume 2 operations (stale label, comment) and stop', async () => {
expect.assertions(2);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(
sut.processor.operations.getConsumedOperationsCount()
).toStrictEqual(2);
});
});
// Special case were we continue the issue processing even if the operations per run is reached
describe('when the operations per run option is set to 1', (): void => {
beforeEach((): void => {
sut.operationsPerRun(1);
});
it('should consume 2 operations (stale label, comment) and stop', async () => {
expect.assertions(2);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(
sut.processor.operations.getConsumedOperationsCount()
).toStrictEqual(2);
});
});
});
});
class SUT {
processor!: IssuesProcessorMock;
private _opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
staleIssueMessage: ''
};
private _testIssueList: Issue[] = [];
private _sutIssues: SUTIssue[] = [];
newIssue(): SUTIssue {
const sutIssue: SUTIssue = new SUTIssue();
this._sutIssues.push(sutIssue);
return sutIssue;
}
staleIn(days: number): SUT {
this._updateOptions({
daysBeforeIssueStale: days
});
return this;
}
commentOnStale(): SUT {
this._updateOptions({
staleIssueMessage: 'Dummy stale issue message'
});
return this;
}
operationsPerRun(count: number): SUT {
this._updateOptions({
operationsPerRun: count
});
return this;
}
async test(): Promise<number> {
return this._setTestIssueList()._setProcessor();
}
private _updateOptions(opts: Partial<IIssuesProcessorOptions>): SUT {
this._opts = {...this._opts, ...opts};
return this;
}
private _setTestIssueList(): SUT {
this._testIssueList = this._sutIssues.map((sutIssue: SUTIssue): Issue => {
return generateIssue(
this._opts,
1,
'My first issue',
sutIssue.updatedAt,
sutIssue.updatedAt,
false
);
});
return this;
}
private async _setProcessor(): Promise<number> {
this.processor = new IssuesProcessorMock(
this._opts,
async p => (p === 1 ? this._testIssueList : []),
async () => [],
async () => new Date().toDateString()
);
return this.processor.processIssues(1);
}
}
class SUTIssue {
updatedAt: IsoDateString = '2020-01-01T17:00:00Z';
updated(daysAgo: number): SUTIssue {
const today = new Date();
today.setDate(today.getDate() - daysAgo);
this.updatedAt = today.toISOString();
return this;
}
}

View File

@@ -464,14 +464,12 @@ class IssuesProcessorBuilder {
issues(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: null
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: null
};
})
);
return this;
@@ -479,27 +477,23 @@ class IssuesProcessorBuilder {
staleIssues(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issues(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
updated_at: '2020-01-01T17:00:00Z',
created_at: '2020-01-01T17:00:00Z',
labels: issue.labels?.map(
(label: Readonly<ILabel>): ILabel => {
return {
...label,
name: 'Stale'
};
}
) ?? [
{
name: 'Stale'
}
]
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
updated_at: '2020-01-01T17:00:00Z',
created_at: '2020-01-01T17:00:00Z',
labels: issue.labels?.map((label: Readonly<ILabel>): ILabel => {
return {
...label,
name: 'Stale'
};
}) ?? [
{
name: 'Stale'
}
]
};
})
);
return this;
@@ -507,14 +501,12 @@ class IssuesProcessorBuilder {
prs(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: {key: 'value'}
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: {key: 'value'}
};
})
);
return this;
@@ -522,27 +514,23 @@ class IssuesProcessorBuilder {
stalePrs(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.prs(
issues.map(
(issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
updated_at: '2020-01-01T17:00:00Z',
created_at: '2020-01-01T17:00:00Z',
labels: issue.labels?.map(
(label: Readonly<ILabel>): ILabel => {
return {
...label,
name: 'Stale'
};
}
) ?? [
{
name: 'Stale'
}
]
};
}
)
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
updated_at: '2020-01-01T17:00:00Z',
created_at: '2020-01-01T17:00:00Z',
labels: issue.labels?.map((label: Readonly<ILabel>): ILabel => {
return {
...label,
name: 'Stale'
};
}) ?? [
{
name: 'Stale'
}
]
};
})
);
return this;
@@ -551,14 +539,14 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
async () => 'abot',
async p => (p === 1 ? this._issues : []),
async () => [
{
user: {
login: 'notme',
type: 'User'
}
},
body: 'body'
}
],
async () => new Date().toDateString()

View File

@@ -118,11 +118,11 @@ inputs:
required: false
remove-issue-stale-when-updated:
description: 'Remove stale labels from issues when they are updated or commented on. Override "remove-stale-when-updated" option regarding only the issues.'
default: 'true'
default: ''
required: false
remove-pr-stale-when-updated:
description: 'Remove stale labels from pull requests when they are updated or commented on. Override "remove-stale-when-updated" option regarding only the pull requests.'
default: 'true'
default: ''
required: false
debug-only:
description: 'Run the processor in debug mode without actually performing any operations on live issues.'
@@ -132,14 +132,6 @@ inputs:
description: 'The order to get issues or pull requests. Defaults to false, which is descending.'
default: 'false'
required: false
skip-stale-pr-message:
description: 'Skip adding stale message when marking a pull request as stale.'
default: 'false'
required: false
skip-stale-issue-message:
description: 'Skip adding stale message when marking an issue as stale.'
default: 'false'
required: false
delete-branch:
description: 'Delete the git branch after closing a stale pull request.'
default: 'false'
@@ -176,6 +168,11 @@ inputs:
description: 'Display some statistics at the end regarding the stale workflow (only when the logs are enabled).'
default: 'true'
required: false
outputs:
closed-issues-prs:
description: 'List of all closed issues and pull requests.'
staled-issues-prs:
description: 'List of all staled issues and pull requests.'
runs:
using: 'node12'
main: 'dist/index.js'

2980
dist/index.js vendored

File diff suppressed because it is too large Load Diff

View File

@@ -7,6 +7,5 @@ module.exports = {
transform: {
'^.+\\.ts$': 'ts-jest'
},
verbose: true,
setupFilesAfterEnv: [`./jest/test.ts`]
verbose: true
};

View File

@@ -1,11 +0,0 @@
import chalk from 'chalk';
// Disabled the colors to:
// - improve the performances
// - avoid to mock chalk
// - avoid to have failing tests when testing the logs due to the extra text the log message will contains
//
// Note:
// If you need to debug the log colours you can remove this line temporarily
// But some tests will fail
chalk.level = 0;

1946
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -16,7 +16,10 @@
"test": "jest",
"test:only-errors": "jest --reporters jest-silent-reporter --silent",
"test:watch": "jest --watch --notify --expand",
"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",
"prerelease": "npm run build && npm run pack",
"release": "standard-version",
"release:dry-run": "standard-version --dry-run"
},
"repository": {
"type": "git",
@@ -27,6 +30,10 @@
"node",
"stale"
],
"engines": {
"node": "12",
"npm": "6"
},
"author": "GitHub",
"license": "MIT",
"dependencies": {
@@ -36,24 +43,25 @@
"semver": "^7.3.5"
},
"devDependencies": {
"@types/jest": "^26.0.20",
"@types/jest": "^26.0.23",
"@types/lodash.deburr": "^4.1.6",
"@types/node": "^15.0.2",
"@types/semver": "^7.3.5",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.22.1",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.1",
"@vercel/ncc": "^0.27.0",
"chalk": "^4.1.0",
"eslint": "^7.21.0",
"ansi-styles": "5.2.0",
"eslint": "^7.28.0",
"eslint-plugin-github": "^4.1.2",
"eslint-plugin-jest": "^24.3.6",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"jest-silent-reporter": "^0.4.0",
"js-yaml": "^4.0.0",
"prettier": "^2.2.1",
"js-yaml": "^4.1.0",
"prettier": "^2.3.1",
"standard-version": "^9.2.0",
"terminal-link": "^2.1.1",
"ts-jest": "^26.5.3",
"typescript": "^4.2.4"
"ts-jest": "^26.5.6",
"typescript": "^4.3.2"
}
}

View File

@@ -1,4 +1,3 @@
import chalk from 'chalk';
import deburr from 'lodash.deburr';
import {Option} from '../enums/option';
import {wordsToList} from '../functions/words-to-list';
@@ -6,6 +5,7 @@ import {IAssignee} from '../interfaces/assignee';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
import {LoggerService} from '../services/logger.service';
type CleanAssignee = string;
@@ -34,7 +34,7 @@ export class Assignees {
if (this._shouldExemptAllAssignees()) {
this._issueLogger.info(
chalk.white('└──'),
LoggerService.white('└──'),
'Skipping this $$type because it has an exempt assignee'
);
@@ -45,7 +45,7 @@ export class Assignees {
if (exemptAssignees.length === 0) {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`No assignee option was specified to skip the stale process for this $$type`
);
this._logSkip();
@@ -54,8 +54,8 @@ export class Assignees {
}
this._issueLogger.info(
chalk.white('├──'),
`Found ${chalk.cyan(exemptAssignees.length)} assignee${
LoggerService.white('├──'),
`Found ${LoggerService.cyan(exemptAssignees.length)} assignee${
exemptAssignees.length > 1 ? 's' : ''
} that can exempt stale on this $$type`
);
@@ -67,13 +67,13 @@ export class Assignees {
if (!hasExemptAssignee) {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
'No assignee on this $$type can exempt the stale process'
);
this._logSkip();
} else {
this._issueLogger.info(
chalk.white('└──'),
LoggerService.white('└──'),
'Skipping this $$type because it has an exempt assignee'
);
}
@@ -90,7 +90,7 @@ export class Assignees {
private _getExemptIssueAssignees(): string[] {
if (this._options.exemptIssueAssignees === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
@@ -98,7 +98,7 @@ export class Assignees {
if (this._options.exemptAssignees === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
@@ -112,10 +112,10 @@ export class Assignees {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is set. ${chalk.cyan(exemptAssignees.length)} assignee${
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -128,10 +128,10 @@ export class Assignees {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueAssignees
)} is set. ${chalk.cyan(exemptAssignees.length)} assignee${
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -142,7 +142,7 @@ export class Assignees {
private _getExemptPullRequestAssignees(): string[] {
if (this._options.exemptPrAssignees === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
@@ -150,7 +150,7 @@ export class Assignees {
if (this._options.exemptAssignees === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
@@ -164,10 +164,10 @@ export class Assignees {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is set. ${chalk.cyan(exemptAssignees.length)} assignee${
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -180,10 +180,10 @@ export class Assignees {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrAssignees
)} is set. ${chalk.cyan(exemptAssignees.length)} assignee${
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -201,7 +201,7 @@ export class Assignees {
if (isSameAssignee) {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`@${issueAssignee.login} is assigned on this $$type and is an exempt assignee`
);
}
@@ -282,6 +282,9 @@ export class Assignees {
}
private _logSkip(): void {
this._issueLogger.info(chalk.white('└──'), 'Skip the assignees checks');
this._issueLogger.info(
LoggerService.white('└──'),
'Skip the assignees checks'
);
}
}

View File

@@ -38,8 +38,6 @@ describe('Issue', (): void => {
removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined,
repoToken: '',
skipStaleIssueMessage: false,
skipStalePrMessage: false,
staleIssueMessage: '',
stalePrMessage: '',
startDate: undefined,
@@ -57,7 +55,9 @@ describe('Issue', (): void => {
exemptAllAssignees: false,
exemptAllIssueAssignees: undefined,
exemptAllPrAssignees: undefined,
enableStatistics: false
enableStatistics: false,
labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: ''
};
issueInterface = {
title: 'dummy-title',

File diff suppressed because it is too large Load Diff

View File

@@ -26,12 +26,17 @@ describe('IssueLogger', (): void => {
});
it('should log a warning with the given message and with the issue number as prefix', (): void => {
expect.assertions(2);
expect.assertions(3);
issueLogger.warning(message);
expect(coreWarningSpy).toHaveBeenCalledTimes(1);
expect(coreWarningSpy).toHaveBeenCalledWith('[#8] dummy-message');
expect(coreWarningSpy).toHaveBeenCalledWith(
expect.stringContaining('[#8]')
);
expect(coreWarningSpy).toHaveBeenCalledWith(
expect.stringContaining('dummy-message')
);
});
});
@@ -52,12 +57,15 @@ describe('IssueLogger', (): void => {
});
it('should log an information with the given message and with the issue number as prefix', (): void => {
expect.assertions(2);
expect.assertions(3);
issueLogger.info(message);
expect(coreInfoSpy).toHaveBeenCalledTimes(1);
expect(coreInfoSpy).toHaveBeenCalledWith('[#8] dummy-message');
expect(coreInfoSpy).toHaveBeenCalledWith(expect.stringContaining('[#8]'));
expect(coreInfoSpy).toHaveBeenCalledWith(
expect.stringContaining('dummy-message')
);
});
});
@@ -78,17 +86,22 @@ describe('IssueLogger', (): void => {
});
it('should log an error with the given message and with the issue number as prefix', (): void => {
expect.assertions(2);
expect.assertions(3);
issueLogger.error(message);
expect(coreErrorSpy).toHaveBeenCalledTimes(1);
expect(coreErrorSpy).toHaveBeenCalledWith('[#8] dummy-message');
expect(coreErrorSpy).toHaveBeenCalledWith(
expect.stringContaining('[#8]')
);
expect(coreErrorSpy).toHaveBeenCalledWith(
expect.stringContaining('dummy-message')
);
});
});
it('should prefix the message with the issue number', (): void => {
expect.assertions(2);
expect.assertions(3);
message = 'dummy-message';
issue = new Issue(
DefaultProcessorOptions,
@@ -102,7 +115,12 @@ describe('IssueLogger', (): void => {
issueLogger.warning(message);
expect(coreWarningSpy).toHaveBeenCalledTimes(1);
expect(coreWarningSpy).toHaveBeenCalledWith('[#123] dummy-message');
expect(coreWarningSpy).toHaveBeenCalledWith(
expect.stringContaining('[#123]')
);
expect(coreWarningSpy).toHaveBeenCalledWith(
expect.stringContaining('dummy-message')
);
});
it.each`
@@ -114,7 +132,7 @@ describe('IssueLogger', (): void => {
`(
'should replace the special tokens "$$type" with the corresponding type',
({pull_request, replacement}): void => {
expect.assertions(2);
expect.assertions(3);
message = 'The $$type will stale! $$type will soon be closed!';
issue = new Issue(
DefaultProcessorOptions,
@@ -130,7 +148,12 @@ describe('IssueLogger', (): void => {
expect(coreWarningSpy).toHaveBeenCalledTimes(1);
expect(coreWarningSpy).toHaveBeenCalledWith(
`[#8] The ${replacement} will stale! ${replacement} will soon be closed!`
expect.stringContaining(`[#8]`)
);
expect(coreWarningSpy).toHaveBeenCalledWith(
expect.stringContaining(
`The ${replacement} will stale! ${replacement} will soon be closed!`
)
);
}
);
@@ -144,7 +167,7 @@ describe('IssueLogger', (): void => {
`(
'should replace the special token "$$type" with the corresponding type with first letter as uppercase',
({pull_request, replacement}): void => {
expect.assertions(2);
expect.assertions(3);
message = '$$type will stale';
issue = new Issue(
DefaultProcessorOptions,
@@ -160,7 +183,10 @@ describe('IssueLogger', (): void => {
expect(coreWarningSpy).toHaveBeenCalledTimes(1);
expect(coreWarningSpy).toHaveBeenCalledWith(
`[#8] ${replacement} will stale`
expect.stringContaining(`[#8]`)
);
expect(coreWarningSpy).toHaveBeenCalledWith(
expect.stringContaining(`${replacement} will stale`)
);
}
);

View File

@@ -1,6 +1,6 @@
import chalk from 'chalk';
import {Issue} from '../issue';
import {Logger} from './logger';
import {LoggerService} from '../../services/logger.service';
/**
* @description
@@ -35,6 +35,10 @@ export class IssueLogger extends Logger {
super.error(this._format(...message));
}
async grouping(message: string, fn: () => Promise<void>): Promise<void> {
return super.grouping(this._format(message), fn);
}
private _replaceTokens(message: Readonly<string>): string {
return this._replaceTypeToken(message);
}
@@ -70,10 +74,10 @@ export class IssueLogger extends Logger {
}
private _getIssuePrefix(): string {
return chalk.red(`[#${this._getIssueNumber()}]`);
return LoggerService.red(`[#${this._getIssueNumber()}]`);
}
private _getPullRequestPrefix(): string {
return chalk.blue(`[#${this._getIssueNumber()}]`);
return LoggerService.blue(`[#${this._getIssueNumber()}]`);
}
}

View File

@@ -25,7 +25,9 @@ describe('Logger', (): void => {
logger.warning(message);
expect(coreWarningSpy).toHaveBeenCalledTimes(1);
expect(coreWarningSpy).toHaveBeenCalledWith('dummy-message');
expect(coreWarningSpy).toHaveBeenCalledWith(
expect.stringContaining('dummy-message')
);
});
});
@@ -46,7 +48,9 @@ describe('Logger', (): void => {
logger.info(message);
expect(coreInfoSpy).toHaveBeenCalledTimes(1);
expect(coreInfoSpy).toHaveBeenCalledWith('dummy-message');
expect(coreInfoSpy).toHaveBeenCalledWith(
expect.stringContaining('dummy-message')
);
});
});
@@ -67,7 +71,9 @@ describe('Logger', (): void => {
logger.error(message);
expect(coreErrorSpy).toHaveBeenCalledTimes(1);
expect(coreErrorSpy).toHaveBeenCalledWith('dummy-message');
expect(coreErrorSpy).toHaveBeenCalledWith(
expect.stringContaining('dummy-message')
);
});
});
});

View File

@@ -1,19 +1,23 @@
import * as core from '@actions/core';
import chalk from 'chalk';
import terminalLink from 'terminal-link';
import {Option} from '../../enums/option';
import {LoggerService} from '../../services/logger.service';
export class Logger {
warning(...message: string[]): void {
core.warning(chalk.whiteBright(...message));
core.warning(LoggerService.whiteBright(message.join(' ')));
}
info(...message: string[]): void {
core.info(chalk.whiteBright(...message));
core.info(LoggerService.whiteBright(message.join(' ')));
}
error(...message: string[]): void {
core.error(chalk.whiteBright(...message));
core.error(LoggerService.whiteBright(message.join(' ')));
}
async grouping(message: string, fn: () => Promise<void>): Promise<void> {
return core.group(LoggerService.whiteBright(message), fn);
}
createLink(name: Readonly<string>, link: Readonly<string>): string {
@@ -21,7 +25,7 @@ export class Logger {
}
createOptionLink(option: Readonly<Option>): string {
return chalk.magenta(
return LoggerService.magenta(
this.createLink(option, `https://github.com/actions/stale#${option}`)
);
}

View File

@@ -1,10 +1,10 @@
import chalk from 'chalk';
import deburr from 'lodash.deburr';
import {Option} from '../enums/option';
import {wordsToList} from '../functions/words-to-list';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
import {LoggerService} from '../services/logger.service';
type CleanMilestone = string;
@@ -33,7 +33,7 @@ export class Milestones {
if (this._shouldExemptAllMilestones()) {
this._issueLogger.info(
chalk.white('└──'),
LoggerService.white('└──'),
'Skipping this $$type because it has a milestone'
);
@@ -44,7 +44,7 @@ export class Milestones {
if (exemptMilestones.length === 0) {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`No milestone option was specified to skip the stale process for this $$type`
);
this._logSkip();
@@ -53,8 +53,8 @@ export class Milestones {
}
this._issueLogger.info(
chalk.white('├──'),
`Found ${chalk.cyan(exemptMilestones.length)} milestone${
LoggerService.white('├──'),
`Found ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length > 1 ? 's' : ''
} that can exempt stale on this $$type`
);
@@ -66,13 +66,13 @@ export class Milestones {
if (!hasExemptMilestone) {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
'No milestone on this $$type can exempt the stale process'
);
this._logSkip();
} else {
this._issueLogger.info(
chalk.white('└──'),
LoggerService.white('└──'),
'Skipping this $$type because it has an exempt milestone'
);
}
@@ -89,7 +89,7 @@ export class Milestones {
private _getExemptIssueMilestones(): string[] {
if (this._options.exemptIssueMilestones === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
@@ -97,7 +97,7 @@ export class Milestones {
if (this._options.exemptMilestones === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
@@ -111,10 +111,10 @@ export class Milestones {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is set. ${chalk.cyan(exemptMilestones.length)} milestone${
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -127,10 +127,10 @@ export class Milestones {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueMilestones
)} is set. ${chalk.cyan(exemptMilestones.length)} milestone${
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -141,7 +141,7 @@ export class Milestones {
private _getExemptPullRequestMilestones(): string[] {
if (this._options.exemptPrMilestones === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
@@ -149,7 +149,7 @@ export class Milestones {
if (this._options.exemptMilestones === '') {
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
@@ -163,10 +163,10 @@ export class Milestones {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is set. ${chalk.cyan(exemptMilestones.length)} milestone${
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -179,10 +179,10 @@ export class Milestones {
);
this._issueLogger.info(
chalk.white('├──'),
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrMilestones
)} is set. ${chalk.cyan(exemptMilestones.length)} milestone${
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -195,9 +195,8 @@ export class Milestones {
return false;
}
const cleanMilestone: CleanMilestone = Milestones._cleanMilestone(
milestone
);
const cleanMilestone: CleanMilestone =
Milestones._cleanMilestone(milestone);
const isSameMilestone: boolean =
cleanMilestone ===
@@ -205,8 +204,10 @@ export class Milestones {
if (isSameMilestone) {
this._issueLogger.info(
chalk.white('├──'),
`The milestone "${milestone}" is set on this $$type and is an exempt milestone`
LoggerService.white('├──'),
`The milestone "${LoggerService.cyan(
milestone
)}" is set on this $$type and is an exempt milestone`
);
}
@@ -288,6 +289,9 @@ export class Milestones {
}
private _logSkip(): void {
this._issueLogger.info(chalk.white('└──'), 'Skip the milestones checks');
this._issueLogger.info(
LoggerService.white('└──'),
'Skip the milestones checks'
);
}
}

View File

@@ -1,6 +1,6 @@
import chalk from 'chalk';
import {Issue} from './issue';
import {Logger} from './loggers/logger';
import {LoggerService} from '../services/logger.service';
interface IGroupValue {
name: string;
@@ -65,8 +65,8 @@ export class Statistics {
return this._incrementUndoStaleIssuesCount(increment);
}
setRemainingOperations(remainingOperations: Readonly<number>): Statistics {
this._operationsCount = remainingOperations;
setOperationsCount(operationsCount: Readonly<number>): Statistics {
this._operationsCount = operationsCount;
return this;
}
@@ -163,7 +163,7 @@ export class Statistics {
}
logStats(): Statistics {
this._logger.info(chalk.yellow.bold('Statistics:'));
this._logger.info(LoggerService.yellow(LoggerService.bold(`Statistics:`)));
this._logProcessedIssuesAndPullRequestsCount();
this._logStaleIssuesAndPullRequestsCount();
this._logUndoStaleIssuesAndPullRequestsCount();
@@ -440,7 +440,7 @@ export class Statistics {
private _logCount(name: Readonly<string>, count: Readonly<number>): void {
if (count > 0) {
this._logger.info(`${name}:`, chalk.cyan(count));
this._logger.info(`${name}:`, LoggerService.cyan(count));
}
}
@@ -498,7 +498,10 @@ export class Statistics {
const prefix = index === onlyValuesSet.length - 1 ? '└──' : '├──';
this._logCount(
`${chalk.white(prefix)} ${value.name.padEnd(longestValue, ' ')}`,
`${LoggerService.white(prefix)} ${value.name.padEnd(
longestValue,
' '
)}`,
value.count
);
}

View File

@@ -22,10 +22,10 @@ export enum Option {
AnyOfLabels = 'any-of-labels',
OperationsPerRun = 'operations-per-run',
RemoveStaleWhenUpdated = 'remove-stale-when-updated',
RemoveIssueStaleWhenUpdated = 'remove-issue-stale-when-updated',
RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated',
DebugOnly = 'debug-only',
Ascending = 'ascending',
SkipStaleIssueMessage = 'skip-stale-issue-message',
SkipStalePrMessage = 'skip-stale-pr-message',
DeleteBranch = 'delete-branch',
StartDate = 'start-date',
ExemptMilestones = 'exempt-milestones',
@@ -40,5 +40,7 @@ export enum Option {
ExemptAllAssignees = 'exempt-all-assignees',
ExemptAllIssueAssignees = 'exempt-all-issue-assignees',
ExemptAllPrAssignees = 'exempt-all-pr-assignees',
EnableStatistics = 'enable-statistics'
EnableStatistics = 'enable-statistics',
LabelsToRemoveWhenUnstale = 'labels-to-remove-when-unstale',
LabelsToAddWhenUnstale = 'labels-to-add-when-unstale'
}

View File

@@ -0,0 +1,14 @@
import deburr from 'lodash.deburr';
import { CleanLabel } from '../types/clean-label';
/**
* @description
* Clean a label by lowercasing it and deburring it for consistency
*
* @param {string} label A raw GitHub label
*
* @return {string} A lowercased, deburred version of the passed in label
*/
export function cleanLabel(label: Readonly<string>): CleanLabel {
return deburr(label.toLowerCase());
}

View File

@@ -7,9 +7,9 @@ describe('isLabeled()', (): void => {
describe('when the given issue contains no label', (): void => {
beforeEach((): void => {
issue = ({
issue = {
labels: []
} as unknown) as Issue;
} as unknown as Issue;
});
describe('when the given label is a simple label', (): void => {

View File

@@ -1,7 +1,6 @@
import deburr from 'lodash.deburr';
import {Issue} from '../classes/issue';
import {ILabel} from '../interfaces/label';
import {CleanLabel} from '../types/clean-label';
import {cleanLabel} from './clean-label';
/**
* @description
@@ -20,7 +19,3 @@ export function isLabeled(
return cleanLabel(label) === cleanLabel(issueLabel.name);
});
}
function cleanLabel(label: Readonly<string>): CleanLabel {
return deburr(label.toLowerCase());
}

View File

@@ -2,4 +2,5 @@ import {IUser} from './user';
export interface IComment {
user: IUser;
body: string;
}

View File

@@ -30,8 +30,6 @@ export interface IIssuesProcessorOptions {
removePrStaleWhenUpdated: boolean | undefined;
debugOnly: boolean;
ascending: boolean;
skipStaleIssueMessage: boolean;
skipStalePrMessage: boolean;
deleteBranch: boolean;
startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822
exemptMilestones: string;
@@ -47,4 +45,6 @@ export interface IIssuesProcessorOptions {
exemptAllIssueAssignees: boolean | undefined;
exemptAllPrAssignees: boolean | undefined;
enableStatistics: boolean;
labelsToRemoveWhenUnstale: string;
labelsToAddWhenUnstale: string;
}

View File

@@ -2,12 +2,19 @@ import * as core from '@actions/core';
import {IssuesProcessor} from './classes/issues-processor';
import {isValidDate} from './functions/dates/is-valid-date';
import {IIssuesProcessorOptions} from './interfaces/issues-processor-options';
import {Issue} from './classes/issue';
async function _run(): Promise<void> {
try {
const args = _getAndValidateArgs();
await new IssuesProcessor(args).processIssues();
const issueProcessor: IssuesProcessor = new IssuesProcessor(args);
await issueProcessor.processIssues();
await processOutput(
issueProcessor.staleIssues,
issueProcessor.closedIssues
);
} catch (error) {
core.error(error);
core.setFailed(error.message);
@@ -57,8 +64,6 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
),
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',
deleteBranch: core.getInput('delete-branch') === 'true',
startDate:
core.getInput('start-date') !== ''
@@ -76,7 +81,9 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
exemptAllAssignees: core.getInput('exempt-all-assignees') === 'true',
exemptAllIssueAssignees: _toOptionalBoolean('exempt-all-issue-assignees'),
exemptAllPrAssignees: _toOptionalBoolean('exempt-all-pr-assignees'),
enableStatistics: core.getInput('enable-statistics') === 'true'
enableStatistics: core.getInput('enable-statistics') === 'true',
labelsToRemoveWhenUnstale: core.getInput('labels-to-remove-when-unstale'),
labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale')
};
for (const numberInput of [
@@ -105,6 +112,14 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
return args;
}
async function processOutput(
staledIssues: Issue[],
closedIssues: Issue[]
): Promise<void> {
core.setOutput('staled-issues-prs', JSON.stringify(staledIssues));
core.setOutput('closed-issues-prs', JSON.stringify(closedIssues));
}
function _toOptionalBoolean(
argumentName: Readonly<string>
): boolean | undefined {

View File

@@ -0,0 +1,52 @@
import styles, {Modifier, ForegroundColor} from 'ansi-styles';
type Message = string | number | boolean;
export class LoggerService {
static whiteBright(message: Readonly<Message>): string {
return this._format(message, 'whiteBright');
}
static yellowBright(message: Readonly<Message>): string {
return this._format(message, 'yellowBright');
}
static magenta(message: Readonly<Message>): string {
return this._format(message, 'magenta');
}
static cyan(message: Readonly<Message>): string {
return this._format(message, 'cyan');
}
static yellow(message: Readonly<Message>): string {
return this._format(message, 'yellow');
}
static white(message: Readonly<Message>): string {
return this._format(message, 'white');
}
static green(message: Readonly<Message>): string {
return this._format(message, 'green');
}
static red(message: Readonly<Message>): string {
return this._format(message, 'red');
}
static blue(message: Readonly<Message>): string {
return this._format(message, 'blue');
}
static bold(message: Readonly<Message>): string {
return this._format(message, 'bold');
}
private static _format(
message: Readonly<Message>,
style: keyof Modifier | keyof ForegroundColor
): string {
return `${styles[style].open}${message}${styles[style].close}`;
}
}