Compare commits

..

71 Commits

Author SHA1 Message Date
Luke Tomlinson
9c1b1c6e11 Changelog 5.1.1 2022-07-27 16:17:02 -04:00
Luke Tomlinson
2b58cc900f Fix issue when days-before-close is more than days-before-stale (#775) 2022-07-25 09:24:15 -04:00
Luke Tomlinson
532554b8a8 update Changelog 2022-07-15 09:08:35 -04:00
Zhongxiang Wang
aaab997cce fix(options): add missing close-issue-reason option (#772) 2022-07-11 13:49:18 -04:00
timsu92
136efb520f docs: update example with new version of stale (#765) 2022-06-24 10:09:05 -04:00
Jacob Bandes-Storch
06d2a3904b Add close-issue-reason option (#764)
* Add close-as-not-planned option

* update readme

* add to Option enum

* improve wording

* npm run pack

* updates from review

* fix tests and improve error message

* fix readme order
2022-06-23 17:43:36 -04:00
0x5c
29e800e1c8 Remove stale when updated without comment (#717)
The existing logic for `remove-stale-when-updated` only considers presence of
comments, ignoring the value of `issueHasUpdate`.

This commits fixes it so it follows the documented behaviour for that setting.

Fixes #715
2022-06-20 15:38:43 -04:00
dependabot[bot]
6b7f9717b7 build(deps): bump github/codeql-action from 1 to 2 (#760)
Bumps [github/codeql-action](https://github.com/github/codeql-action) from 1 to 2.
- [Release notes](https://github.com/github/codeql-action/releases)
- [Changelog](https://github.com/github/codeql-action/blob/main/CHANGELOG.md)
- [Commits](https://github.com/github/codeql-action/compare/v1...v2)

---
updated-dependencies:
- dependency-name: github/codeql-action
  dependency-type: direct:production
  update-type: version-update:semver-major
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-20 13:50:11 -04:00
Luke Tomlinson
6c298b192c Update CONTRIBUTING.md 2022-06-20 13:49:18 -04:00
Luke Tomlinson
c048b97ed3 Update CONTRIBUTING.md 2022-06-20 13:48:36 -04:00
dependabot[bot]
71b06d0194 build(deps): bump actions/upload-artifact from 2 to 3 (#762)
Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3.
- [Release notes](https://github.com/actions/upload-artifact/releases)
- [Commits](https://github.com/actions/upload-artifact/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/upload-artifact
  dependency-type: direct:production
  update-type: version-update:semver-major
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-20 13:44:43 -04:00
dependabot[bot]
7bb514d8f8 build(deps): bump actions/checkout from 2 to 3 (#763)
Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3.
- [Release notes](https://github.com/actions/checkout/releases)
- [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md)
- [Commits](https://github.com/actions/checkout/compare/v2...v3)

---
updated-dependencies:
- dependency-name: actions/checkout
  dependency-type: direct:production
  update-type: version-update:semver-major
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-20 13:43:45 -04:00
Adam Stachowicz
a78f1809b1 Fix spaces in issues-processor.ts (#748)
* Fix spaces in `issues-processor.ts`

* `npm run build` and `npm run pack`
2022-06-20 13:43:08 -04:00
Cory Miller
e577b690d3 Merge pull request #733 from flaxel/main
🔧  Add GitHub Actions Dependabot
2022-06-20 13:22:54 -04:00
Cory Miller
736a97ebc6 Merge branch 'main' into main 2022-06-20 13:19:34 -04:00
Parker Brown
b9ccbf0648 Change NPM version update interval (daily → weekly)
Checking daily results in a lot of closed PRs because new PRs supersede them before they are reviewed and merged.
2022-06-20 13:03:36 -04:00
Falk Puschner
69c1cc9976 🚨 fix lint issue 2022-06-13 21:47:14 +02:00
Falk Puschner
8c947ce781 🎨 change interval
Co-authored-by: Parker Brown <17183625+parkerbxyz@users.noreply.github.com>
2022-06-13 21:44:08 +02:00
Falk Puschner
4b36ad56cb 💚 run prettier 2022-05-11 13:00:09 +02:00
Falk Puschner
64112b01cc 🎨 fix yaml 2022-05-11 12:38:17 +02:00
Falk Puschner
d693f556ca 🎨 improve dependabot 2022-05-11 12:36:54 +02:00
Luke Tomlinson
65d24b7092 Don't process a stale issue in the same run it's marked stale (#696) 2022-04-29 10:07:39 -04:00
dependabot[bot]
57708ae6dd build(deps): bump ajv from 6.12.0 to 6.12.6 (#675)
Bumps [ajv](https://github.com/ajv-validator/ajv) from 6.12.0 to 6.12.6.
- [Release notes](https://github.com/ajv-validator/ajv/releases)
- [Commits](https://github.com/ajv-validator/ajv/compare/v6.12.0...v6.12.6)

---
updated-dependencies:
- dependency-name: ajv
  dependency-type: indirect
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-31 15:43:31 -04:00
Luke Tomlinson
a88f7b30b9 Update @actions/github to 5.0.1 (#707)
* Update github package

* Update dist

* Use @actions/github@5.0.1

* Cleanup

* More cleanup
2022-03-31 15:38:16 -04:00
dependabot[bot]
74dfff0835 build(deps): bump minimist from 1.2.5 to 1.2.6 (#700)
Bumps [minimist](https://github.com/substack/minimist) from 1.2.5 to 1.2.6.
- [Release notes](https://github.com/substack/minimist/releases)
- [Commits](https://github.com/substack/minimist/compare/1.2.5...1.2.6)

---
updated-dependencies:
- dependency-name: minimist
  dependency-type: indirect
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-03-30 09:18:49 -04:00
Thomas Boop
3cc1237663 Merge pull request #670 from actions/thboop/node16upgrade
Update default runtime to node16
2022-02-28 16:18:50 -05:00
Thomas Boop
76e9fbc6ae update node version 2022-02-10 14:40:59 -05:00
Thomas Boop
6467b96231 Update default runtime to node16
Node 12 has an end of life on April 30, 2022.

This PR updates the default runtime to [node16](https://github.blog/changelog/2021-12-10-github-actions-github-hosted-runners-now-run-node-js-16-by-default/), rather then node12. 

This is supported on all Actions Runners v2.285.0 or later.
2022-02-07 14:05:30 -05:00
dependabot[bot]
8af60513da build(deps-dev): bump jest-circus from 27.2.0 to 27.4.6 (#665)
Bumps [jest-circus](https://github.com/facebook/jest/tree/HEAD/packages/jest-circus) from 27.2.0 to 27.4.6.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/commits/v27.4.6/packages/jest-circus)

---
updated-dependencies:
- dependency-name: jest-circus
  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>
2022-02-04 09:55:05 -05:00
m.bell
7a7efcae1f Fix per issue operation count (#662)
* Fix per issue operation count

* Run pack
2022-02-04 09:54:35 -05:00
dependabot[bot]
04a1828bc1 build(deps-dev): bump ts-jest from 27.0.5 to 27.1.2 (#641)
Bumps [ts-jest](https://github.com/kulshekhar/ts-jest) from 27.0.5 to 27.1.2.
- [Release notes](https://github.com/kulshekhar/ts-jest/releases)
- [Changelog](https://github.com/kulshekhar/ts-jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/kulshekhar/ts-jest/compare/v27.0.5...v27.1.2)

---
updated-dependencies:
- dependency-name: ts-jest
  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-12-29 19:52:14 +03:00
dependabot[bot]
65ca3956bd build(deps-dev): bump eslint-plugin-jest from 24.4.2 to 25.3.2 (#639)
Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 24.4.2 to 25.3.2.
- [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases)
- [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v24.4.2...v25.3.2)

---
updated-dependencies:
- dependency-name: eslint-plugin-jest
  dependency-type: direct:development
  update-type: version-update:semver-major
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-12-29 16:55:51 +03:00
dependabot[bot]
eee276c280 build(deps-dev): bump prettier from 2.4.1 to 2.5.1 (#628)
Bumps [prettier](https://github.com/prettier/prettier) from 2.4.1 to 2.5.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.4.1...2.5.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-12-29 14:23:59 +03:00
MaksimZhukov
6c2f9f3f54 Merge pull request #640 from dmitry-shibanov/v-dmshib/fix-check-dist
Fix check-dist.yml
2021-12-29 13:36:23 +03:00
Dmitry Shibanov
37323f14dd fix check-dist.yml 2021-12-29 12:56:54 +03:00
Luke Tomlinson
3be940e59b Merge pull request #627 from actions/prep-release
Bump release to 4.1.0
2021-12-10 15:00:13 -05:00
Luke Tomlinson
7d0e5bedbf Fix formatting check 2021-12-10 14:54:39 -05:00
Luke Tomlinson
77bfb89501 Update changelog 2021-12-10 14:42:33 -05:00
Luke Tomlinson
7fb802b307 Bump release to 4.1.0 2021-12-10 14:28:19 -05:00
Luke Tomlinson
54197c7137 Merge pull request #602 from actions/revert-breaking-change
Revert "Merge pull request #586 from C0ZEN/feature/split-pr-and-issue…
2021-10-20 09:40:28 -04:00
Luke Tomlinson
3a971aeb80 Revert "Merge pull request #586 from C0ZEN/feature/split-pr-and-issue-options"
This reverts commit db699ab3b1, reversing
changes made to b83d488cb9.
2021-10-20 09:25:24 -04:00
Luke Tomlinson
fc4a5ff942 Merge pull request #595 from actions/dependabot/npm_and_yarn/types/jest-27.0.2
build(deps-dev): bump @types/jest from 27.0.1 to 27.0.2
2021-10-19 13:31:19 -04:00
Luke Tomlinson
db699ab3b1 Merge pull request #586 from C0ZEN/feature/split-pr-and-issue-options
feat(options): remove common options between the issues and PRs
2021-10-19 13:30:46 -04:00
dependabot[bot]
f8e08de81b build(deps-dev): bump @types/jest from 27.0.1 to 27.0.2
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 27.0.1 to 27.0.2.
- [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>
2021-10-14 11:02:03 +00:00
Luke Tomlinson
b83d488cb9 Update dependencies (#592) 2021-10-13 11:42:09 -04:00
dependabot[bot]
1ff6cd74cb build(deps): bump tmpl from 1.0.4 to 1.0.5 (#575)
Bumps [tmpl](https://github.com/daaku/nodejs-tmpl) from 1.0.4 to 1.0.5.
- [Release notes](https://github.com/daaku/nodejs-tmpl/releases)
- [Commits](https://github.com/daaku/nodejs-tmpl/commits/v1.0.5)

---
updated-dependencies:
- dependency-name: tmpl
  dependency-type: indirect
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-10-13 09:02:38 -04:00
dependabot[bot]
86fed0e1f1 build(deps-dev): bump jest-silent-reporter from 0.4.0 to 0.5.0 (#573)
Bumps [jest-silent-reporter](https://github.com/rickhanlonii/jest-silent-reporter) from 0.4.0 to 0.5.0.
- [Release notes](https://github.com/rickhanlonii/jest-silent-reporter/releases)
- [Commits](https://github.com/rickhanlonii/jest-silent-reporter/compare/0.4.0...0.5.0)

---
updated-dependencies:
- dependency-name: jest-silent-reporter
  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-10-13 09:02:17 -04:00
TESTELIN Geoffrey
67004407a6 docs(readme): split the options between common, issues and prs 2021-10-08 22:42:12 +02:00
TESTELIN Geoffrey
b9a40762bf feat: remove the remove-stale-when-updated option
BREAKING CHANGE:
The option remove-stale-when-updated was removed
2021-10-08 21:30:39 +02:00
TESTELIN Geoffrey
bab816b473 feat: remove the days-before-stale option
BREAKING CHANGE:
The option days-before-stale was removed
2021-10-08 21:06:12 +02:00
TESTELIN Geoffrey
6299c36a0d feat: remove the only-labels option
BREAKING CHANGE:
The option only-labels was removed
2021-10-08 20:39:44 +02:00
TESTELIN Geoffrey
a8c5bb1c29 feat: remove the only-labels option
BREAKING CHANGE:
The option only-labels was removed
2021-10-08 20:26:58 +02:00
TESTELIN Geoffrey
1c81c38e2f feat: remove the any-of-labels option
BREAKING CHANGE:
The option any-of-labels was removed
2021-10-08 20:18:01 +02:00
TESTELIN Geoffrey
f6a70aa856 feat: remove the exempt-milestones option
BREAKING CHANGE:
The option exempt-milestones was removed
2021-10-08 19:48:38 +02:00
TESTELIN Geoffrey
315391885d feat: remove the exempt-all-milestones option
BREAKING CHANGE:
The option exempt-all-milestones was removed
2021-10-08 19:19:07 +02:00
TESTELIN Geoffrey
4665995b65 feat: remove the exempt-assignees option
BREAKING CHANGE:
The option exempt-assignees was removed
2021-10-08 19:06:51 +02:00
TESTELIN Geoffrey
b80ae639fa feat: remove the exempt-all-assignees option
BREAKING CHANGE:
The option exempt-all-assignees was removed
2021-10-08 18:50:37 +02:00
TESTELIN Geoffrey
3021a55a47 feat: remove the ignore-updates option
BREAKING CHANGE:
The option ignore-updates was removed
2021-10-08 18:06:39 +02:00
Geoffrey Testelin
b98591d49e docs(stale-issue-comment): update the docs to remove that omitting the option will not send a message (#522)
* chore(assignees): add logs

* docs(stale-issue-comment): update the docs to remove that omitting will not send a message

To be sure, what would be even better is to add a test using the default config (because the main issue is that the default options of the specs are not matching the ones from the action).

Closes #521

* test(comment): add more coverage to test the stale issue message

* docs(readme): improve the wording

Co-authored-by: Luke Tomlinson <luketomlinson@github.com>

* refactor: simplify the code to use the stats for the specs

* chore(rebase): fix rebase issue

* chore(statistics): fix issue due to rebase

Co-authored-by: Luke Tomlinson <luketomlinson@github.com>
2021-09-22 09:18:19 -04:00
Geoffrey Testelin
9912fa74d1 feat(draft-pr): add new option to not process PRs which are in draft (#539)
* chore(assignees): add logs

* feat(draft-pr): add new option to not process PRs which are in draft

* refactor(draft-pr): create a dedicated class to handle the logic

* chore(index): update index file
2021-09-20 09:37:32 -04:00
dependabot[bot]
303465a5d2 build(deps-dev): bump eslint-plugin-jest from 24.3.6 to 24.4.2 (#570)
Bumps [eslint-plugin-jest](https://github.com/jest-community/eslint-plugin-jest) from 24.3.6 to 24.4.2.
- [Release notes](https://github.com/jest-community/eslint-plugin-jest/releases)
- [Changelog](https://github.com/jest-community/eslint-plugin-jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/jest-community/eslint-plugin-jest/compare/v24.3.6...v24.4.2)

---
updated-dependencies:
- dependency-name: eslint-plugin-jest
  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-09-17 14:24:25 -04:00
JamieDanielson
dee9af8160 Fix ISO format on start-date in README (#562) 2021-09-17 14:23:49 -04:00
dependabot[bot]
31d06d7a0a build(deps-dev): bump prettier from 2.3.1 to 2.4.1 (#568)
Bumps [prettier](https://github.com/prettier/prettier) from 2.3.1 to 2.4.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.3.1...2.4.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-09-17 14:16:45 -04:00
dependabot[bot]
fcb25faea2 build(deps-dev): bump @typescript-eslint/parser from 4.26.1 to 4.31.1 (#567)
Bumps [@typescript-eslint/parser](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/parser) from 4.26.1 to 4.31.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.31.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-09-17 14:16:29 -04:00
dependabot[bot]
9dee5c72d9 build(deps-dev): bump @typescript-eslint/eslint-plugin (#566)
Bumps [@typescript-eslint/eslint-plugin](https://github.com/typescript-eslint/typescript-eslint/tree/HEAD/packages/eslint-plugin) from 4.26.0 to 4.31.1.
- [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.31.1/packages/eslint-plugin)

---
updated-dependencies:
- dependency-name: "@typescript-eslint/eslint-plugin"
  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-09-17 09:57:08 -04:00
dependabot[bot]
0aa6030913 build(deps-dev): bump jest-circus from 26.6.3 to 27.2.0 (#565)
Bumps [jest-circus](https://github.com/facebook/jest/tree/HEAD/packages/jest-circus) from 26.6.3 to 27.2.0.
- [Release notes](https://github.com/facebook/jest/releases)
- [Changelog](https://github.com/facebook/jest/blob/main/CHANGELOG.md)
- [Commits](https://github.com/facebook/jest/commits/v27.2.0/packages/jest-circus)

---
updated-dependencies:
- dependency-name: jest-circus
  dependency-type: direct:development
  update-type: version-update:semver-major
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-17 09:56:55 -04:00
dependabot[bot]
5aa0d3ef84 build(deps-dev): bump @types/jest from 26.0.23 to 27.0.1 (#549)
Bumps [@types/jest](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/jest) from 26.0.23 to 27.0.1.
- [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-major
...

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

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2021-09-17 09:56:39 -04:00
Geoffrey Testelin
1cdda06bb3 feat(options): add new option ignore-updates to stale even with activity (#540)
* chore(assignees): add logs

* docs(readme): use the override syntax to simplify the reading

* docs(readme): add missing default options

* docs(readme): add 3 new options to ignore activity before stale

* chore(action): add 3 new options

* fix(removeStaleWhenUpdated): use the value of the action config as expected

Fixes #451

* chore(main): add 3 new options

* feat(ignore): add new class to ignore all activities before stale

* feat(option): add new options to ignore all activities before stale

* chore(index): update index file

* docs(readme): fix typo

* docs(readme): add missing empty row

* chore(rebase): fix logger issues due to rebase

* chore: aplly changes due to rebase

* refactor(naming): change the name of the options as suggested

* chore(logs): reverse the logs as well

* docs(readme): format the table of options

* refactor(naming): rename the the options

* style(rename): rename more updates wording to activities

* build(ci): run the test step as expected for a CI

instead of using a real linter with auto fix and the tests verbose as fuck

* chore: handle breaking changes due to new changes

* refactor(naming): rename and reverse the options

* style(tests): use plural for some describe

* docs(days-before-stale): list the new option

* chore(index): update index file

* chore: keep static methods on top

* chore(logs): remove useless log
2021-09-17 09:54:38 -04:00
Marko Kungla
002bc97450 add missing inputs to action.yml closes #551 (#554) 2021-09-14 10:13:17 -04:00
Falk Puschner
2e221262b1 docs(readme): add branch hint (#532)
* docs(readme): add branch hint

* using english words

Co-authored-by: Luke Tomlinson <luketomlinson@github.com>

Co-authored-by: Luke Tomlinson <luketomlinson@github.com>
2021-09-08 13:40:19 -04:00
Brian Cristante
27d80e173f Create check-dist.yml (#553)
* Add check-dist.yml

* Fix triggers in licensed.yml

* Remove licensed.yml
2021-09-08 13:39:27 -04:00
39 changed files with 9167 additions and 7560 deletions

View File

@@ -4,6 +4,11 @@ updates:
- package-ecosystem: 'npm' - package-ecosystem: 'npm'
# Look for `package.json` and `lock` files in the `root` directory # Look for `package.json` and `lock` files in the `root` directory
directory: '/' directory: '/'
# Check the npm registry for updates every day (weekdays) # Check the npm registry for updates once a week (Monday)
schedule: schedule:
interval: 'daily' interval: 'weekly'
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'

53
.github/workflows/check-dist.yml vendored Normal file
View File

@@ -0,0 +1,53 @@
# `dist/index.js` is a special file in Actions.
# When you reference an action with `uses:` in a workflow,
# `index.js` is the code that will run.
# For our project, we generate this file through a build process from other source files.
# We need to make sure the checked-in `index.js` actually matches what we expect it to be.
name: Check dist/
on:
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:
jobs:
check-dist:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: 16.x
- name: Install dependencies
run: npm ci
- name: Rebuild the dist/ directory
run: |
npm run build
npm run pack
- name: Compare the expected and actual dist/ directories
run: |
if [ "$(git diff --ignore-space-at-eol dist/ | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi
id: diff
# If index.js was different than expected, upload the expected version as an artifact
- uses: actions/upload-artifact@v3
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
with:
name: dist
path: dist/

View File

@@ -13,13 +13,13 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Checkout repository - name: Checkout repository
uses: actions/checkout@v2 uses: actions/checkout@v3
- name: Initialize CodeQL - name: Initialize CodeQL
uses: github/codeql-action/init@v1 uses: github/codeql-action/init@v2
- name: Autobuild - name: Autobuild
uses: github/codeql-action/autobuild@v1 uses: github/codeql-action/autobuild@v2
- name: Perform CodeQL Analysis - name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1 uses: github/codeql-action/analyze@v2

View File

@@ -10,14 +10,14 @@ jobs:
build: # make sure build/ci work properly build: # make sure build/ci work properly
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- run: | - run: |
npm ci npm ci
npm run all npm run all:ci
test: # make sure the action works on a clean machine without building test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v3
- uses: ./ - uses: ./
id: stale id: stale
with: with:

View File

@@ -1,24 +1,37 @@
# Changelog # Changelog
Starting in version 4.0.0 we will maintain a changelog
# [5.1.1]
[Fix issue when days-before-close is more than days-before-stale](https://github.com/actions/stale/pull/775)
# [5.1.0]
[Don't process stale issues right after they're marked stale](https://github.com/actions/stale/issues/696)
[Add close-issue-reason option][#764](https://github.com/actions/stale/pull/764)[#772](https://github.com/actions/stale/pull/772)
Various dependabot/dependency updates
## [4.1.0](https://github.com/actions/stale/compare/v3.0.19...v4.1.0) (2021-07-14)
## Features
- [Ability to exempt draft PRs](https://github.com/actions/stale/commit/9912fa74d1c01b5d6187793d97441019cbe325d0)
## [4.0.0](https://github.com/actions/stale/compare/v3.0.19...v4.0.0) (2021-07-14) ## [4.0.0](https://github.com/actions/stale/compare/v3.0.19...v4.0.0) (2021-07-14)
### Features ### 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) - **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)) - **output:** print output parameters ([#458](https://github.com/actions/stale/issues/458)) ([3e6d35b](https://github.com/actions/stale/commit/3e6d35b685f0b2fa1a69be893fa07d3d85e05ee0))
### Bug Fixes ### 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) - **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)) - **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) - **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) - **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) - **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 ### 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 `true`. - 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 `true`.
* 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. - 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

@@ -46,6 +46,13 @@ Build, lint, package and test everything.
$ npm run all $ npm run all
``` ```
IMPORTANT:
Be sure to commit the result of:
```bash
$ npm run pack
```
Otherwise PR checks will fail.
# Release # Release
Based on [standard-version](https://github.com/conventional-changelog/standard-version). Based on [standard-version](https://github.com/conventional-changelog/standard-version).

181
README.md
View File

@@ -2,9 +2,9 @@
Warns and then closes issues and PRs that have had no activity for a specified amount of time. Warns and then closes issues and PRs that have had no activity for a specified amount of time.
The default configuration will: The configuration must be on the default branch and the default values will:
- Add a label "Stale" on issues and pull requests after 60 days of inactivity - Add a label "Stale" on issues and pull requests after 60 days of inactivity and comment on them
- Close the stale issues and pull requests after 7 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 - If an update/comment occur on stale issues or pull requests, the stale label will be removed and the timer will restart
@@ -28,61 +28,66 @@ You can find more information about the required permissions under the correspon
Every argument is optional. Every argument is optional.
| Input | Description | Default | | Input | Description | Default |
| ------------------------------------------------------------------- | ------------------------------------------------------------------------ | --------------------- | | ------------------------------------------------------------------- | --------------------------------------------------------------------------- | --------------------- |
| [repo-token](#repo-token) | PAT for GitHub API authentication | `${{ github.token }}` | | [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-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-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-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-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-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 | | | [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-issue-message](#stale-issue-message) | Comment on the staled issues | |
| [stale-pr-message](#stale-pr-message) | Comment on the staled PRs | | | [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-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 | | | [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` | | [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 | | | [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-issue-reason](#close-issue-reason) | Reason to use when closing issues | |
| [close-pr-label](#close-pr-label) | Label to apply on closed PRs | | | [stale-pr-label](#stale-pr-label) | Label to apply on staled PRs | `Stale` |
| [exempt-issue-labels](#exempt-issue-labels) | Labels on issues exempted from stale | | | [close-pr-label](#close-pr-label) | Label to apply on closed PRs | |
| [exempt-pr-labels](#exempt-pr-labels) | Labels on PRs exempted from stale | | | [exempt-issue-labels](#exempt-issue-labels) | Labels on issues exempted from stale | |
| [only-labels](#only-labels) | Only issues/PRs with ALL these labels are checked | | | [exempt-pr-labels](#exempt-pr-labels) | Labels on PRs exempted from stale | |
| [only-issue-labels](#only-issue-labels) | Only issues with ALL these labels are checked | | | [only-labels](#only-labels) | Only issues/PRs with ALL these labels are checked | |
| [only-pr-labels](#only-pr-labels) | Only PRs with ALL these labels are checked | | | [only-issue-labels](#only-issue-labels) | Override [only-labels](#only-labels) for issues only | |
| [any-of-labels](#any-of-labels) | Only issues/PRs with ANY of these labels are checked | | | [only-pr-labels](#only-pr-labels) | Override [only-labels](#only-labels) for PRs only | |
| [any-of-issue-labels](#any-of-issue-labels) | Only issues with ANY of these labels are checked | | | [any-of-labels](#any-of-labels) | Only issues/PRs with ANY of these labels are checked | |
| [any-of-pr-labels](#any-of-pr-labels) | Only PRs with ANY of these labels are checked | | | [any-of-issue-labels](#any-of-issue-labels) | Override [any-of-labels](#any-of-labels) for issues only | |
| [operations-per-run](#operations-per-run) | Max number of operations per run | `30` | | [any-of-pr-labels](#any-of-pr-labels) | Override [any-of-labels](#any-of-labels) for PRs only | |
| [remove-stale-when-updated](#remove-stale-when-updated) | Remove stale label from issues/PRs on updates/comments | `true` | | [operations-per-run](#operations-per-run) | Max number of operations per run | `30` |
| [remove-issue-stale-when-updated](#remove-issue-stale-when-updated) | Remove stale label from issues on updates/comments | | | [remove-stale-when-updated](#remove-stale-when-updated) | Remove stale label from issues/PRs on updates | `true` |
| [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | | | [remove-issue-stale-when-updated](#remove-issue-stale-when-updated) | Remove stale label from issues on updates/comments | |
| [labels-to-add-when-unstale](#labels-to-add-when-unstale) | Add specified labels from issues/PRs when they become unstale | | | [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | |
| [labels-to-remove-when-unstale](#labels-to-remove-when-unstale) | Remove specified labels from issues/PRs when they become unstale | | | [labels-to-add-when-unstale](#labels-to-add-when-unstale) | Add specified labels from issues/PRs when they become unstale | |
| [debug-only](#debug-only) | Dry-run | `false` | | [labels-to-remove-when-unstale](#labels-to-remove-when-unstale) | Remove specified labels from issues/PRs when they become unstale | |
| [ascending](#ascending) | Order to get issues/PRs | `false` | | [debug-only](#debug-only) | Dry-run | `false` |
| [start-date](#start-date) | Skip stale action for issues/PRs created before it | | | [ascending](#ascending) | Order to get issues/PRs | `false` |
| [delete-branch](#delete-branch) | Delete branch after closing a stale PR | `false` | | [start-date](#start-date) | Skip stale action for issues/PRs created before it | |
| [exempt-milestones](#exempt-milestones) | Milestones on issues/PRs exempted from stale | | | [delete-branch](#delete-branch) | Delete branch after closing a stale PR | `false` |
| [exempt-issue-milestones](#exempt-issue-milestones) | Override [exempt-milestones](#exempt-milestones) for issues only | | | [exempt-milestones](#exempt-milestones) | Milestones on issues/PRs exempted from stale | |
| [exempt-pr-milestones](#exempt-pr-milestones) | Override [exempt-milestones](#exempt-milestones) for PRs only | | | [exempt-issue-milestones](#exempt-issue-milestones) | Override [exempt-milestones](#exempt-milestones) for issues only | |
| [exempt-all-milestones](#exempt-all-milestones) | Exempt all issues/PRs with milestones from stale | | | [exempt-pr-milestones](#exempt-pr-milestones) | Override [exempt-milestones](#exempt-milestones) for PRs only | |
| [exempt-all-issue-milestones](#exempt-all-issue-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for issues only | | | [exempt-all-milestones](#exempt-all-milestones) | Exempt all issues/PRs with milestones from stale | `false` |
| [exempt-all-pr-milestones](#exempt-all-pr-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for PRs only | | | [exempt-all-issue-milestones](#exempt-all-issue-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for issues only | |
| [exempt-assignees](#exempt-assignees) | Assignees on issues/PRs exempted from stale | | | [exempt-all-pr-milestones](#exempt-all-pr-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for PRs only | |
| [exempt-issue-assignees](#exempt-issue-assignees) | Override [exempt-assignees](#exempt-assignees) for issues only | | | [exempt-assignees](#exempt-assignees) | Assignees on issues/PRs exempted from stale | |
| [exempt-pr-assignees](#exempt-pr-assignees) | Override [exempt-assignees](#exempt-assignees) for PRs only | | | [exempt-issue-assignees](#exempt-issue-assignees) | Override [exempt-assignees](#exempt-assignees) for issues only | |
| [exempt-all-assignees](#exempt-all-assignees) | Exempt all issues/PRs with assignees from stale | | | [exempt-pr-assignees](#exempt-pr-assignees) | Override [exempt-assignees](#exempt-assignees) for PRs only | |
| [exempt-all-issue-assignees](#exempt-all-issue-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for issues only | | | [exempt-all-assignees](#exempt-all-assignees) | Exempt all issues/PRs with assignees from stale | `false` |
| [exempt-all-pr-assignees](#exempt-all-pr-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for PRs only | | | [exempt-all-issue-assignees](#exempt-all-issue-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for issues only | |
| [enable-statistics](#enable-statistics) | Display statistics in the logs | `true` | | [exempt-all-pr-assignees](#exempt-all-pr-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for PRs only | |
| [exempt-draft-pr](#exempt-draft-pr) | Skip the stale action for draft PRs | `false` |
| [enable-statistics](#enable-statistics) | Display statistics in the logs | `true` |
| [ignore-updates](#ignore-updates) | Any update (update/comment) can reset the stale idle time on the issues/PRs | `false` |
| [ignore-issue-updates](#ignore-issue-updates) | Override [ignore-updates](#ignore-updates) for issues only | |
| [ignore-pr-updates](#ignore-pr-updates) | Override [ignore-updates](#ignore-updates) for PRs only | |
### List of output options ### List of output options
| Output | Description | | Output | Description |
| ----------------- | -------------------------------------------- | | ----------------- | ------------------------------------------- |
| staled-issues-prs | List of all staled issues and pull requests. | | staled-issues-prs | List of all staled issues and pull requests |
| closed-issues-prs | List of all closed issues and pull requests. | | closed-issues-prs | List of all closed issues and pull requests |
### Detailed options ### Detailed options
@@ -96,7 +101,9 @@ Default value: `${{ github.token }}`
#### days-before-stale #### days-before-stale
The idle number of days before marking the issues or the pull requests as stale (by adding a label). 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. 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.
It means that any updates made, or any comments added to the issues or to the pull requests will restart the counter of days before marking as stale.
However, if you wish to ignore this behaviour so that the creation date (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `created_at`) only matters, you can disable the [ignore-updates](#ignore-updates) option.
If set to a negative number like `-1`, no issues or pull requests will be marked as stale automatically. 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. In that case, you can still add the stale label manually to mark as stale.
@@ -122,6 +129,7 @@ You can fine tune which issues or pull requests should be marked as stale based
- [exempt-all-milestones](#exempt-all-milestones) - [exempt-all-milestones](#exempt-all-milestones)
- [exempt-assignees](#exempt-assignees) - [exempt-assignees](#exempt-assignees)
- [exempt-all-assignees](#exempt-all-assignees) - [exempt-all-assignees](#exempt-all-assignees)
- [ignore-updates](#ignore-updates)
Default value: `60` Default value: `60`
@@ -168,7 +176,7 @@ Default value: unset
The message that will be added as a comment to the issues when the stale workflow marks it automatically as stale with a label. 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. You can skip the comment sending by passing an empty string.
Default value: unset Default value: unset
Required Permission: `issues: write` Required Permission: `issues: write`
@@ -177,7 +185,7 @@ Required Permission: `issues: write`
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. 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. You can skip the comment sending by passing an empty string.
Default value: unset Default value: unset
Required Permission: `pull-requests: write` Required Permission: `pull-requests: write`
@@ -212,6 +220,12 @@ It will be automatically removed if the issues are no longer closed nor locked.
Default value: unset Default value: unset
Required Permission: `issues: write` Required Permission: `issues: write`
#### close-issue-reason
Specify the [reason](https://github.blog/changelog/2022-05-19-the-new-github-issues-may-19th-update/) used when closing issues. Valid values are `completed` and `not_planned`.
Default value: unset
#### stale-pr-label #### stale-pr-label
The label that will be added to the pull requests when automatically marked as stale. The label that will be added to the pull requests when automatically marked as stale.
@@ -466,6 +480,14 @@ Override [exempt-all-assignees](#exempt-all-assignees) but only to exempt the pu
Default value: unset Default value: unset
#### exempt-draft-pr
If set to `true`, the pull requests currently in draft will not be marked as stale automatically.
⚠️ This option consume one operation per pull request to process because we need to fetch the pull request with the GitHub API to know if it's a draft one or not.
Default value: `false`
Required Permission: `pull-requests: read`
#### enable-statistics #### enable-statistics
Collects and display statistics at the end of the stale workflow logs to get a summary of what happened during the run. Collects and display statistics at the end of the stale workflow logs to get a summary of what happened during the run.
@@ -473,6 +495,27 @@ This option is only useful if the debug output secret `ACTIONS_STEP_DEBUG` is se
Default value: `true` Default value: `true`
#### ignore-updates
The option [days-before-stale](#days-before-stale) will define the number of days before considering the issues or the pull requests as stale.
In most cases, the purpose of this action is to only stale when necessary so if any update occurs or if a comment is added to them, the counter will restart.
Nonetheless, if you don't care about this, and you prefer to stick to this number of days no matter the update, you can enable this option.
Instead of comparing the number of days based on the [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`, it will be based on the [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `created_at`.
Default value: `false`
#### ignore-issue-updates
Useful to override [ignore-updates](#ignore-updates) but only to ignore the updates for the issues.
Default value: unset
#### ignore-pr-updates
Useful to override [ignore-updates](#ignore-updates) but only to ignore the updates for the pull requests.
Default value: unset
### Usage ### Usage
See also [action.yml](./action.yml) for a comprehensive list of all the options. See also [action.yml](./action.yml) for a comprehensive list of all the options.
@@ -489,7 +532,7 @@ jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v4 - uses: actions/stale@v5
with: with:
stale-issue-message: 'Message to comment on stale issues. If none provided, will not mark issues stale' stale-issue-message: 'Message to comment on stale issues. If none provided, will not mark issues stale'
stale-pr-message: 'Message to comment on stale PRs. If none provided, will not mark PRs stale' stale-pr-message: 'Message to comment on stale PRs. If none provided, will not mark PRs stale'
@@ -507,7 +550,7 @@ jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v4 - uses: actions/stale@v5
with: with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.' 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-stale: 30
@@ -526,7 +569,7 @@ jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v4 - uses: actions/stale@v5
with: with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.' stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
stale-pr-message: 'This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.' stale-pr-message: 'This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.'
@@ -548,7 +591,7 @@ jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v4 - uses: actions/stale@v5
with: with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.' stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
stale-pr-message: 'This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.' stale-pr-message: 'This PR is stale because it has been open 45 days with no activity. Remove stale label or comment or this will be closed in 10 days.'
@@ -572,7 +615,7 @@ jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v4 - uses: actions/stale@v5
with: with:
stale-issue-message: 'Stale issue message' stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message' stale-pr-message: 'Stale pull request message'
@@ -595,9 +638,9 @@ jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v4 - uses: actions/stale@v5
with: with:
start-date: '2020-18-04T00:00:00Z' # ISO 8601 or RFC 2822 start-date: '2020-04-18T00:00:00Z' # ISO 8601 or RFC 2822
``` ```
Avoid stale for specific milestones: Avoid stale for specific milestones:
@@ -612,7 +655,7 @@ jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v4 - uses: actions/stale@v5
with: with:
exempt-issue-milestones: 'future,alpha,beta' exempt-issue-milestones: 'future,alpha,beta'
exempt-pr-milestones: 'bugfix,improvement' exempt-pr-milestones: 'bugfix,improvement'
@@ -630,7 +673,7 @@ jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v4 - uses: actions/stale@v5
with: with:
exempt-all-pr-milestones: true exempt-all-pr-milestones: true
``` ```
@@ -647,7 +690,7 @@ jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v4 - uses: actions/stale@v5
with: with:
any-of-labels: 'needs-more-info,needs-demo' any-of-labels: 'needs-more-info,needs-demo'
# You can opt for 'only-labels' instead if your use-case requires all labels # You can opt for 'only-labels' instead if your use-case requires all labels
@@ -666,7 +709,7 @@ jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v4 - uses: actions/stale@v5
with: with:
exempt-issue-assignees: 'marco,polo' exempt-issue-assignees: 'marco,polo'
exempt-pr-assignees: 'marco' exempt-pr-assignees: 'marco'
@@ -684,7 +727,7 @@ jobs:
stale: stale:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/stale@v4 - uses: actions/stale@v5
with: with:
exempt-all-pr-assignees: true exempt-all-pr-assignees: true
``` ```

View File

@@ -8,7 +8,7 @@ import {generateIssue} from './functions/generate-issue';
let issuesProcessorBuilder: IssuesProcessorBuilder; let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock; let issuesProcessor: IssuesProcessorMock;
describe('any-of-labels option', (): void => { describe('any-of-labels options', (): void => {
beforeEach((): void => { beforeEach((): void => {
issuesProcessorBuilder = new IssuesProcessorBuilder(); issuesProcessorBuilder = new IssuesProcessorBuilder();
}); });
@@ -1103,7 +1103,7 @@ class IssuesProcessorBuilder {
issue.updated_at ?? new Date().toDateString(), issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(), issue.created_at ?? new Date().toDateString(),
!!issue.pull_request, !!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name) : [] issue.labels ? issue.labels.map(label => label.name || '') : []
) )
); );

View File

@@ -2,19 +2,21 @@ import {Issue} from '../../src/classes/issue';
import {IssuesProcessor} from '../../src/classes/issues-processor'; import {IssuesProcessor} from '../../src/classes/issues-processor';
import {IComment} from '../../src/interfaces/comment'; import {IComment} from '../../src/interfaces/comment';
import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options'; import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options';
import {IPullRequest} from '../../src/interfaces/pull-request';
export class IssuesProcessorMock extends IssuesProcessor { export class IssuesProcessorMock extends IssuesProcessor {
constructor( constructor(
options: IIssuesProcessorOptions, options: IIssuesProcessorOptions,
getIssues?: (page: number) => Promise<Issue[]>, getIssues?: (page: number) => Promise<Issue[]>,
listIssueComments?: ( listIssueComments?: (
issueNumber: number, issue: Issue,
sinceDate: string sinceDate: string
) => Promise<IComment[]>, ) => Promise<IComment[]>,
getLabelCreationDate?: ( getLabelCreationDate?: (
issue: Issue, issue: Issue,
label: string label: string
) => Promise<string | undefined> ) => Promise<string | undefined>,
getPullRequest?: (issue: Issue) => Promise<IPullRequest | undefined | void>
) { ) {
super(options); super(options);
@@ -29,5 +31,9 @@ export class IssuesProcessorMock extends IssuesProcessor {
if (getLabelCreationDate) { if (getLabelCreationDate) {
this.getLabelCreationDate = getLabelCreationDate; this.getLabelCreationDate = getLabelCreationDate;
} }
if (getPullRequest) {
this.getPullRequest = getPullRequest;
}
} }
} }

View File

@@ -46,5 +46,10 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
exemptAllPrAssignees: undefined, exemptAllPrAssignees: undefined,
enableStatistics: true, enableStatistics: true,
labelsToRemoveWhenUnstale: '', labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: '' labelsToAddWhenUnstale: '',
ignoreUpdates: false,
ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined,
exemptDraftPr: false,
closeIssueReason: ''
}); });

View File

@@ -0,0 +1,139 @@
import {Issue} from '../src/classes/issue';
import {IIssue} from '../src/interfaces/issue';
import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options';
import {IPullRequest} from '../src/interfaces/pull-request';
import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue';
let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock;
describe('exempt-draft-pr option', (): void => {
beforeEach((): void => {
issuesProcessorBuilder = new IssuesProcessorBuilder();
});
describe('when the option "exempt-draft-pr" is disabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.processDraftPr();
});
test('should stale the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder
.toStalePrs([
{
number: 10
}
])
.build();
await issuesProcessor.processIssues();
expect(issuesProcessor.staleIssues).toHaveLength(1);
});
});
describe('when the option "exempt-draft-pr" is enabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.exemptDraftPr();
});
test('should not stale the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder
.toStalePrs([
{
number: 20
}
])
.build();
await issuesProcessor.processIssues();
expect(issuesProcessor.staleIssues).toHaveLength(0);
});
});
});
class IssuesProcessorBuilder {
private _options: IIssuesProcessorOptions = {
...DefaultProcessorOptions
};
private _issues: Issue[] = [];
processDraftPr(): IssuesProcessorBuilder {
this._options.exemptDraftPr = false;
return this;
}
exemptDraftPr(): IssuesProcessorBuilder {
this._options.exemptDraftPr = true;
return this;
}
issuesOrPrs(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this._issues = issues.map(
(issue: Readonly<Partial<IIssue>>, index: Readonly<number>): Issue =>
generateIssue(
this._options,
issue.number ?? index,
issue.title ?? 'dummy-title',
issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(),
!!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name || '') : []
)
);
return this;
}
prs(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: {key: 'value'}
};
})
);
return this;
}
toStalePrs(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'
};
})
);
return this;
}
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
async p => (p === 1 ? this._issues : []),
async () => [],
async () => new Date().toDateString(),
async (): Promise<IPullRequest> => {
return Promise.resolve({
number: 0,
draft: true,
head: {
ref: 'ref'
}
});
}
);
}
}

View File

@@ -1,5 +1,5 @@
import {Issue} from '../../src/classes/issue'; import {Issue} from '../../src/classes/issue';
import {IAssignee} from '../../src/interfaces/assignee'; import {IUserAssignee} from '../../src/interfaces/assignee';
import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options'; import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options';
import {IsoDateString} from '../../src/types/iso-date-string'; import {IsoDateString} from '../../src/types/iso-date-string';
@@ -32,9 +32,10 @@ export function generateIssue(
title: milestone title: milestone
} }
: undefined, : undefined,
assignees: assignees.map((assignee: Readonly<string>): IAssignee => { assignees: assignees.map((assignee: Readonly<string>): IUserAssignee => {
return { return {
login: assignee login: assignee,
type: 'User'
}; };
}) })
}); });

View File

@@ -2282,3 +2282,73 @@ test('processing an issue stale since less than the daysBeforeStale without a st
expect(processor.deletedBranchIssues).toHaveLength(0); expect(processor.deletedBranchIssues).toHaveLength(0);
expect(processor.closedIssues).toHaveLength(0); expect(processor.closedIssues).toHaveLength(0);
}); });
test('processing a pull request to be stale with the "stalePrMessage" option set will send a PR comment', async () => {
expect.assertions(3);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
stalePrMessage: 'This PR is stale',
daysBeforeStale: 10,
daysBeforePrStale: 1
};
const issueDate = new Date();
issueDate.setDate(issueDate.getDate() - 2);
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'A pull request with no label and a stale message',
issueDate.toDateString(),
issueDate.toDateString(),
true
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(0);
expect(processor.statistics?.addedPullRequestsCommentsCount).toStrictEqual(1);
});
test('processing a pull request to be stale with the "stalePrMessage" option set to empty will not send a PR comment', async () => {
expect.assertions(3);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
stalePrMessage: '',
daysBeforeStale: 10,
daysBeforePrStale: 1
};
const issueDate = new Date();
issueDate.setDate(issueDate.getDate() - 2);
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'A pull request with no label and a stale message',
issueDate.toDateString(),
issueDate.toDateString(),
true
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(0);
expect(processor.statistics?.addedPullRequestsCommentsCount).toStrictEqual(0);
});

View File

@@ -8,7 +8,7 @@ import {generateIssue} from './functions/generate-issue';
let issuesProcessorBuilder: IssuesProcessorBuilder; let issuesProcessorBuilder: IssuesProcessorBuilder;
let issuesProcessor: IssuesProcessorMock; let issuesProcessor: IssuesProcessorMock;
describe('only-labels option', (): void => { describe('only-labels options', (): void => {
beforeEach((): void => { beforeEach((): void => {
issuesProcessorBuilder = new IssuesProcessorBuilder(); issuesProcessorBuilder = new IssuesProcessorBuilder();
}); });
@@ -1103,7 +1103,7 @@ class IssuesProcessorBuilder {
issue.updated_at ?? new Date().toDateString(), issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(), issue.created_at ?? new Date().toDateString(),
!!issue.pull_request, !!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name) : [] issue.labels ? issue.labels.map(label => label.name || '') : []
) )
); );

View File

@@ -5,7 +5,7 @@ import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options'; import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue'; import {generateIssue} from './functions/generate-issue';
describe('operations per run option', (): void => { describe('operations-per-run option', (): void => {
let sut: SUT; let sut: SUT;
beforeEach((): void => { beforeEach((): void => {

View File

@@ -455,7 +455,7 @@ class IssuesProcessorBuilder {
issue.updated_at ?? new Date().toDateString(), issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(), issue.created_at ?? new Date().toDateString(),
!!issue.pull_request, !!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name) : [] issue.labels ? issue.labels.map(label => label.name || '') : []
) )
); );

View File

@@ -0,0 +1,696 @@
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('ignore-updates options', (): void => {
let sut: SUT;
beforeEach((): void => {
sut = new SUT();
});
describe('when the issue should be stale within 10 days and was created 20 days ago and updated 5 days ago', (): void => {
beforeEach((): void => {
sut.toIssue().staleIn(10).created(20).updated(5);
});
describe('when the ignore updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnUpdates();
});
it('should not stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(0);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
describe('when the ignore issue updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignoreIssueUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore issue updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnIssueUpdates();
});
it('should not stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(0);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore issue updates option is unset', (): void => {
beforeEach((): void => {
sut.unsetIgnoreIssueUpdates();
});
it('should not stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(0);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
});
describe('when the ignore updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignoreUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
describe('when the ignore issue updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignoreIssueUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore issue updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnIssueUpdates();
});
it('should not stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(0);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore issue updates option is unset', (): void => {
beforeEach((): void => {
sut.unsetIgnoreIssueUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
});
});
describe('when the issue should be stale within 10 days and was created 20 days ago and updated 15 days ago', (): void => {
beforeEach((): void => {
sut.toIssue().staleIn(10).created(20).updated(15);
});
describe('when the ignore updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
describe('when the ignore issue updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignoreIssueUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore issue updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnIssueUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore issue updates option is unset', (): void => {
beforeEach((): void => {
sut.unsetIgnoreIssueUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
});
describe('when the ignore updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignoreUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
describe('when the ignore issue updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignoreIssueUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore issue updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnIssueUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore issue updates option is unset', (): void => {
beforeEach((): void => {
sut.unsetIgnoreIssueUpdates();
});
it('should stale the issue', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
});
});
describe('when the pull request should be stale within 10 days and was created 20 days ago and updated 5 days ago', (): void => {
beforeEach((): void => {
sut.toPullRequest().staleIn(10).created(20).updated(5);
});
describe('when the ignore updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnUpdates();
});
it('should not stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(0);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
describe('when the ignore pull request updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignorePullRequestUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore pull request updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnPullRequestUpdates();
});
it('should not stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(0);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore pull request updates option is unset', (): void => {
beforeEach((): void => {
sut.unsetIgnorePullRequestUpdates();
});
it('should not stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(0);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
});
describe('when the ignore updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignoreUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
describe('when the ignore pull request updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignorePullRequestUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore pull request updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnPullRequestUpdates();
});
it('should not stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(0);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore pull request updates option is unset', (): void => {
beforeEach((): void => {
sut.unsetIgnorePullRequestUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
});
});
describe('when the pull request should be stale within 10 days and was created 20 days ago and updated 15 days ago', (): void => {
beforeEach((): void => {
sut.toPullRequest().staleIn(10).created(20).updated(15);
});
describe('when the ignore updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
describe('when the ignore pull request updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignorePullRequestUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore pull request updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnPullRequestUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore pull request updates option is unset', (): void => {
beforeEach((): void => {
sut.unsetIgnorePullRequestUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
});
describe('when the ignore updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignoreUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
describe('when the ignore pull request updates option is enabled', (): void => {
beforeEach((): void => {
sut.ignorePullRequestUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore pull request updates option is disabled', (): void => {
beforeEach((): void => {
sut.staleOnPullRequestUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the ignore pull request updates option is unset', (): void => {
beforeEach((): void => {
sut.unsetIgnorePullRequestUpdates();
});
it('should stale the pull request', async () => {
expect.assertions(3);
await sut.test();
expect(sut.processor.staleIssues).toHaveLength(1);
expect(sut.processor.closedIssues).toHaveLength(0);
expect(sut.processor.removedLabelIssues).toHaveLength(0);
});
});
});
});
});
class SUT {
processor!: IssuesProcessorMock;
private _opts: IIssuesProcessorOptions = {...DefaultProcessorOptions};
private _isPullRequest = false;
private _createdAt: IsoDateString = '2020-01-01T17:00:00Z';
private _updatedAt: IsoDateString = '2020-01-01T17:00:00Z';
private _testIssueList: Issue[] = [];
toIssue(): SUT {
this._isPullRequest = false;
return this;
}
toPullRequest(): SUT {
this._isPullRequest = true;
return this;
}
staleIn(days: number): SUT {
this._updateOptions({
daysBeforeIssueStale: days,
daysBeforePrStale: days
});
return this;
}
created(daysAgo: number): SUT {
const today = new Date();
today.setDate(today.getDate() - daysAgo);
this._createdAt = today.toISOString();
return this;
}
updated(daysAgo: number): SUT {
const today = new Date();
today.setDate(today.getDate() - daysAgo);
this._updatedAt = today.toISOString();
return this;
}
ignoreUpdates(): SUT {
this._updateOptions({
ignoreUpdates: true
});
return this;
}
staleOnUpdates(): SUT {
this._updateOptions({
ignoreUpdates: false
});
return this;
}
ignoreIssueUpdates(): SUT {
this._updateOptions({
ignoreIssueUpdates: true
});
return this;
}
staleOnIssueUpdates(): SUT {
this._updateOptions({
ignoreIssueUpdates: false
});
return this;
}
unsetIgnoreIssueUpdates(): SUT {
this._updateOptions({
ignoreIssueUpdates: undefined
});
return this;
}
ignorePullRequestUpdates(): SUT {
this._updateOptions({
ignorePrUpdates: true
});
return this;
}
staleOnPullRequestUpdates(): SUT {
this._updateOptions({
ignorePrUpdates: false
});
return this;
}
unsetIgnorePullRequestUpdates(): SUT {
this._updateOptions({
ignorePrUpdates: undefined
});
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 = [
generateIssue(
this._opts,
1,
'My first issue',
this._updatedAt,
this._createdAt,
this._isPullRequest
)
];
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);
}
}

View File

@@ -49,6 +49,10 @@ inputs:
description: 'The labels that mean an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2").' description: 'The labels that mean an issue is exempt from being marked stale. Separate multiple labels with commas (eg. "label1,label2").'
default: '' default: ''
required: false required: false
close-issue-reason:
description: 'The reason to use when closing an issue.'
default: ''
required: false
stale-pr-label: stale-pr-label:
description: 'The label to apply when a pull request is stale.' description: 'The label to apply when a pull request is stale.'
default: 'Stale' default: 'Stale'
@@ -164,15 +168,39 @@ inputs:
description: 'Exempt all pull requests with assignees from being marked as stale. Override "exempt-all-assignees" option regarding only the pull requests.' description: 'Exempt all pull requests with assignees from being marked as stale. Override "exempt-all-assignees" option regarding only the pull requests.'
default: '' default: ''
required: false required: false
exempt-draft-pr:
description: 'Exempt draft pull requests from being marked as stale. Default to false.'
default: 'false'
required: false
enable-statistics: enable-statistics:
description: 'Display some statistics at the end regarding the stale workflow (only when the logs are enabled).' description: 'Display some statistics at the end regarding the stale workflow (only when the logs are enabled).'
default: 'true' default: 'true'
required: false required: false
labels-to-add-when-unstale:
description: 'A comma delimited list of labels to add when a stale issue or pull request receives activity and has the stale-issue-label or stale-pr-label removed from it.'
default: ''
required: false
labels-to-remove-when-unstale:
description: 'A comma delimited list of labels to remove when a stale issue or pull request receives activity and has the stale-issue-label or stale-pr-label removed from it.'
default: ''
required: false
ignore-updates:
description: 'Any update (update/comment) can reset the stale idle time on the issues and pull requests.'
default: 'false'
required: false
ignore-issue-updates:
description: 'Any update (update/comment) can reset the stale idle time on the issues. Override "ignore-updates" option regarding only the issues.'
default: ''
required: false
ignore-pr-updates:
description: 'Any update (update/comment) can reset the stale idle time on the pull requests. Override "ignore-updates" option regarding only the pull requests.'
default: ''
required: false
outputs: outputs:
closed-issues-prs: closed-issues-prs:
description: 'List of all closed issues and pull requests.' description: 'List of all closed issues and pull requests.'
staled-issues-prs: staled-issues-prs:
description: 'List of all staled issues and pull requests.' description: 'List of all staled issues and pull requests.'
runs: runs:
using: 'node12' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'

4364
dist/index.js vendored

File diff suppressed because one or more lines are too long

8273
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -6,8 +6,8 @@
"main": "lib/main.js", "main": "lib/main.js",
"scripts": { "scripts": {
"build": "tsc --project tsconfig.app.json", "build": "tsc --project tsconfig.app.json",
"format": "prettier --write --ignore-unknown **/*.{md,json,yml,ts}", "format": "prettier --write --ignore-unknown **/*.{json,yml,ts}",
"format-check": "prettier --check --ignore-unknown **/*.{md,json,yml,ts}", "format-check": "prettier --check --ignore-unknown **/*.{json,yml,ts}",
"lint": "eslint src/**/*.ts", "lint": "eslint src/**/*.ts",
"lint:fix": "eslint src/**/*.ts --fix", "lint:fix": "eslint src/**/*.ts --fix",
"lint:all": "npm run format-check && npm run lint", "lint:all": "npm run format-check && npm run lint",
@@ -17,6 +17,7 @@
"test:only-errors": "jest --reporters jest-silent-reporter --silent", "test:only-errors": "jest --reporters jest-silent-reporter --silent",
"test:watch": "jest --watch --notify --expand", "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",
"all:ci": "npm run build && npm run lint:all && npm run pack && npm run test:only-errors",
"prerelease": "npm run build && npm run pack", "prerelease": "npm run build && npm run pack",
"release": "standard-version", "release": "standard-version",
"release:dry-run": "standard-version --dry-run" "release:dry-run": "standard-version --dry-run"
@@ -38,30 +39,30 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.2.6",
"@actions/github": "^4.0.0", "@actions/github": "^5.0.1",
"lodash.deburr": "^4.1.0", "lodash.deburr": "^4.1.0",
"semver": "^7.3.5" "semver": "^7.3.5"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^26.0.23", "@types/jest": "^27.0.2",
"@types/lodash.deburr": "^4.1.6", "@types/lodash.deburr": "^4.1.6",
"@types/node": "^15.0.2", "@types/node": "^15.0.2",
"@types/semver": "^7.3.5", "@types/semver": "^7.3.5",
"@typescript-eslint/eslint-plugin": "^4.26.0", "@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.26.1", "@typescript-eslint/parser": "^4.31.1",
"@vercel/ncc": "^0.28.6", "@vercel/ncc": "^0.28.6",
"ansi-styles": "5.2.0", "ansi-styles": "5.2.0",
"eslint": "^7.28.0", "eslint": "^7.28.0",
"eslint-plugin-github": "^4.1.2", "eslint-plugin-github": "^4.1.2",
"eslint-plugin-jest": "^24.3.6", "eslint-plugin-jest": "^25.3.2",
"jest": "^26.6.3", "jest": "^27.2.5",
"jest-circus": "^26.6.3", "jest-circus": "^27.4.6",
"jest-silent-reporter": "^0.4.0", "jest-silent-reporter": "^0.5.0",
"js-yaml": "^4.1.0", "js-yaml": "^4.1.0",
"prettier": "^2.3.1", "prettier": "^2.5.1",
"standard-version": "^9.2.0", "standard-version": "^9.3.1",
"terminal-link": "^2.1.1", "terminal-link": "^2.1.1",
"ts-jest": "^26.5.6", "ts-jest": "^27.1.2",
"typescript": "^4.3.2" "typescript": "^4.3.2"
} }
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,7 +1,7 @@
import deburr from 'lodash.deburr'; import deburr from 'lodash.deburr';
import {Option} from '../enums/option'; import {Option} from '../enums/option';
import {wordsToList} from '../functions/words-to-list'; import {wordsToList} from '../functions/words-to-list';
import {IAssignee} from '../interfaces/assignee'; import {Assignee} from '../interfaces/assignee';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Issue} from './issue'; import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger'; import {IssueLogger} from './loggers/issue-logger';
@@ -10,10 +10,6 @@ import {LoggerService} from '../services/logger.service';
type CleanAssignee = string; type CleanAssignee = string;
export class Assignees { export class Assignees {
private static _cleanAssignee(assignee: Readonly<string>): CleanAssignee {
return deburr(assignee.toLowerCase());
}
private readonly _options: IIssuesProcessorOptions; private readonly _options: IIssuesProcessorOptions;
private readonly _issue: Issue; private readonly _issue: Issue;
private readonly _issueLogger: IssueLogger; private readonly _issueLogger: IssueLogger;
@@ -24,6 +20,10 @@ export class Assignees {
this._issueLogger = new IssueLogger(issue); this._issueLogger = new IssueLogger(issue);
} }
private static _cleanAssignee(assignee: Readonly<string>): CleanAssignee {
return deburr(assignee.toLowerCase());
}
shouldExemptAssignees(): boolean { shouldExemptAssignees(): boolean {
if (!this._issue.hasAssignees) { if (!this._issue.hasAssignees) {
this._issueLogger.info('This $$type has no assignee'); this._issueLogger.info('This $$type has no assignee');
@@ -195,7 +195,7 @@ export class Assignees {
const cleanAssignee: CleanAssignee = Assignees._cleanAssignee(assignee); const cleanAssignee: CleanAssignee = Assignees._cleanAssignee(assignee);
return this._issue.assignees.some( return this._issue.assignees.some(
(issueAssignee: Readonly<IAssignee>): boolean => { (issueAssignee: Readonly<Assignee>): boolean => {
const isSameAssignee: boolean = const isSameAssignee: boolean =
cleanAssignee === Assignees._cleanAssignee(issueAssignee.login); cleanAssignee === Assignees._cleanAssignee(issueAssignee.login);

View File

@@ -0,0 +1,51 @@
import {Option} from '../enums/option';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {IPullRequest} from '../interfaces/pull-request';
import {LoggerService} from '../services/logger.service';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
export class ExemptDraftPullRequest {
private readonly _options: IIssuesProcessorOptions;
private readonly _issue: Issue;
private readonly _issueLogger: IssueLogger;
constructor(options: Readonly<IIssuesProcessorOptions>, issue: Issue) {
this._options = options;
this._issue = issue;
this._issueLogger = new IssueLogger(issue);
}
async shouldExemptDraftPullRequest(
pullRequestCallback: () => Promise<IPullRequest | undefined | void>
): Promise<boolean> {
if (this._issue.isPullRequest) {
if (this._options.exemptDraftPr) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptDraftPr
)} is enabled`
);
const pullRequest: IPullRequest | undefined | void =
await pullRequestCallback();
if (pullRequest?.draft === true) {
this._issueLogger.info(
LoggerService.white('└──'),
`Skip the $$type draft checks`
);
return true;
} else {
this._issueLogger.info(
LoggerService.white('└──'),
`Continuing the process for this $$type because it is not a draft`
);
}
}
}
return false;
}
}

View File

@@ -0,0 +1,251 @@
import {DefaultProcessorOptions} from '../../__tests__/constants/default-processor-options';
import {generateIIssue} from '../../__tests__/functions/generate-iissue';
import {IIssue} from '../interfaces/issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {IgnoreUpdates} from './ignore-updates';
import {Issue} from './issue';
describe('IgnoreUpdates', (): void => {
let ignoreUpdates: IgnoreUpdates;
let optionsInterface: IIssuesProcessorOptions;
let issue: Issue;
let issueInterface: IIssue;
beforeEach((): void => {
optionsInterface = {
...DefaultProcessorOptions,
ignoreIssueUpdates: true
};
issueInterface = generateIIssue();
});
describe('shouldIgnoreUpdates()', (): void => {
describe('when the given issue is not a pull request', (): void => {
beforeEach((): void => {
issueInterface.pull_request = undefined;
});
describe('when the given options are configured to reset the stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreUpdates = false;
});
describe('when the given options are not configured to reset the issue stale on updates', (): void => {
beforeEach((): void => {
delete optionsInterface.ignoreIssueUpdates;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
});
describe('when the given options are configured to reset the stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreUpdates = true;
});
describe('when the given options are not configured to reset the issue stale on updates', (): void => {
beforeEach((): void => {
delete optionsInterface.ignoreIssueUpdates;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
describe('when the given options are configured to reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the issue stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreIssueUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
});
});
describe('when the given issue is a pull request', (): void => {
beforeEach((): void => {
issueInterface.pull_request = {};
});
describe('when the given options are configured to reset the stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreUpdates = false;
});
describe('when the given options are not configured to reset the pull request stale on updates', (): void => {
beforeEach((): void => {
delete optionsInterface.ignorePrUpdates;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
});
describe('when the given options are configured to not reset the stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignoreUpdates = true;
});
describe('when the given options are not configured to reset the pull request stale on updates', (): void => {
beforeEach((): void => {
delete optionsInterface.ignorePrUpdates;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
describe('when the given options are configured to reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = false;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(false);
});
});
describe('when the given options are configured to not reset the pull request stale on updates', (): void => {
beforeEach((): void => {
optionsInterface.ignorePrUpdates = true;
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
ignoreUpdates = new IgnoreUpdates(optionsInterface, issue);
const result = ignoreUpdates.shouldIgnoreUpdates();
expect(result).toStrictEqual(true);
});
});
});
});
});
});

View File

@@ -0,0 +1,90 @@
import {Option} from '../enums/option';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
export class IgnoreUpdates {
private readonly _options: IIssuesProcessorOptions;
private readonly _issue: Issue;
private readonly _issueLogger: IssueLogger;
constructor(options: Readonly<IIssuesProcessorOptions>, issue: Issue) {
this._options = options;
this._issue = issue;
this._issueLogger = new IssueLogger(issue);
}
shouldIgnoreUpdates(): boolean {
return this._shouldIgnoreUpdates();
}
private _shouldIgnoreUpdates(): boolean {
return this._issue.isPullRequest
? this._shouldIgnorePullRequestUpdates()
: this._shouldIgnoreIssueUpdates();
}
private _shouldIgnorePullRequestUpdates(): boolean {
if (this._options.ignorePrUpdates === true) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnorePrUpdates
)} is enabled. The stale counter will ignore any updates or comments on this $$type and will use the creation date as a reference ignoring any kind of update`
);
return true;
} else if (this._options.ignorePrUpdates === false) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnorePrUpdates
)} is disabled. The stale counter will take into account updates and comments on this $$type to avoid to stale when there is some update`
);
return false;
}
this._logIgnoreUpdates();
return this._options.ignoreUpdates;
}
private _shouldIgnoreIssueUpdates(): boolean {
if (this._options.ignoreIssueUpdates === true) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnoreIssueUpdates
)} is enabled. The stale counter will ignore any updates or comments on this $$type and will use the creation date as a reference ignoring any kind of update`
);
return true;
} else if (this._options.ignoreIssueUpdates === false) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnoreIssueUpdates
)} is disabled. The stale counter will take into account updates and comments on this $$type to avoid to stale when there is some update`
);
return false;
}
this._logIgnoreUpdates();
return this._options.ignoreUpdates;
}
private _logIgnoreUpdates(): void {
if (this._options.ignoreUpdates) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnoreUpdates
)} is enabled. The stale counter will ignore any updates or comments on this $$type and will use the creation date as a reference ignoring any kind of update`
);
} else {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.IgnoreUpdates
)} is disabled. The stale counter will take into account updates and comments on this $$type to avoid to stale when there is some update`
);
}
}
}

View File

@@ -1,4 +1,4 @@
import {IAssignee} from '../interfaces/assignee'; import {IUserAssignee} from '../interfaces/assignee';
import {IIssue} from '../interfaces/issue'; import {IIssue} from '../interfaces/issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {ILabel} from '../interfaces/label'; import {ILabel} from '../interfaces/label';
@@ -57,7 +57,12 @@ describe('Issue', (): void => {
exemptAllPrAssignees: undefined, exemptAllPrAssignees: undefined,
enableStatistics: false, enableStatistics: false,
labelsToRemoveWhenUnstale: '', labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: '' labelsToAddWhenUnstale: '',
ignoreUpdates: false,
ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined,
exemptDraftPr: false,
closeIssueReason: ''
}; };
issueInterface = { issueInterface = {
title: 'dummy-title', title: 'dummy-title',
@@ -77,7 +82,8 @@ describe('Issue', (): void => {
}, },
assignees: [ assignees: [
{ {
login: 'dummy-login' login: 'dummy-login',
type: 'User'
} }
] ]
}; };
@@ -150,8 +156,9 @@ describe('Issue', (): void => {
expect(issue.assignees).toStrictEqual([ expect(issue.assignees).toStrictEqual([
{ {
login: 'dummy-login' login: 'dummy-login',
} as IAssignee type: 'User'
} as IUserAssignee
]); ]);
}); });
@@ -272,7 +279,8 @@ describe('Issue', (): void => {
beforeEach((): void => { beforeEach((): void => {
issueInterface.assignees = [ issueInterface.assignees = [
{ {
login: 'dummy-login' login: 'dummy-login',
type: 'User'
} }
]; ];
issue = new Issue(optionsInterface, issueInterface); issue = new Issue(optionsInterface, issueInterface);

View File

@@ -1,7 +1,7 @@
import {isLabeled} from '../functions/is-labeled'; import {isLabeled} from '../functions/is-labeled';
import {isPullRequest} from '../functions/is-pull-request'; import {isPullRequest} from '../functions/is-pull-request';
import {IAssignee} from '../interfaces/assignee'; import {Assignee} from '../interfaces/assignee';
import {IIssue} from '../interfaces/issue'; import {IIssue, OctokitIssue} from '../interfaces/issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {ILabel} from '../interfaces/label'; import {ILabel} from '../interfaces/label';
import {IMilestone} from '../interfaces/milestone'; import {IMilestone} from '../interfaces/milestone';
@@ -9,7 +9,6 @@ import {IsoDateString} from '../types/iso-date-string';
import {Operations} from './operations'; import {Operations} from './operations';
export class Issue implements IIssue { export class Issue implements IIssue {
private readonly _options: IIssuesProcessorOptions;
readonly title: string; readonly title: string;
readonly number: number; readonly number: number;
created_at: IsoDateString; created_at: IsoDateString;
@@ -18,10 +17,31 @@ export class Issue implements IIssue {
readonly pull_request: Object | null | undefined; readonly pull_request: Object | null | undefined;
readonly state: string | 'closed' | 'open'; readonly state: string | 'closed' | 'open';
readonly locked: boolean; readonly locked: boolean;
readonly milestone: IMilestone | undefined; readonly milestone?: IMilestone | null;
readonly assignees: IAssignee[]; readonly assignees: Assignee[];
isStale: boolean; isStale: boolean;
markedStaleThisRun: boolean;
operations = new Operations(); operations = new Operations();
private readonly _options: IIssuesProcessorOptions;
constructor(
options: Readonly<IIssuesProcessorOptions>,
issue: Readonly<OctokitIssue> | Readonly<IIssue>
) {
this._options = options;
this.title = issue.title;
this.number = issue.number;
this.created_at = issue.created_at;
this.updated_at = issue.updated_at;
this.labels = mapLabels(issue.labels);
this.pull_request = issue.pull_request;
this.state = issue.state;
this.locked = issue.locked;
this.milestone = issue.milestone;
this.assignees = issue.assignees || [];
this.isStale = isLabeled(this, this.staleLabel);
this.markedStaleThisRun = false;
}
get isPullRequest(): boolean { get isPullRequest(): boolean {
return isPullRequest(this); return isPullRequest(this);
@@ -35,28 +55,20 @@ export class Issue implements IIssue {
return this.assignees.length > 0; return this.assignees.length > 0;
} }
constructor(
options: Readonly<IIssuesProcessorOptions>,
issue: Readonly<IIssue>
) {
this._options = options;
this.title = issue.title;
this.number = issue.number;
this.created_at = issue.created_at;
this.updated_at = issue.updated_at;
this.labels = issue.labels;
this.pull_request = issue.pull_request;
this.state = issue.state;
this.locked = issue.locked;
this.milestone = issue.milestone;
this.assignees = issue.assignees;
this.isStale = isLabeled(this, this.staleLabel);
}
private _getStaleLabel(): string { private _getStaleLabel(): string {
return this.isPullRequest return this.isPullRequest
? this._options.stalePrLabel ? this._options.stalePrLabel
: this._options.staleIssueLabel; : this._options.staleIssueLabel;
} }
} }
function mapLabels(labels: (string | ILabel)[] | ILabel[]): ILabel[] {
return labels.map(label => {
if (typeof label == 'string') {
return {
name: label
};
}
return label;
});
}

View File

@@ -1,22 +1,22 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import {context, getOctokit} from '@actions/github'; import {context, getOctokit} from '@actions/github';
import {GitHub} from '@actions/github/lib/utils'; import {GitHub} from '@actions/github/lib/utils';
import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
import {Option} from '../enums/option'; import {Option} from '../enums/option';
import {getHumanizedDate} from '../functions/dates/get-humanized-date'; import {getHumanizedDate} from '../functions/dates/get-humanized-date';
import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than'; import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than';
import {isValidDate} from '../functions/dates/is-valid-date'; import {isValidDate} from '../functions/dates/is-valid-date';
import {isBoolean} from '../functions/is-boolean'; import {isBoolean} from '../functions/is-boolean';
import {isLabeled} from '../functions/is-labeled'; import {isLabeled} from '../functions/is-labeled';
import { cleanLabel } from '../functions/clean-label'; import {cleanLabel} from '../functions/clean-label';
import {shouldMarkWhenStale} from '../functions/should-mark-when-stale'; import {shouldMarkWhenStale} from '../functions/should-mark-when-stale';
import {wordsToList} from '../functions/words-to-list'; import {wordsToList} from '../functions/words-to-list';
import {IComment} from '../interfaces/comment'; import {IComment} from '../interfaces/comment';
import {IIssue} from '../interfaces/issue';
import {IIssueEvent} from '../interfaces/issue-event'; import {IIssueEvent} from '../interfaces/issue-event';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options'; import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {IPullRequest} from '../interfaces/pull-request'; import {IPullRequest} from '../interfaces/pull-request';
import {Assignees} from './assignees'; import {Assignees} from './assignees';
import {IgnoreUpdates} from './ignore-updates';
import {ExemptDraftPullRequest} from './exempt-draft-pull-request';
import {Issue} from './issue'; import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger'; import {IssueLogger} from './loggers/issue-logger';
import {Logger} from './loggers/logger'; import {Logger} from './loggers/logger';
@@ -24,13 +24,14 @@ import {Milestones} from './milestones';
import {StaleOperations} from './stale-operations'; import {StaleOperations} from './stale-operations';
import {Statistics} from './statistics'; import {Statistics} from './statistics';
import {LoggerService} from '../services/logger.service'; import {LoggerService} from '../services/logger.service';
import {OctokitIssue} from '../interfaces/issue';
/*** /***
* Handle processing of issues for staleness/closure. * Handle processing of issues for staleness/closure.
*/ */
export class IssuesProcessor { export class IssuesProcessor {
private static _updatedSince(timestamp: string, num_minutes: number): boolean { private static _updatedSince(timestamp: string, num_days: number): boolean {
const daysInMillis = 1000 * 60 * num_minutes; const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
const millisSinceLastUpdated = const millisSinceLastUpdated =
new Date().getTime() - new Date(timestamp).getTime(); new Date().getTime() - new Date(timestamp).getTime();
@@ -53,22 +54,12 @@ export class IssuesProcessor {
} }
} }
private static _getStaleMessageUsedOptionName(
issue: Readonly<Issue>
): Option.StalePrMessage | Option.StaleIssueMessage {
return issue.isPullRequest
? Option.StalePrMessage
: Option.StaleIssueMessage;
}
private static _getCloseLabelUsedOptionName( private static _getCloseLabelUsedOptionName(
issue: Readonly<Issue> issue: Readonly<Issue>
): Option.ClosePrLabel | Option.CloseIssueLabel { ): Option.ClosePrLabel | Option.CloseIssueLabel {
return issue.isPullRequest ? Option.ClosePrLabel : Option.CloseIssueLabel; return issue.isPullRequest ? Option.ClosePrLabel : Option.CloseIssueLabel;
} }
private readonly _logger: Logger = new Logger();
private readonly _statistics: Statistics | undefined;
readonly operations: StaleOperations; readonly operations: StaleOperations;
readonly client: InstanceType<typeof GitHub>; readonly client: InstanceType<typeof GitHub>;
readonly options: IIssuesProcessorOptions; readonly options: IIssuesProcessorOptions;
@@ -77,6 +68,9 @@ export class IssuesProcessor {
readonly deletedBranchIssues: Issue[] = []; readonly deletedBranchIssues: Issue[] = [];
readonly removedLabelIssues: Issue[] = []; readonly removedLabelIssues: Issue[] = [];
readonly addedLabelIssues: Issue[] = []; readonly addedLabelIssues: Issue[] = [];
readonly addedCloseCommentIssues: Issue[] = [];
readonly statistics: Statistics | undefined;
private readonly _logger: Logger = new Logger();
constructor(options: IIssuesProcessorOptions) { constructor(options: IIssuesProcessorOptions) {
this.options = options; this.options = options;
@@ -99,7 +93,7 @@ export class IssuesProcessor {
} }
if (this.options.enableStatistics) { if (this.options.enableStatistics) {
this._statistics = new Statistics(); this.statistics = new Statistics();
} }
} }
@@ -111,7 +105,7 @@ export class IssuesProcessor {
this._logger.info( this._logger.info(
LoggerService.green(`No more issues found to process. Exiting...`) LoggerService.green(`No more issues found to process. Exiting...`)
); );
this._statistics this.statistics
?.setOperationsCount(this.operations.getConsumedOperationsCount()) ?.setOperationsCount(this.operations.getConsumedOperationsCount())
.logStats(); .logStats();
@@ -119,11 +113,11 @@ export class IssuesProcessor {
} else { } else {
this._logger.info( this._logger.info(
`${LoggerService.yellow( `${LoggerService.yellow(
'Processing the batch of issues' 'Processing the batch of issues '
)} ${LoggerService.cyan(`#${page}`)} ${LoggerService.yellow( )} ${LoggerService.cyan(`#${page}`)} ${LoggerService.yellow(
'containing' ' containing '
)} ${LoggerService.cyan(issues.length)} ${LoggerService.yellow( )} ${LoggerService.cyan(issues.length)} ${LoggerService.yellow(
`issue${issues.length > 1 ? 's' : ''}...` ` issue${issues.length > 1 ? 's' : ''}...`
)}` )}`
); );
} }
@@ -157,14 +151,14 @@ export class IssuesProcessor {
); );
this._logger.warning( this._logger.warning(
`${LoggerService.yellowBright( `${LoggerService.yellowBright(
'If you think that not enough issues were processed you could try to increase the quantity related to the' 'If you think that not enough issues were processed you could try to increase the quantity related to the '
)} ${this._logger.createOptionLink( )} ${this._logger.createOptionLink(
Option.OperationsPerRun Option.OperationsPerRun
)} ${LoggerService.yellowBright( )} ${LoggerService.yellowBright(
'option which is currently set to' ' option which is currently set to '
)} ${LoggerService.cyan(this.options.operationsPerRun)}` )} ${LoggerService.cyan(this.options.operationsPerRun)}`
); );
this._statistics this.statistics
?.setOperationsCount(this.operations.getConsumedOperationsCount()) ?.setOperationsCount(this.operations.getConsumedOperationsCount())
.logStats(); .logStats();
@@ -172,9 +166,9 @@ export class IssuesProcessor {
} }
this._logger.info( this._logger.info(
`${LoggerService.green('Batch')} ${LoggerService.cyan( `${LoggerService.green('Batch ')} ${LoggerService.cyan(
`#${page}` `#${page}`
)} ${LoggerService.green('processed.')}` )} ${LoggerService.green(' processed.')}`
); );
// Do the next batch // Do the next batch
@@ -186,7 +180,7 @@ export class IssuesProcessor {
labelsToAddWhenUnstale: Readonly<string>[], labelsToAddWhenUnstale: Readonly<string>[],
labelsToRemoveWhenUnstale: Readonly<string>[] labelsToRemoveWhenUnstale: Readonly<string>[]
): Promise<void> { ): Promise<void> {
this._statistics?.incrementProcessedItemsCount(issue); this.statistics?.incrementProcessedItemsCount(issue);
const issueLogger: IssueLogger = new IssueLogger(issue); const issueLogger: IssueLogger = new IssueLogger(issue);
issueLogger.info( issueLogger.info(
@@ -214,6 +208,19 @@ export class IssuesProcessor {
const daysBeforeStale: number = issue.isPullRequest const daysBeforeStale: number = issue.isPullRequest
? this._getDaysBeforePrStale() ? this._getDaysBeforePrStale()
: this._getDaysBeforeIssueStale(); : this._getDaysBeforeIssueStale();
if (issue.state === 'closed') {
issueLogger.info(`Skipping this $$type because it is closed`);
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process closed issues
}
if (issue.locked) {
issueLogger.info(`Skipping this $$type because it is locked`);
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process locked issues
}
const onlyLabels: string[] = wordsToList(this._getOnlyLabels(issue)); const onlyLabels: string[] = wordsToList(this._getOnlyLabels(issue));
if (onlyLabels.length > 0) { if (onlyLabels.length > 0) {
@@ -267,18 +274,6 @@ export class IssuesProcessor {
const shouldMarkAsStale: boolean = shouldMarkWhenStale(daysBeforeStale); const shouldMarkAsStale: boolean = shouldMarkWhenStale(daysBeforeStale);
if (issue.state === 'closed') {
issueLogger.info(`Skipping this $$type because it is closed`);
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process closed issues
}
if (issue.locked) {
issueLogger.info(`Skipping this $$type because it is locked`);
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process locked issues
}
// Try to remove the close label when not close/locked issue or PR // Try to remove the close label when not close/locked issue or PR
await this._removeCloseLabel(issue, closeLabel); await this._removeCloseLabel(issue, closeLabel);
@@ -404,23 +399,63 @@ export class IssuesProcessor {
return; // Don't process exempt assignees return; // Don't process exempt assignees
} }
// Should this issue be marked stale? // Ignore draft PR
const shouldBeStale = !IssuesProcessor._updatedSince( // Note that this check is so far below because it cost one read operation
issue.updated_at, // So it's simply better to do all the stale checks which don't cost more operation before this one
daysBeforeStale const exemptDraftPullRequest: ExemptDraftPullRequest =
); new ExemptDraftPullRequest(this.options, issue);
if (
await exemptDraftPullRequest.shouldExemptDraftPullRequest(
async (): Promise<IPullRequest | undefined | void> => {
return this.getPullRequest(issue);
}
)
) {
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process draft PR
}
// Determine if this issue needs to be marked stale first // Determine if this issue needs to be marked stale first
if (!issue.isStale) { if (!issue.isStale) {
issueLogger.info(`This $$type is not stale`); issueLogger.info(`This $$type is not stale`);
const updatedAtDate: Date = new Date(issue.updated_at); const shouldIgnoreUpdates: boolean = new IgnoreUpdates(
this.options,
issue
).shouldIgnoreUpdates();
// Should this issue be marked as stale?
let shouldBeStale: boolean;
// Ignore the last update and only use the creation date
if (shouldIgnoreUpdates) {
shouldBeStale = !IssuesProcessor._updatedSince(
issue.created_at,
daysBeforeStale
);
}
// Use the last update to check if we need to stale
else {
shouldBeStale = !IssuesProcessor._updatedSince(
issue.updated_at,
daysBeforeStale
);
}
if (shouldBeStale) { if (shouldBeStale) {
issueLogger.info( if (shouldIgnoreUpdates) {
`This $$type should be stale based on the last update date the ${getHumanizedDate( issueLogger.info(
updatedAtDate `This $$type should be stale based on the creation date the ${getHumanizedDate(
)} (${LoggerService.cyan(issue.updated_at)})` new Date(issue.created_at)
); )} (${LoggerService.cyan(issue.created_at)})`
);
} else {
issueLogger.info(
`This $$type should be stale based on the last update date the ${getHumanizedDate(
new Date(issue.updated_at)
)} (${LoggerService.cyan(issue.updated_at)})`
);
}
if (shouldMarkAsStale) { if (shouldMarkAsStale) {
issueLogger.info( issueLogger.info(
@@ -430,6 +465,7 @@ export class IssuesProcessor {
); );
await this._markStale(issue, staleMessage, staleLabel, skipMessage); await this._markStale(issue, staleMessage, staleLabel, skipMessage);
issue.isStale = true; // This issue is now considered stale issue.isStale = true; // This issue is now considered stale
issue.markedStaleThisRun = true;
issueLogger.info(`This $$type is now stale`); issueLogger.info(`This $$type is now stale`);
} else { } else {
issueLogger.info( issueLogger.info(
@@ -439,11 +475,19 @@ export class IssuesProcessor {
); );
} }
} else { } else {
issueLogger.info( if (shouldIgnoreUpdates) {
`This $$type should not be stale based on the last update date the ${getHumanizedDate( issueLogger.info(
updatedAtDate `This $$type should not be stale based on the creation date the ${getHumanizedDate(
)} (${LoggerService.cyan(issue.updated_at)})` new Date(issue.created_at)
); )} (${LoggerService.cyan(issue.created_at)})`
);
} else {
issueLogger.info(
`This $$type should not be stale based on the last update date the ${getHumanizedDate(
new Date(issue.updated_at)
)} (${LoggerService.cyan(issue.updated_at)})`
);
}
} }
} }
@@ -466,17 +510,17 @@ export class IssuesProcessor {
// Grab comments for an issue since a given date // Grab comments for an issue since a given date
async listIssueComments( async listIssueComments(
issueNumber: Readonly<number>, issue: Readonly<Issue>,
sinceDate: Readonly<string> sinceDate: Readonly<string>
): Promise<IComment[]> { ): Promise<IComment[]> {
// Find any comments since date on the given issue // Find any comments since date on the given issue
try { try {
this.operations.consumeOperation(); this._consumeIssueOperation(issue);
this._statistics?.incrementFetchedItemsCommentsCount(); this.statistics?.incrementFetchedItemsCommentsCount();
const comments = await this.client.issues.listComments({ const comments = await this.client.rest.issues.listComments({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issueNumber, issue_number: issue.number,
since: sinceDate since: sinceDate
}); });
return comments.data; return comments.data;
@@ -488,25 +532,20 @@ export class IssuesProcessor {
// grab issues from github in batches of 100 // grab issues from github in batches of 100
async getIssues(page: number): Promise<Issue[]> { async getIssues(page: number): Promise<Issue[]> {
// generate type for response
const endpoint = this.client.issues.listForRepo;
type OctoKitIssueList = GetResponseTypeFromEndpointMethod<typeof endpoint>;
try { try {
this.operations.consumeOperation(); this.operations.consumeOperation();
const issueResult: OctoKitIssueList = const issueResult = await this.client.rest.issues.listForRepo({
await this.client.issues.listForRepo({ owner: context.repo.owner,
owner: context.repo.owner, repo: context.repo.repo,
repo: context.repo.repo, state: 'open',
state: 'open', per_page: 100,
per_page: 100, direction: this.options.ascending ? 'asc' : 'desc',
direction: this.options.ascending ? 'asc' : 'desc', page
page });
}); this.statistics?.incrementFetchedItemsCount(issueResult.data.length);
this._statistics?.incrementFetchedItemsCount(issueResult.data.length);
return issueResult.data.map( return issueResult.data.map(
(issue: Readonly<IIssue>): Issue => new Issue(this.options, issue) (issue: Readonly<OctokitIssue>): Issue => new Issue(this.options, issue)
); );
} catch (error) { } catch (error) {
this._logger.error(`Get issues for repo error: ${error.message}`); this._logger.error(`Get issues for repo error: ${error.message}`);
@@ -525,8 +564,8 @@ export class IssuesProcessor {
issueLogger.info(`Checking for label on this $$type`); issueLogger.info(`Checking for label on this $$type`);
this._consumeIssueOperation(issue); this._consumeIssueOperation(issue);
this._statistics?.incrementFetchedItemsEventsCount(); this.statistics?.incrementFetchedItemsEventsCount();
const options = this.client.issues.listEvents.endpoint.merge({ const options = this.client.rest.issues.listEvents.endpoint.merge({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
per_page: 100, per_page: 100,
@@ -537,7 +576,9 @@ export class IssuesProcessor {
const reversedEvents = events.reverse(); const reversedEvents = events.reverse();
const staleLabeledEvent = reversedEvents.find( const staleLabeledEvent = reversedEvents.find(
event => event.event === 'labeled' && cleanLabel(event.label.name) === cleanLabel(label) event =>
event.event === 'labeled' &&
cleanLabel(event.label.name) === cleanLabel(label)
); );
if (!staleLabeledEvent) { if (!staleLabeledEvent) {
@@ -548,6 +589,25 @@ export class IssuesProcessor {
return staleLabeledEvent.created_at; return staleLabeledEvent.created_at;
} }
async getPullRequest(issue: Issue): Promise<IPullRequest | undefined | void> {
const issueLogger: IssueLogger = new IssueLogger(issue);
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementFetchedPullRequestsCount();
const pullRequest = await this.client.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number
});
return pullRequest.data;
} catch (error) {
issueLogger.error(`Error when getting this $$type: ${error.message}`);
}
}
// handle all of the stale issue logic when we find a stale issue // handle all of the stale issue logic when we find a stale issue
private async _processStaleIssue( private async _processStaleIssue(
issue: Issue, issue: Issue,
@@ -565,13 +625,15 @@ export class IssuesProcessor {
`$$type marked stale on: ${LoggerService.cyan(markedStaleOn)}` `$$type marked stale on: ${LoggerService.cyan(markedStaleOn)}`
); );
const issueHasComments: boolean = await this._hasCommentsSince( const issueHasCommentsSinceStale: boolean = await this._hasCommentsSince(
issue, issue,
markedStaleOn, markedStaleOn,
staleMessage staleMessage
); );
issueLogger.info( issueLogger.info(
`$$type has been commented on: ${LoggerService.cyan(issueHasComments)}` `$$type has been commented on: ${LoggerService.cyan(
issueHasCommentsSinceStale
)}`
); );
const daysBeforeClose: number = issue.isPullRequest const daysBeforeClose: number = issue.isPullRequest
@@ -582,14 +644,6 @@ export class IssuesProcessor {
`Days before $$type close: ${LoggerService.cyan(daysBeforeClose)}` `Days before $$type close: ${LoggerService.cyan(daysBeforeClose)}`
); );
const issueHasUpdate: boolean = IssuesProcessor._updatedSince(
issue.updated_at,
daysBeforeClose
);
issueLogger.info(
`$$type has been updated: ${LoggerService.cyan(issueHasUpdate)}`
);
const shouldRemoveStaleWhenUpdated: boolean = const shouldRemoveStaleWhenUpdated: boolean =
this._shouldRemoveStaleWhenUpdated(issue); this._shouldRemoveStaleWhenUpdated(issue);
@@ -607,10 +661,27 @@ export class IssuesProcessor {
); );
} }
if (issue.markedStaleThisRun) {
issueLogger.info(`marked stale this run, so don't check for updates`);
}
const issueHasUpdateSinceStale =
new Date(issue.updated_at) > new Date(markedStaleOn);
issueLogger.info(
`$$type has been updated since it was marked stale: ${LoggerService.cyan(
issueHasUpdateSinceStale
)}`
);
// Should we un-stale this issue? // Should we un-stale this issue?
if (shouldRemoveStaleWhenUpdated && issueHasComments) { if (
shouldRemoveStaleWhenUpdated &&
(issueHasUpdateSinceStale || issueHasCommentsSinceStale) &&
!issue.markedStaleThisRun
) {
issueLogger.info( issueLogger.info(
`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when updated` `Remove the stale label since the $$type has been updated and the workflow should remove the stale label when updated`
); );
await this._removeStaleLabel(issue, staleLabel); await this._removeStaleLabel(issue, staleLabel);
@@ -628,7 +699,17 @@ export class IssuesProcessor {
return; // Nothing to do because we aren't closing stale issues return; // Nothing to do because we aren't closing stale issues
} }
if (!issueHasComments && !issueHasUpdate) { const issueHasUpdateInCloseWindow: boolean = IssuesProcessor._updatedSince(
issue.updated_at,
daysBeforeClose
);
issueLogger.info(
`$$type has been updated in the last ${daysBeforeClose} days: ${LoggerService.cyan(
issueHasUpdateInCloseWindow
)}`
);
if (!issueHasCommentsSinceStale && !issueHasUpdateInCloseWindow) {
issueLogger.info( issueLogger.info(
`Closing $$type because it was last updated on: ${LoggerService.cyan( `Closing $$type because it was last updated on: ${LoggerService.cyan(
issue.updated_at issue.updated_at
@@ -640,14 +721,14 @@ export class IssuesProcessor {
issueLogger.info( issueLogger.info(
`Deleting the branch since the option ${issueLogger.createOptionLink( `Deleting the branch since the option ${issueLogger.createOptionLink(
Option.DeleteBranch Option.DeleteBranch
)} was specified` )} is enabled`
); );
await this._deleteBranch(issue); await this._deleteBranch(issue);
this.deletedBranchIssues.push(issue); this.deletedBranchIssues.push(issue);
} }
} else { } else {
issueLogger.info( issueLogger.info(
`Stale $$type is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate})` `Stale $$type is not old enough to close yet (hasComments? ${issueHasCommentsSinceStale}, hasUpdate? ${issueHasUpdateInCloseWindow})`
); );
} }
} }
@@ -669,12 +750,12 @@ export class IssuesProcessor {
} }
// find any comments since the date // find any comments since the date
const comments = await this.listIssueComments(issue.number, sinceDate); const comments = await this.listIssueComments(issue, sinceDate);
const filteredComments = comments.filter( const filteredComments = comments.filter(
comment => comment =>
comment.user.type === 'User' && comment.user?.type === 'User' &&
comment.body.toLowerCase() !== staleMessage.toLowerCase() comment.body?.toLowerCase() !== staleMessage.toLowerCase()
); );
issueLogger.info( issueLogger.info(
@@ -707,10 +788,10 @@ export class IssuesProcessor {
if (!skipMessage) { if (!skipMessage) {
try { try {
this._consumeIssueOperation(issue); this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsComment(issue); this.statistics?.incrementAddedItemsComment(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.createComment({ await this.client.rest.issues.createComment({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@@ -724,11 +805,11 @@ export class IssuesProcessor {
try { try {
this._consumeIssueOperation(issue); this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsLabel(issue); this.statistics?.incrementAddedItemsLabel(issue);
this._statistics?.incrementStaleItemsCount(issue); this.statistics?.incrementStaleItemsCount(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.addLabels({ await this.client.rest.issues.addLabels({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@@ -754,10 +835,11 @@ export class IssuesProcessor {
if (closeMessage) { if (closeMessage) {
try { try {
this._consumeIssueOperation(issue); this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsComment(issue); this.statistics?.incrementAddedItemsComment(issue);
this.addedCloseCommentIssues.push(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.createComment({ await this.client.rest.issues.createComment({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@@ -772,10 +854,10 @@ export class IssuesProcessor {
if (closeLabel) { if (closeLabel) {
try { try {
this._consumeIssueOperation(issue); this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsLabel(issue); this.statistics?.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.addLabels({ await this.client.rest.issues.addLabels({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@@ -789,14 +871,15 @@ export class IssuesProcessor {
try { try {
this._consumeIssueOperation(issue); this._consumeIssueOperation(issue);
this._statistics?.incrementClosedItemsCount(issue); this.statistics?.incrementClosedItemsCount(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.update({ await this.client.rest.issues.update({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
state: 'closed' state: 'closed',
state_reason: this.options.closeIssueReason || undefined
}); });
} }
} catch (error) { } catch (error) {
@@ -804,34 +887,18 @@ export class IssuesProcessor {
} }
} }
private async _getPullRequest(
issue: Issue
): Promise<IPullRequest | undefined | void> {
const issueLogger: IssueLogger = new IssueLogger(issue);
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementFetchedPullRequestsCount();
const pullRequest = await this.client.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number
});
return pullRequest.data;
} catch (error) {
issueLogger.error(`Error when getting this $$type: ${error.message}`);
}
}
// Delete the branch on closed pull request // Delete the branch on closed pull request
private async _deleteBranch(issue: Issue): Promise<void> { private async _deleteBranch(issue: Issue): Promise<void> {
const issueLogger: IssueLogger = new IssueLogger(issue); const issueLogger: IssueLogger = new IssueLogger(issue);
issueLogger.info(`Delete branch from closed $$type - ${issue.title}`); issueLogger.info(`Delete
branch from closed $
$type
-
${issue.title}`);
const pullRequest = await this._getPullRequest(issue); const pullRequest: IPullRequest | undefined | void =
await this.getPullRequest(issue);
if (!pullRequest) { if (!pullRequest) {
issueLogger.info( issueLogger.info(
@@ -847,10 +914,10 @@ export class IssuesProcessor {
try { try {
this._consumeIssueOperation(issue); this._consumeIssueOperation(issue);
this._statistics?.incrementDeletedBranchesCount(); this.statistics?.incrementDeletedBranchesCount();
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.git.deleteRef({ await this.client.rest.git.deleteRef({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
ref: `heads/${branch}` ref: `heads/${branch}`
@@ -882,10 +949,10 @@ export class IssuesProcessor {
try { try {
this._consumeIssueOperation(issue); this._consumeIssueOperation(issue);
this._statistics?.incrementDeletedItemsLabelsCount(issue); this.statistics?.incrementDeletedItemsLabelsCount(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.removeLabel({ await this.client.rest.issues.removeLabel({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@@ -1015,10 +1082,10 @@ export class IssuesProcessor {
this.addedLabelIssues.push(issue); this.addedLabelIssues.push(issue);
try { try {
this.operations.consumeOperation(); this._consumeIssueOperation(issue);
this._statistics?.incrementAddedItemsLabel(issue); this.statistics?.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) { if (!this.options.debugOnly) {
await this.client.issues.addLabels({ await this.client.rest.issues.addLabels({
owner: context.repo.owner, owner: context.repo.owner,
repo: context.repo.repo, repo: context.repo.repo,
issue_number: issue.number, issue_number: issue.number,
@@ -1043,7 +1110,7 @@ export class IssuesProcessor {
); );
await this._removeLabel(issue, staleLabel); await this._removeLabel(issue, staleLabel);
this._statistics?.incrementUndoStaleItemsCount(issue); this.statistics?.incrementUndoStaleItemsCount(issue);
} }
private async _removeCloseLabel( private async _removeCloseLabel(
@@ -1080,7 +1147,7 @@ export class IssuesProcessor {
); );
await this._removeLabel(issue, closeLabel, true); await this._removeLabel(issue, closeLabel, true);
this._statistics?.incrementDeletedCloseItemsLabelsCount(issue); this.statistics?.incrementDeletedCloseItemsLabelsCount(issue);
} else { } else {
issueLogger.info( issueLogger.info(
LoggerService.white('└──'), LoggerService.white('└──'),

View File

@@ -9,28 +9,28 @@ interface IGroupValue {
export class Statistics { export class Statistics {
private readonly _logger: Logger = new Logger(); private readonly _logger: Logger = new Logger();
private _processedIssuesCount = 0; processedIssuesCount = 0;
private _processedPullRequestsCount = 0; processedPullRequestsCount = 0;
private _staleIssuesCount = 0; staleIssuesCount = 0;
private _stalePullRequestsCount = 0; stalePullRequestsCount = 0;
private _undoStaleIssuesCount = 0; undoStaleIssuesCount = 0;
private _undoStalePullRequestsCount = 0; undoStalePullRequestsCount = 0;
private _operationsCount = 0; operationsCount = 0;
private _closedIssuesCount = 0; closedIssuesCount = 0;
private _closedPullRequestsCount = 0; closedPullRequestsCount = 0;
private _deletedIssuesLabelsCount = 0; deletedIssuesLabelsCount = 0;
private _deletedPullRequestsLabelsCount = 0; deletedPullRequestsLabelsCount = 0;
private _deletedCloseIssuesLabelsCount = 0; deletedCloseIssuesLabelsCount = 0;
private _deletedClosePullRequestsLabelsCount = 0; deletedClosePullRequestsLabelsCount = 0;
private _deletedBranchesCount = 0; deletedBranchesCount = 0;
private _addedIssuesLabelsCount = 0; addedIssuesLabelsCount = 0;
private _addedPullRequestsLabelsCount = 0; addedPullRequestsLabelsCount = 0;
private _addedIssuesCommentsCount = 0; addedIssuesCommentsCount = 0;
private _addedPullRequestsCommentsCount = 0; addedPullRequestsCommentsCount = 0;
private _fetchedItemsCount = 0; fetchedItemsCount = 0;
private _fetchedItemsEventsCount = 0; fetchedItemsEventsCount = 0;
private _fetchedItemsCommentsCount = 0; fetchedItemsCommentsCount = 0;
private _fetchedPullRequestsCount = 0; fetchedPullRequestsCount = 0;
incrementProcessedItemsCount( incrementProcessedItemsCount(
issue: Readonly<Issue>, issue: Readonly<Issue>,
@@ -66,7 +66,7 @@ export class Statistics {
} }
setOperationsCount(operationsCount: Readonly<number>): Statistics { setOperationsCount(operationsCount: Readonly<number>): Statistics {
this._operationsCount = operationsCount; this.operationsCount = operationsCount;
return this; return this;
} }
@@ -105,7 +105,7 @@ export class Statistics {
} }
incrementDeletedBranchesCount(increment: Readonly<number> = 1): Statistics { incrementDeletedBranchesCount(increment: Readonly<number> = 1): Statistics {
this._deletedBranchesCount += increment; this.deletedBranchesCount += increment;
return this; return this;
} }
@@ -133,7 +133,7 @@ export class Statistics {
} }
incrementFetchedItemsCount(increment: Readonly<number> = 1): Statistics { incrementFetchedItemsCount(increment: Readonly<number> = 1): Statistics {
this._fetchedItemsCount += increment; this.fetchedItemsCount += increment;
return this; return this;
} }
@@ -141,7 +141,7 @@ export class Statistics {
incrementFetchedItemsEventsCount( incrementFetchedItemsEventsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._fetchedItemsEventsCount += increment; this.fetchedItemsEventsCount += increment;
return this; return this;
} }
@@ -149,7 +149,7 @@ export class Statistics {
incrementFetchedItemsCommentsCount( incrementFetchedItemsCommentsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._fetchedItemsCommentsCount += increment; this.fetchedItemsCommentsCount += increment;
return this; return this;
} }
@@ -157,7 +157,7 @@ export class Statistics {
incrementFetchedPullRequestsCount( incrementFetchedPullRequestsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._fetchedPullRequestsCount += increment; this.fetchedPullRequestsCount += increment;
return this; return this;
} }
@@ -185,7 +185,7 @@ export class Statistics {
private _incrementProcessedIssuesCount( private _incrementProcessedIssuesCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._processedIssuesCount += increment; this.processedIssuesCount += increment;
return this; return this;
} }
@@ -193,7 +193,7 @@ export class Statistics {
private _incrementProcessedPullRequestsCount( private _incrementProcessedPullRequestsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._processedPullRequestsCount += increment; this.processedPullRequestsCount += increment;
return this; return this;
} }
@@ -201,7 +201,7 @@ export class Statistics {
private _incrementStaleIssuesCount( private _incrementStaleIssuesCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._staleIssuesCount += increment; this.staleIssuesCount += increment;
return this; return this;
} }
@@ -209,7 +209,7 @@ export class Statistics {
private _incrementStalePullRequestsCount( private _incrementStalePullRequestsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._stalePullRequestsCount += increment; this.stalePullRequestsCount += increment;
return this; return this;
} }
@@ -217,7 +217,7 @@ export class Statistics {
private _incrementUndoStaleIssuesCount( private _incrementUndoStaleIssuesCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._undoStaleIssuesCount += increment; this.undoStaleIssuesCount += increment;
return this; return this;
} }
@@ -225,7 +225,7 @@ export class Statistics {
private _incrementUndoStalePullRequestsCount( private _incrementUndoStalePullRequestsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._undoStalePullRequestsCount += increment; this.undoStalePullRequestsCount += increment;
return this; return this;
} }
@@ -233,7 +233,7 @@ export class Statistics {
private _incrementClosedIssuesCount( private _incrementClosedIssuesCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._closedIssuesCount += increment; this.closedIssuesCount += increment;
return this; return this;
} }
@@ -241,7 +241,7 @@ export class Statistics {
private _incrementClosedPullRequestsCount( private _incrementClosedPullRequestsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._closedPullRequestsCount += increment; this.closedPullRequestsCount += increment;
return this; return this;
} }
@@ -249,7 +249,7 @@ export class Statistics {
private _incrementDeletedIssuesLabelsCount( private _incrementDeletedIssuesLabelsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._deletedIssuesLabelsCount += increment; this.deletedIssuesLabelsCount += increment;
return this; return this;
} }
@@ -257,7 +257,7 @@ export class Statistics {
private _incrementDeletedPullRequestsLabelsCount( private _incrementDeletedPullRequestsLabelsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._deletedPullRequestsLabelsCount += increment; this.deletedPullRequestsLabelsCount += increment;
return this; return this;
} }
@@ -265,7 +265,7 @@ export class Statistics {
private _incrementDeletedCloseIssuesLabelsCount( private _incrementDeletedCloseIssuesLabelsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._deletedCloseIssuesLabelsCount += increment; this.deletedCloseIssuesLabelsCount += increment;
return this; return this;
} }
@@ -273,7 +273,7 @@ export class Statistics {
private _incrementDeletedClosePullRequestsLabelsCount( private _incrementDeletedClosePullRequestsLabelsCount(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._deletedClosePullRequestsLabelsCount += increment; this.deletedClosePullRequestsLabelsCount += increment;
return this; return this;
} }
@@ -281,7 +281,7 @@ export class Statistics {
private _incrementAddedIssuesLabel( private _incrementAddedIssuesLabel(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._addedIssuesLabelsCount += increment; this.addedIssuesLabelsCount += increment;
return this; return this;
} }
@@ -289,7 +289,7 @@ export class Statistics {
private _incrementAddedPullRequestsLabel( private _incrementAddedPullRequestsLabel(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._addedPullRequestsLabelsCount += increment; this.addedPullRequestsLabelsCount += increment;
return this; return this;
} }
@@ -297,7 +297,7 @@ export class Statistics {
private _incrementAddedIssuesComment( private _incrementAddedIssuesComment(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._addedIssuesCommentsCount += increment; this.addedIssuesCommentsCount += increment;
return this; return this;
} }
@@ -305,7 +305,7 @@ export class Statistics {
private _incrementAddedPullRequestsComment( private _incrementAddedPullRequestsComment(
increment: Readonly<number> = 1 increment: Readonly<number> = 1
): Statistics { ): Statistics {
this._addedPullRequestsCommentsCount += increment; this.addedPullRequestsCommentsCount += increment;
return this; return this;
} }
@@ -314,11 +314,11 @@ export class Statistics {
this._logGroup('Processed items', [ this._logGroup('Processed items', [
{ {
name: 'Processed issues', name: 'Processed issues',
count: this._processedIssuesCount count: this.processedIssuesCount
}, },
{ {
name: 'Processed PRs', name: 'Processed PRs',
count: this._processedPullRequestsCount count: this.processedPullRequestsCount
} }
]); ]);
} }
@@ -327,11 +327,11 @@ export class Statistics {
this._logGroup('New stale items', [ this._logGroup('New stale items', [
{ {
name: 'New stale issues', name: 'New stale issues',
count: this._staleIssuesCount count: this.staleIssuesCount
}, },
{ {
name: 'New stale PRs', name: 'New stale PRs',
count: this._stalePullRequestsCount count: this.stalePullRequestsCount
} }
]); ]);
} }
@@ -340,11 +340,11 @@ export class Statistics {
this._logGroup('No longer stale items', [ this._logGroup('No longer stale items', [
{ {
name: 'No longer stale issues', name: 'No longer stale issues',
count: this._undoStaleIssuesCount count: this.undoStaleIssuesCount
}, },
{ {
name: 'No longer stale PRs', name: 'No longer stale PRs',
count: this._undoStalePullRequestsCount count: this.undoStalePullRequestsCount
} }
]); ]);
} }
@@ -353,11 +353,11 @@ export class Statistics {
this._logGroup('Closed items', [ this._logGroup('Closed items', [
{ {
name: 'Closed issues', name: 'Closed issues',
count: this._closedIssuesCount count: this.closedIssuesCount
}, },
{ {
name: 'Closed PRs', name: 'Closed PRs',
count: this._closedPullRequestsCount count: this.closedPullRequestsCount
} }
]); ]);
} }
@@ -366,11 +366,11 @@ export class Statistics {
this._logGroup('Deleted items labels', [ this._logGroup('Deleted items labels', [
{ {
name: 'Deleted issues labels', name: 'Deleted issues labels',
count: this._deletedIssuesLabelsCount count: this.deletedIssuesLabelsCount
}, },
{ {
name: 'Deleted PRs labels', name: 'Deleted PRs labels',
count: this._deletedPullRequestsLabelsCount count: this.deletedPullRequestsLabelsCount
} }
]); ]);
} }
@@ -379,28 +379,28 @@ export class Statistics {
this._logGroup('Deleted close items labels', [ this._logGroup('Deleted close items labels', [
{ {
name: 'Deleted close issues labels', name: 'Deleted close issues labels',
count: this._deletedCloseIssuesLabelsCount count: this.deletedCloseIssuesLabelsCount
}, },
{ {
name: 'Deleted close PRs labels', name: 'Deleted close PRs labels',
count: this._deletedClosePullRequestsLabelsCount count: this.deletedClosePullRequestsLabelsCount
} }
]); ]);
} }
private _logDeletedBranchesCount(): void { private _logDeletedBranchesCount(): void {
this._logCount('Deleted branches', this._deletedBranchesCount); this._logCount('Deleted branches', this.deletedBranchesCount);
} }
private _logAddedIssuesAndPullRequestsLabelsCount(): void { private _logAddedIssuesAndPullRequestsLabelsCount(): void {
this._logGroup('Added items labels', [ this._logGroup('Added items labels', [
{ {
name: 'Added issues labels', name: 'Added issues labels',
count: this._addedIssuesLabelsCount count: this.addedIssuesLabelsCount
}, },
{ {
name: 'Added PRs labels', name: 'Added PRs labels',
count: this._addedPullRequestsLabelsCount count: this.addedPullRequestsLabelsCount
} }
]); ]);
} }
@@ -409,33 +409,33 @@ export class Statistics {
this._logGroup('Added items comments', [ this._logGroup('Added items comments', [
{ {
name: 'Added issues comments', name: 'Added issues comments',
count: this._addedIssuesCommentsCount count: this.addedIssuesCommentsCount
}, },
{ {
name: 'Added PRs comments', name: 'Added PRs comments',
count: this._addedPullRequestsCommentsCount count: this.addedPullRequestsCommentsCount
} }
]); ]);
} }
private _logFetchedItemsCount(): void { private _logFetchedItemsCount(): void {
this._logCount('Fetched items', this._fetchedItemsCount); this._logCount('Fetched items', this.fetchedItemsCount);
} }
private _logFetchedItemsEventsCount(): void { private _logFetchedItemsEventsCount(): void {
this._logCount('Fetched items events', this._fetchedItemsEventsCount); this._logCount('Fetched items events', this.fetchedItemsEventsCount);
} }
private _logFetchedItemsCommentsCount(): void { private _logFetchedItemsCommentsCount(): void {
this._logCount('Fetched items comments', this._fetchedItemsCommentsCount); this._logCount('Fetched items comments', this.fetchedItemsCommentsCount);
} }
private _logFetchedPullRequestsCount(): void { private _logFetchedPullRequestsCount(): void {
this._logCount('Fetched pull requests', this._fetchedPullRequestsCount); this._logCount('Fetched pull requests', this.fetchedPullRequestsCount);
} }
private _logOperationsCount(): void { private _logOperationsCount(): void {
this._logCount('Operations performed', this._operationsCount); this._logCount('Operations performed', this.operationsCount);
} }
private _logCount(name: Readonly<string>, count: Readonly<number>): void { private _logCount(name: Readonly<string>, count: Readonly<number>): void {

View File

@@ -42,5 +42,10 @@ export enum Option {
ExemptAllPrAssignees = 'exempt-all-pr-assignees', ExemptAllPrAssignees = 'exempt-all-pr-assignees',
EnableStatistics = 'enable-statistics', EnableStatistics = 'enable-statistics',
LabelsToRemoveWhenUnstale = 'labels-to-remove-when-unstale', LabelsToRemoveWhenUnstale = 'labels-to-remove-when-unstale',
LabelsToAddWhenUnstale = 'labels-to-add-when-unstale' LabelsToAddWhenUnstale = 'labels-to-add-when-unstale',
IgnoreUpdates = 'ignore-updates',
IgnoreIssueUpdates = 'ignore-issue-updates',
IgnorePrUpdates = 'ignore-pr-updates',
ExemptDraftPr = 'exempt-draft-pr',
CloseIssueReason = 'close-issue-reason'
} }

View File

@@ -1,5 +1,5 @@
import deburr from 'lodash.deburr'; import deburr from 'lodash.deburr';
import { CleanLabel } from '../types/clean-label'; import {CleanLabel} from '../types/clean-label';
/** /**
* @description * @description
@@ -9,6 +9,6 @@ import { CleanLabel } from '../types/clean-label';
* *
* @return {string} A lowercased, deburred version of the passed in label * @return {string} A lowercased, deburred version of the passed in label
*/ */
export function cleanLabel(label: Readonly<string>): CleanLabel { export function cleanLabel(label?: Readonly<string>): CleanLabel {
return deburr(label.toLowerCase()); return deburr(label?.toLowerCase());
} }

View File

@@ -1,3 +1,11 @@
export interface IAssignee { // @todo improve to include the notion of team?
login: string; interface IAssignee {
} type: string;
}
export interface IUserAssignee extends IAssignee {
login: string;
type: 'User' | string;
}
export type Assignee = IUserAssignee;

View File

@@ -1,6 +1,6 @@
import {IUser} from './user'; import {IUser} from './user';
export interface IComment { export interface IComment {
user: IUser; user: IUser | null;
body: string; body?: string;
} }

View File

@@ -1,17 +1,19 @@
import {IsoDateString} from '../types/iso-date-string'; import {IsoDateString} from '../types/iso-date-string';
import {IAssignee} from './assignee'; import {Assignee} from './assignee';
import {ILabel} from './label'; import {ILabel} from './label';
import {IMilestone} from './milestone'; import {IMilestone} from './milestone';
import {components} from '@octokit/openapi-types';
export interface IIssue { export interface IIssue {
title: string; title: string;
number: number; number: number;
created_at: IsoDateString; created_at: IsoDateString;
updated_at: IsoDateString; updated_at: IsoDateString;
labels: ILabel[]; labels: ILabel[];
pull_request: Object | null | undefined; pull_request?: Object | null;
state: string; state: string;
locked: boolean; locked: boolean;
milestone: IMilestone | undefined; milestone?: IMilestone | null;
assignees: IAssignee[]; assignees?: Assignee[] | null;
} }
export type OctokitIssue = components['schemas']['issue'];

View File

@@ -47,4 +47,9 @@ export interface IIssuesProcessorOptions {
enableStatistics: boolean; enableStatistics: boolean;
labelsToRemoveWhenUnstale: string; labelsToRemoveWhenUnstale: string;
labelsToAddWhenUnstale: string; labelsToAddWhenUnstale: string;
ignoreUpdates: boolean;
ignoreIssueUpdates: boolean | undefined;
ignorePrUpdates: boolean | undefined;
exemptDraftPr: boolean;
closeIssueReason: string;
} }

View File

@@ -1,3 +1,3 @@
export interface ILabel { export interface ILabel {
name: string; name?: string;
} }

View File

@@ -3,4 +3,5 @@ export interface IPullRequest {
head: { head: {
ref: string; ref: string;
}; };
draft?: boolean;
} }

View File

@@ -57,10 +57,10 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
core.getInput('remove-stale-when-updated') === 'false' core.getInput('remove-stale-when-updated') === 'false'
), ),
removeIssueStaleWhenUpdated: _toOptionalBoolean( removeIssueStaleWhenUpdated: _toOptionalBoolean(
core.getInput('remove-issue-stale-when-updated') 'remove-issue-stale-when-updated'
), ),
removePrStaleWhenUpdated: _toOptionalBoolean( removePrStaleWhenUpdated: _toOptionalBoolean(
core.getInput('remove-pr-stale-when-updated') 'remove-pr-stale-when-updated'
), ),
debugOnly: core.getInput('debug-only') === 'true', debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true', ascending: core.getInput('ascending') === 'true',
@@ -83,7 +83,12 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
exemptAllPrAssignees: _toOptionalBoolean('exempt-all-pr-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'), labelsToRemoveWhenUnstale: core.getInput('labels-to-remove-when-unstale'),
labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale') labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale'),
ignoreUpdates: core.getInput('ignore-updates') === 'true',
ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'),
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
exemptDraftPr: core.getInput('exempt-draft-pr') === 'true',
closeIssueReason: core.getInput('close-issue-reason')
}; };
for (const numberInput of [ for (const numberInput of [
@@ -109,6 +114,15 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
} }
} }
const validCloseReasons = ['', 'completed', 'not_planned'];
if (!validCloseReasons.includes(args.closeIssueReason)) {
const errorMessage = `Unrecognized close-issue-reason "${
args.closeIssueReason
}", valid values are: ${validCloseReasons.filter(Boolean).join(', ')}`;
core.setFailed(errorMessage);
throw new Error(errorMessage);
}
return args; return args;
} }
@@ -120,6 +134,17 @@ async function processOutput(
core.setOutput('closed-issues-prs', JSON.stringify(closedIssues)); core.setOutput('closed-issues-prs', JSON.stringify(closedIssues));
} }
/**
* @description
* From an argument name, get the value as an optional boolean
* This is very useful for all the arguments that override others
* It will allow us to easily use the original one when the return value is `undefined`
* Which is different from `true` or `false` that consider the argument as set
*
* @param {Readonly<string>} argumentName The name of the argument to check
*
* @returns {boolean | undefined} The value matching the given argument name
*/
function _toOptionalBoolean( function _toOptionalBoolean(
argumentName: Readonly<string> argumentName: Readonly<string>
): boolean | undefined { ): boolean | undefined {