mirror of
https://github.com/actions/stale.git
synced 2025-12-23 08:58:17 +00:00
Compare commits
41 Commits
v4-testing
...
v4.1.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7fb802b307 | ||
|
|
54197c7137 | ||
|
|
3a971aeb80 | ||
|
|
fc4a5ff942 | ||
|
|
db699ab3b1 | ||
|
|
f8e08de81b | ||
|
|
b83d488cb9 | ||
|
|
1ff6cd74cb | ||
|
|
86fed0e1f1 | ||
|
|
67004407a6 | ||
|
|
b9a40762bf | ||
|
|
bab816b473 | ||
|
|
6299c36a0d | ||
|
|
a8c5bb1c29 | ||
|
|
1c81c38e2f | ||
|
|
f6a70aa856 | ||
|
|
315391885d | ||
|
|
4665995b65 | ||
|
|
b80ae639fa | ||
|
|
3021a55a47 | ||
|
|
b98591d49e | ||
|
|
9912fa74d1 | ||
|
|
303465a5d2 | ||
|
|
dee9af8160 | ||
|
|
31d06d7a0a | ||
|
|
fcb25faea2 | ||
|
|
9dee5c72d9 | ||
|
|
0aa6030913 | ||
|
|
5aa0d3ef84 | ||
|
|
1cdda06bb3 | ||
|
|
002bc97450 | ||
|
|
2e221262b1 | ||
|
|
27d80e173f | ||
|
|
86507610fb | ||
|
|
ceeedec52e | ||
|
|
0156089d02 | ||
|
|
cdf15f641a | ||
|
|
a78d0b721e | ||
|
|
d901397e11 | ||
|
|
678bfc7a59 | ||
|
|
4b47cddc05 |
51
.github/workflows/check-dist.yml
vendored
Normal file
51
.github/workflows/check-dist.yml
vendored
Normal file
@@ -0,0 +1,51 @@
|
||||
# `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@v2
|
||||
|
||||
- name: Set Node.js 12.x
|
||||
uses: actions/setup-node@v1
|
||||
with:
|
||||
node-version: 12.x
|
||||
|
||||
- name: Install dependencies
|
||||
run: npm ci
|
||||
|
||||
- name: Rebuild the dist/ directory
|
||||
run: npm run build
|
||||
|
||||
- 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@v2
|
||||
if: ${{ failure() && steps.diff.conclusion == 'failure' }}
|
||||
with:
|
||||
name: dist
|
||||
path: dist/
|
||||
2
.github/workflows/test.yml
vendored
2
.github/workflows/test.yml
vendored
@@ -13,7 +13,7 @@ jobs:
|
||||
- uses: actions/checkout@v2
|
||||
- run: |
|
||||
npm ci
|
||||
npm run all
|
||||
npm run all:ci
|
||||
test: # make sure the action works on a clean machine without building
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
|
||||
31
CHANGELOG.md
Normal file
31
CHANGELOG.md
Normal file
@@ -0,0 +1,31 @@
|
||||
# Changelog
|
||||
|
||||
## [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
|
||||
)
|
||||
|
||||
---
|
||||
Starting in version 4.0.0 we will maintain a changelog
|
||||
|
||||
## [4.0.0](https://github.com/actions/stale/compare/v3.0.19...v4.0.0) (2021-07-14)
|
||||
|
||||
### Features
|
||||
|
||||
- **options:** simplify config by removing skip stale message options ([#457](https://github.com/actions/stale/issues/457)) ([6ec637d](https://github.com/actions/stale/commit/6ec637d238067ab8cc96c9289dcdac280bbd3f4a)), closes [#405](https://github.com/actions/stale/issues/405) [#455](https://github.com/actions/stale/issues/455)
|
||||
- **output:** print output parameters ([#458](https://github.com/actions/stale/issues/458)) ([3e6d35b](https://github.com/actions/stale/commit/3e6d35b685f0b2fa1a69be893fa07d3d85e05ee0))
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
- **dry-run:** forbid mutations in dry-run ([#500](https://github.com/actions/stale/issues/500)) ([f1017f3](https://github.com/actions/stale/commit/f1017f33dd159ea51366375120c3e6981d7c3097)), closes [#499](https://github.com/actions/stale/issues/499)
|
||||
- **logs:** coloured logs ([#465](https://github.com/actions/stale/issues/465)) ([5fbbfba](https://github.com/actions/stale/commit/5fbbfba142860ea6512549e96e36e3540c314132))
|
||||
- **operations:** fail fast the current batch to respect the operations limit ([#474](https://github.com/actions/stale/issues/474)) ([5f6f311](https://github.com/actions/stale/commit/5f6f311ca6aa75babadfc7bac6edf5d85fa3f35d)), closes [#466](https://github.com/actions/stale/issues/466)
|
||||
- **label comparison**: make label comparison case insensitive [#517](https://github.com/actions/stale/pull/517), closes [#516](https://github.com/actions/stale/pull/516)
|
||||
- **filtering comments by actor could have strange behavior**: "stale" comments are now detected based on if the message is the stale message not _who_ made the comment([#519](https://github.com/actions/stale/pull/519)), fixes [#441](https://github.com/actions/stale/pull/441), [#509](https://github.com/actions/stale/pull/509), [#518](https://github.com/actions/stale/pull/518)
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
- The options `skip-stale-issue-message` and `skip-stale-pr-message` were removed. Instead, setting the options `stale-issue-message` and `stale-pr-message` will be enough to let the stale workflow add a comment. If the options are unset, a comment will not be added which was the equivalent of setting `skip-stale-issue-message` to `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.
|
||||
189
README.md
189
README.md
@@ -2,26 +2,17 @@
|
||||
|
||||
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
|
||||
- If an update/comment occur on stale issues or pull requests, the stale label will be removed and the timer will restart
|
||||
|
||||
## Recommended permissions
|
||||
|
||||
For the execution of this action, it must be able to fetch all issues and pull requests from your repository.
|
||||
This can be achieved with the following [configuration in the action](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#permissions) if the permissions are restricted:
|
||||
|
||||
```yaml
|
||||
permissions:
|
||||
issues: read
|
||||
pull-requests: read
|
||||
```
|
||||
|
||||
In addition, based on the provided configuration, the action could require more permission(s) (e.g.: add label, remove label, comment, close, etc.).
|
||||
You can find more information about the required permissions under the corresponding options that you wish to use.
|
||||
However, if don't want to bother, you can use these permissions:
|
||||
This can be achieved with the following [configuration in the action](https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#permissions) if the permissions are restricted:
|
||||
|
||||
```yaml
|
||||
permissions:
|
||||
@@ -29,67 +20,73 @@ permissions:
|
||||
pull-requests: write
|
||||
```
|
||||
|
||||
You can find more information about the required permissions under the corresponding options that you wish to use.
|
||||
|
||||
## All options
|
||||
|
||||
### List of input options
|
||||
|
||||
Every argument is optional.
|
||||
|
||||
| Input | Description | Default |
|
||||
| ------------------------------------------------------------------- | ------------------------------------------------------------------------ | --------------------- |
|
||||
| [repo-token](#repo-token) | PAT for GitHub API authentication | `${{ github.token }}` |
|
||||
| [days-before-stale](#days-before-stale) | Idle number of days before marking issues/PRs stale | `60` |
|
||||
| [days-before-issue-stale](#days-before-issue-stale) | Override [days-before-stale](#days-before-stale) for issues only | |
|
||||
| [days-before-pr-stale](#days-before-pr-stale) | Override [days-before-stale](#days-before-stale) for PRs only | |
|
||||
| [days-before-close](#days-before-close) | Idle number of days before closing stale issues/PRs | `7` |
|
||||
| [days-before-issue-close](#days-before-issue-close) | Override [days-before-close](#days-before-close) for issues only | |
|
||||
| [days-before-pr-close](#days-before-pr-close) | Override [days-before-close](#days-before-close) for PRs only | |
|
||||
| [stale-issue-message](#stale-issue-message) | Comment on the staled issues | |
|
||||
| [stale-pr-message](#stale-pr-message) | Comment on the staled PRs | |
|
||||
| [close-issue-message](#close-issue-message) | Comment on the staled issues while closed | |
|
||||
| [close-pr-message](#close-pr-message) | Comment on the staled PRs while closed | |
|
||||
| [stale-issue-label](#stale-issue-label) | Label to apply on staled issues | `Stale` |
|
||||
| [close-issue-label](#close-issue-label) | Label to apply on closed issues | |
|
||||
| [stale-pr-label](#stale-pr-label) | Label to apply on staled PRs | `Stale` |
|
||||
| [close-pr-label](#close-pr-label) | Label to apply on closed PRs | |
|
||||
| [exempt-issue-labels](#exempt-issue-labels) | Labels on issues exempted from stale | |
|
||||
| [exempt-pr-labels](#exempt-pr-labels) | Labels on PRs exempted from stale | |
|
||||
| [only-labels](#only-labels) | Only issues/PRs with ALL these labels are checked | |
|
||||
| [only-issue-labels](#only-issue-labels) | Only issues with ALL these labels are checked | |
|
||||
| [only-pr-labels](#only-pr-labels) | Only PRs with ALL these labels are checked | |
|
||||
| [any-of-labels](#any-of-labels) | Only issues/PRs with ANY of these labels are checked | |
|
||||
| [any-of-issue-labels](#any-of-issue-labels) | Only issues with ANY of these labels are checked | |
|
||||
| [any-of-pr-labels](#any-of-pr-labels) | Only PRs with ANY of these labels are checked | |
|
||||
| [operations-per-run](#operations-per-run) | Max number of operations per run | `30` |
|
||||
| [remove-stale-when-updated](#remove-stale-when-updated) | Remove stale label from issues/PRs on updates/comments | `true` |
|
||||
| [remove-issue-stale-when-updated](#remove-issue-stale-when-updated) | Remove stale label from issues on updates/comments | |
|
||||
| [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | |
|
||||
| [labels-to-add-when-unstale](#labels-to-add-when-unstale) | Add specified labels from issues/PRs when they become unstale | |
|
||||
| [labels-to-remove-when-unstale](#labels-to-remove-when-unstale) | Remove specified labels from issues/PRs when they become unstale | |
|
||||
| [debug-only](#debug-only) | Dry-run | `false` |
|
||||
| [ascending](#ascending) | Order to get issues/PRs | `false` |
|
||||
| [start-date](#start-date) | Skip stale action for issues/PRs created before it | |
|
||||
| [delete-branch](#delete-branch) | Delete branch after closing a stale PR | `false` |
|
||||
| [exempt-milestones](#exempt-milestones) | Milestones on issues/PRs exempted from stale | |
|
||||
| [exempt-issue-milestones](#exempt-issue-milestones) | Override [exempt-milestones](#exempt-milestones) for issues only | |
|
||||
| [exempt-pr-milestones](#exempt-pr-milestones) | Override [exempt-milestones](#exempt-milestones) for PRs only | |
|
||||
| [exempt-all-milestones](#exempt-all-milestones) | Exempt all issues/PRs with milestones from stale | |
|
||||
| [exempt-all-issue-milestones](#exempt-all-issue-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for issues only | |
|
||||
| [exempt-all-pr-milestones](#exempt-all-pr-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for PRs only | |
|
||||
| [exempt-assignees](#exempt-assignees) | Assignees on issues/PRs exempted from stale | |
|
||||
| [exempt-issue-assignees](#exempt-issue-assignees) | Override [exempt-assignees](#exempt-assignees) for issues only | |
|
||||
| [exempt-pr-assignees](#exempt-pr-assignees) | Override [exempt-assignees](#exempt-assignees) for PRs only | |
|
||||
| [exempt-all-assignees](#exempt-all-assignees) | Exempt all issues/PRs with assignees from stale | |
|
||||
| [exempt-all-issue-assignees](#exempt-all-issue-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for issues only | |
|
||||
| [exempt-all-pr-assignees](#exempt-all-pr-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for PRs only | |
|
||||
| [enable-statistics](#enable-statistics) | Display statistics in the logs | `true` |
|
||||
| Input | Description | Default |
|
||||
| ------------------------------------------------------------------- | --------------------------------------------------------------------------- | --------------------- |
|
||||
| [repo-token](#repo-token) | PAT for GitHub API authentication | `${{ github.token }}` |
|
||||
| [days-before-stale](#days-before-stale) | Idle number of days before marking issues/PRs stale | `60` |
|
||||
| [days-before-issue-stale](#days-before-issue-stale) | Override [days-before-stale](#days-before-stale) for issues only | |
|
||||
| [days-before-pr-stale](#days-before-pr-stale) | Override [days-before-stale](#days-before-stale) for PRs only | |
|
||||
| [days-before-close](#days-before-close) | Idle number of days before closing stale issues/PRs | `7` |
|
||||
| [days-before-issue-close](#days-before-issue-close) | Override [days-before-close](#days-before-close) for issues only | |
|
||||
| [days-before-pr-close](#days-before-pr-close) | Override [days-before-close](#days-before-close) for PRs only | |
|
||||
| [stale-issue-message](#stale-issue-message) | Comment on the staled issues | |
|
||||
| [stale-pr-message](#stale-pr-message) | Comment on the staled PRs | |
|
||||
| [close-issue-message](#close-issue-message) | Comment on the staled issues while closed | |
|
||||
| [close-pr-message](#close-pr-message) | Comment on the staled PRs while closed | |
|
||||
| [stale-issue-label](#stale-issue-label) | Label to apply on staled issues | `Stale` |
|
||||
| [close-issue-label](#close-issue-label) | Label to apply on closed issues | |
|
||||
| [stale-pr-label](#stale-pr-label) | Label to apply on staled PRs | `Stale` |
|
||||
| [close-pr-label](#close-pr-label) | Label to apply on closed PRs | |
|
||||
| [exempt-issue-labels](#exempt-issue-labels) | Labels on issues exempted from stale | |
|
||||
| [exempt-pr-labels](#exempt-pr-labels) | Labels on PRs exempted from stale | |
|
||||
| [only-labels](#only-labels) | Only issues/PRs with ALL these labels are checked | |
|
||||
| [only-issue-labels](#only-issue-labels) | Override [only-labels](#only-labels) for issues only | |
|
||||
| [only-pr-labels](#only-pr-labels) | Override [only-labels](#only-labels) for PRs only | |
|
||||
| [any-of-labels](#any-of-labels) | Only issues/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 | |
|
||||
| [any-of-pr-labels](#any-of-pr-labels) | Override [any-of-labels](#any-of-labels) for PRs only | |
|
||||
| [operations-per-run](#operations-per-run) | Max number of operations per run | `30` |
|
||||
| [remove-stale-when-updated](#remove-stale-when-updated) | Remove stale label from issues/PRs on updates | `true` |
|
||||
| [remove-issue-stale-when-updated](#remove-issue-stale-when-updated) | Remove stale label from issues on updates/comments | |
|
||||
| [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | |
|
||||
| [labels-to-add-when-unstale](#labels-to-add-when-unstale) | Add specified labels from issues/PRs when they become unstale | |
|
||||
| [labels-to-remove-when-unstale](#labels-to-remove-when-unstale) | Remove specified labels from issues/PRs when they become unstale | |
|
||||
| [debug-only](#debug-only) | Dry-run | `false` |
|
||||
| [ascending](#ascending) | Order to get issues/PRs | `false` |
|
||||
| [start-date](#start-date) | Skip stale action for issues/PRs created before it | |
|
||||
| [delete-branch](#delete-branch) | Delete branch after closing a stale PR | `false` |
|
||||
| [exempt-milestones](#exempt-milestones) | Milestones on issues/PRs exempted from stale | |
|
||||
| [exempt-issue-milestones](#exempt-issue-milestones) | Override [exempt-milestones](#exempt-milestones) for issues only | |
|
||||
| [exempt-pr-milestones](#exempt-pr-milestones) | Override [exempt-milestones](#exempt-milestones) for PRs only | |
|
||||
| [exempt-all-milestones](#exempt-all-milestones) | Exempt all issues/PRs with milestones from stale | `false` |
|
||||
| [exempt-all-issue-milestones](#exempt-all-issue-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for issues only | |
|
||||
| [exempt-all-pr-milestones](#exempt-all-pr-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for PRs only | |
|
||||
| [exempt-assignees](#exempt-assignees) | Assignees on issues/PRs exempted from stale | |
|
||||
| [exempt-issue-assignees](#exempt-issue-assignees) | Override [exempt-assignees](#exempt-assignees) for issues only | |
|
||||
| [exempt-pr-assignees](#exempt-pr-assignees) | Override [exempt-assignees](#exempt-assignees) for PRs only | |
|
||||
| [exempt-all-assignees](#exempt-all-assignees) | Exempt all issues/PRs with assignees from stale | `false` |
|
||||
| [exempt-all-issue-assignees](#exempt-all-issue-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for issues only | |
|
||||
| [exempt-all-pr-assignees](#exempt-all-pr-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for PRs only | |
|
||||
| [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
|
||||
|
||||
| Output | Description |
|
||||
| ----------------- | -------------------------------------------- |
|
||||
| staled-issues-prs | List of all staled issues and pull requests. |
|
||||
| closed-issues-prs | List of all closed issues and pull requests. |
|
||||
| Output | Description |
|
||||
| ----------------- | ------------------------------------------- |
|
||||
| staled-issues-prs | List of all staled issues and pull requests |
|
||||
| closed-issues-prs | List of all closed issues and pull requests |
|
||||
|
||||
### Detailed options
|
||||
|
||||
@@ -103,7 +100,9 @@ Default value: `${{ github.token }}`
|
||||
#### days-before-stale
|
||||
|
||||
The idle number of days before marking the issues or the pull requests as stale (by adding a label).
|
||||
The issues or the pull requests will be marked as stale if the last update (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`) is older than the idle number of days.
|
||||
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.
|
||||
In that case, you can still add the stale label manually to mark as stale.
|
||||
@@ -129,6 +128,7 @@ You can fine tune which issues or pull requests should be marked as stale based
|
||||
- [exempt-all-milestones](#exempt-all-milestones)
|
||||
- [exempt-assignees](#exempt-assignees)
|
||||
- [exempt-all-assignees](#exempt-all-assignees)
|
||||
- [ignore-updates](#ignore-updates)
|
||||
|
||||
Default value: `60`
|
||||
|
||||
@@ -175,7 +175,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.
|
||||
|
||||
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
|
||||
Required Permission: `issues: write`
|
||||
@@ -184,7 +184,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.
|
||||
|
||||
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
|
||||
Required Permission: `pull-requests: write`
|
||||
@@ -473,6 +473,14 @@ Override [exempt-all-assignees](#exempt-all-assignees) but only to exempt the pu
|
||||
|
||||
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
|
||||
|
||||
Collects and display statistics at the end of the stale workflow logs to get a summary of what happened during the run.
|
||||
@@ -480,6 +488,27 @@ This option is only useful if the debug output secret `ACTIONS_STEP_DEBUG` is se
|
||||
|
||||
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
|
||||
|
||||
See also [action.yml](./action.yml) for a comprehensive list of all the options.
|
||||
@@ -496,7 +525,7 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v4
|
||||
with:
|
||||
stale-issue-message: 'Message to comment on stale issues. If none provided, will not mark issues stale'
|
||||
stale-pr-message: 'Message to comment on stale PRs. If none provided, will not mark PRs stale'
|
||||
@@ -514,7 +543,7 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v4
|
||||
with:
|
||||
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
|
||||
days-before-stale: 30
|
||||
@@ -533,9 +562,8 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v4
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
|
||||
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.'
|
||||
close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.'
|
||||
@@ -556,9 +584,8 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v4
|
||||
with:
|
||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
|
||||
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.'
|
||||
close-issue-message: 'This issue was closed because it has been stalled for 5 days with no activity.'
|
||||
@@ -581,7 +608,7 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v4
|
||||
with:
|
||||
stale-issue-message: 'Stale issue message'
|
||||
stale-pr-message: 'Stale pull request message'
|
||||
@@ -604,9 +631,9 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v4
|
||||
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:
|
||||
@@ -621,7 +648,7 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v4
|
||||
with:
|
||||
exempt-issue-milestones: 'future,alpha,beta'
|
||||
exempt-pr-milestones: 'bugfix,improvement'
|
||||
@@ -639,7 +666,7 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v4
|
||||
with:
|
||||
exempt-all-pr-milestones: true
|
||||
```
|
||||
@@ -656,7 +683,7 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v4
|
||||
with:
|
||||
any-of-labels: 'needs-more-info,needs-demo'
|
||||
# You can opt for 'only-labels' instead if your use-case requires all labels
|
||||
@@ -675,7 +702,7 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v4
|
||||
with:
|
||||
exempt-issue-assignees: 'marco,polo'
|
||||
exempt-pr-assignees: 'marco'
|
||||
@@ -693,7 +720,7 @@ jobs:
|
||||
stale:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/stale@v3
|
||||
- uses: actions/stale@v4
|
||||
with:
|
||||
exempt-all-pr-assignees: true
|
||||
```
|
||||
|
||||
@@ -8,7 +8,7 @@ import {generateIssue} from './functions/generate-issue';
|
||||
let issuesProcessorBuilder: IssuesProcessorBuilder;
|
||||
let issuesProcessor: IssuesProcessorMock;
|
||||
|
||||
describe('any-of-labels option', (): void => {
|
||||
describe('any-of-labels options', (): void => {
|
||||
beforeEach((): void => {
|
||||
issuesProcessorBuilder = new IssuesProcessorBuilder();
|
||||
});
|
||||
@@ -1139,7 +1139,6 @@ class IssuesProcessorBuilder {
|
||||
build(): IssuesProcessorMock {
|
||||
return new IssuesProcessorMock(
|
||||
this._options,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? this._issues : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
|
||||
@@ -48,7 +48,6 @@ describe('assignees options', (): void => {
|
||||
const setProcessor = () => {
|
||||
processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? testIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
|
||||
@@ -2,11 +2,11 @@ import {Issue} from '../../src/classes/issue';
|
||||
import {IssuesProcessor} from '../../src/classes/issues-processor';
|
||||
import {IComment} from '../../src/interfaces/comment';
|
||||
import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options';
|
||||
import {IPullRequest} from '../../src/interfaces/pull-request';
|
||||
|
||||
export class IssuesProcessorMock extends IssuesProcessor {
|
||||
constructor(
|
||||
options: IIssuesProcessorOptions,
|
||||
getActor?: () => Promise<string>,
|
||||
getIssues?: (page: number) => Promise<Issue[]>,
|
||||
listIssueComments?: (
|
||||
issueNumber: number,
|
||||
@@ -15,14 +15,11 @@ export class IssuesProcessorMock extends IssuesProcessor {
|
||||
getLabelCreationDate?: (
|
||||
issue: Issue,
|
||||
label: string
|
||||
) => Promise<string | undefined>
|
||||
) => Promise<string | undefined>,
|
||||
getPullRequest?: (issue: Issue) => Promise<IPullRequest | undefined | void>
|
||||
) {
|
||||
super(options);
|
||||
|
||||
if (getActor) {
|
||||
this.getActor = getActor;
|
||||
}
|
||||
|
||||
if (getIssues) {
|
||||
this.getIssues = getIssues;
|
||||
}
|
||||
@@ -34,5 +31,9 @@ export class IssuesProcessorMock extends IssuesProcessor {
|
||||
if (getLabelCreationDate) {
|
||||
this.getLabelCreationDate = getLabelCreationDate;
|
||||
}
|
||||
|
||||
if (getPullRequest) {
|
||||
this.getPullRequest = getPullRequest;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,5 +46,9 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
|
||||
exemptAllPrAssignees: undefined,
|
||||
enableStatistics: true,
|
||||
labelsToRemoveWhenUnstale: '',
|
||||
labelsToAddWhenUnstale: ''
|
||||
labelsToAddWhenUnstale: '',
|
||||
ignoreUpdates: false,
|
||||
ignoreIssueUpdates: undefined,
|
||||
ignorePrUpdates: undefined,
|
||||
exemptDraftPr: false
|
||||
});
|
||||
|
||||
139
__tests__/exempt-draft-pr.spec.ts
Normal file
139
__tests__/exempt-draft-pr.spec.ts
Normal 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'
|
||||
}
|
||||
});
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
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 {IsoDateString} from '../../src/types/iso-date-string';
|
||||
|
||||
@@ -32,9 +32,10 @@ export function generateIssue(
|
||||
title: milestone
|
||||
}
|
||||
: undefined,
|
||||
assignees: assignees.map((assignee: Readonly<string>): IAssignee => {
|
||||
assignees: assignees.map((assignee: Readonly<string>): IUserAssignee => {
|
||||
return {
|
||||
login: assignee
|
||||
login: assignee,
|
||||
type: 'User'
|
||||
};
|
||||
})
|
||||
});
|
||||
|
||||
@@ -16,7 +16,6 @@ test('processing an issue with no label will make it stale and close it, if it i
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -48,7 +47,6 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -80,7 +78,6 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -112,7 +109,6 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -144,7 +140,6 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -176,7 +171,6 @@ test('processing an issue with no label and a start date as ISO 8601 being befor
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -208,7 +202,6 @@ test('processing an issue with no label and a start date as ISO 8601 being after
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -240,7 +233,6 @@ test('processing an issue with no label and a start date as RFC 2822 being befor
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -272,7 +264,6 @@ test('processing an issue with no label and a start date as RFC 2822 being after
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -296,7 +287,6 @@ test('processing an issue with no label will make it stale and close it, if it i
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -321,7 +311,6 @@ test('processing an issue with no label will make it stale and not close it, if
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -344,7 +333,6 @@ test('processing an issue with no label will make it stale and not close it if d
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -368,7 +356,6 @@ test('processing an issue with no label will make it stale and not close it if d
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -392,7 +379,6 @@ test('processing an issue with no label will not make it stale if days-before-st
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -417,7 +403,6 @@ test('processing an issue with no label will not make it stale if days-before-st
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -445,7 +430,6 @@ test('processing an issue with no label will make it stale but not close it', as
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -476,7 +460,6 @@ test('processing a stale issue will close it', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -507,7 +490,6 @@ test('processing a stale issue containing a space in the label will close it', a
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -538,7 +520,6 @@ test('processing a stale issue containing a slash in the label will close it', a
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -570,7 +551,6 @@ test('processing a stale issue will close it when days-before-issue-stale overri
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -601,7 +581,6 @@ test('processing a stale PR will close it', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -633,7 +612,6 @@ test('processing a stale PR will close it when days-before-pr-stale override day
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -665,7 +643,6 @@ test('processing a stale issue will close it even if configured not to mark as s
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -698,7 +675,6 @@ test('processing a stale issue will close it even if configured not to mark as s
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -730,7 +706,6 @@ test('processing a stale PR will close it even if configured not to mark as stal
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -763,7 +738,6 @@ test('processing a stale PR will close it even if configured not to mark as stal
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -791,7 +765,6 @@ test('closed issues will not be marked stale', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => []
|
||||
);
|
||||
@@ -818,7 +791,6 @@ test('stale closed issues will not be closed', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -846,7 +818,6 @@ test('closed prs will not be marked stale', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -874,7 +845,6 @@ test('stale closed prs will not be closed', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -901,10 +871,8 @@ test('locked issues will not be marked stale', async () => {
|
||||
true
|
||||
)
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : [])
|
||||
const processor = new IssuesProcessorMock(DefaultProcessorOptions, async p =>
|
||||
p === 1 ? TestIssueList : []
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -930,7 +898,6 @@ test('stale locked issues will not be closed', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -957,10 +924,8 @@ test('locked prs will not be marked stale', async () => {
|
||||
true
|
||||
)
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : [])
|
||||
const processor = new IssuesProcessorMock(DefaultProcessorOptions, async p =>
|
||||
p === 1 ? TestIssueList : []
|
||||
);
|
||||
|
||||
// process our fake issue list
|
||||
@@ -986,7 +951,6 @@ test('stale locked prs will not be closed', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1016,7 +980,6 @@ test('exempt issue labels will not be marked stale', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1046,7 +1009,6 @@ test('exempt issue labels will not be marked stale (multi issue label with space
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1075,7 +1037,6 @@ test('exempt issue labels will not be marked stale (multi issue label)', async (
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1122,7 +1083,6 @@ test('exempt pr labels will not be marked stale', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1151,14 +1111,14 @@ test('exempt issue labels will not be marked stale and will remove the existing
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [
|
||||
{
|
||||
user: {
|
||||
login: 'notme',
|
||||
type: 'User'
|
||||
}
|
||||
},
|
||||
body: 'Body'
|
||||
}
|
||||
], // return a fake comment to indicate there was an update
|
||||
async () => new Date().toDateString()
|
||||
@@ -1206,7 +1166,6 @@ test('stale issues should not be closed if days is set to -1', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1234,14 +1193,14 @@ test('stale label should be removed if a comment was added to a stale issue', as
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [
|
||||
{
|
||||
user: {
|
||||
login: 'notme',
|
||||
type: 'User'
|
||||
}
|
||||
},
|
||||
body: 'Body'
|
||||
}
|
||||
], // return a fake comment to indicate there was an update
|
||||
async () => new Date().toDateString()
|
||||
@@ -1275,14 +1234,14 @@ test('when the option "labelsToAddWhenUnstale" is set, the labels should be adde
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [
|
||||
{
|
||||
user: {
|
||||
login: 'notme',
|
||||
type: 'User'
|
||||
}
|
||||
},
|
||||
body: 'Body'
|
||||
}
|
||||
], // return a fake comment to indicate there was an update
|
||||
async () => new Date().toDateString()
|
||||
@@ -1315,14 +1274,14 @@ test('stale label should not be removed if a comment was added by the bot (and t
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [
|
||||
{
|
||||
user: {
|
||||
login: 'abot',
|
||||
type: 'User'
|
||||
}
|
||||
},
|
||||
body: 'This issue is stale'
|
||||
}
|
||||
], // return a fake comment to indicate there was an update by the bot
|
||||
async () => new Date().toDateString()
|
||||
@@ -1355,9 +1314,8 @@ test('stale label containing a space should be removed if a comment was added to
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [{user: {login: 'notme', type: 'User'}}], // return a fake comment to indicate there was an update
|
||||
async () => [{user: {login: 'notme', type: 'User'}, body: 'Body'}], // return a fake comment to indicate there was an update
|
||||
async () => new Date().toDateString()
|
||||
);
|
||||
|
||||
@@ -1387,7 +1345,6 @@ test('stale issues should not be closed until after the closed number of days',
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1420,7 +1377,6 @@ test('stale issues should be closed if the closed nubmer of days (additive) is a
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1452,7 +1408,6 @@ test('stale issues should not be closed until after the closed number of days (l
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1485,7 +1440,6 @@ test('skips stale message on issues when stale-issue-message is empty', async ()
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1530,7 +1484,6 @@ test('send stale message on issues when stale-issue-message is not empty', async
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1575,7 +1528,6 @@ test('skips stale message on prs when stale-pr-message is empty', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1620,7 +1572,6 @@ test('send stale message on prs when stale-pr-message is not empty', async () =>
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1662,7 +1613,6 @@ test('git branch is deleted when option is enabled', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1692,7 +1642,6 @@ test('git branch is not deleted when issue is not pull request', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1724,7 +1673,6 @@ test('an issue without a milestone will be marked as stale', async () => {
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
DefaultProcessorOptions,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1758,7 +1706,6 @@ test('an issue without an exempted milestone will be marked as stale', async ()
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1792,7 +1739,6 @@ test('an issue with an exempted milestone will not be marked as stale', async ()
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1826,7 +1772,6 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1860,7 +1805,6 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1895,7 +1839,6 @@ test('an issue with an exempted milestone but without an exempted issue mileston
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1930,7 +1873,6 @@ test('an issue with an exempted milestone but with another exempted issue milest
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1965,7 +1907,6 @@ test('an issue with an exempted milestone and with an exempted issue milestone w
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -1993,7 +1934,6 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -2020,7 +1960,6 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -2047,7 +1986,6 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -2081,7 +2019,6 @@ test('processing a pull request opened since 2 days and with the option "daysBef
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -2115,7 +2052,6 @@ test('processing a pull request opened since 2 days and with the option "daysBef
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -2149,7 +2085,6 @@ test('processing a pull request opened since 2 days and with the option "daysBef
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -2186,7 +2121,6 @@ test('processing a previously closed issue with a close label will remove the cl
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -2222,7 +2156,6 @@ test('processing a closed issue with a close label will not remove the close lab
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -2258,7 +2191,6 @@ test('processing a locked issue with a close label will not remove the close lab
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
@@ -2298,7 +2230,6 @@ test('processing an issue stale since less than the daysBeforeStale with a stale
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async (): Promise<IComment[]> => Promise.resolve([]),
|
||||
async () => labelCreatedAt.toDateString()
|
||||
@@ -2339,7 +2270,6 @@ test('processing an issue stale since less than the daysBeforeStale without a st
|
||||
];
|
||||
const processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? TestIssueList : []),
|
||||
async (): Promise<IComment[]> => Promise.resolve([]),
|
||||
async () => new Date().toDateString()
|
||||
@@ -2352,3 +2282,73 @@ test('processing an issue stale since less than the daysBeforeStale without a st
|
||||
expect(processor.deletedBranchIssues).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);
|
||||
});
|
||||
|
||||
@@ -39,7 +39,6 @@ describe('milestones options', (): void => {
|
||||
const setProcessor = () => {
|
||||
processor = new IssuesProcessorMock(
|
||||
opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? testIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
|
||||
@@ -8,7 +8,7 @@ import {generateIssue} from './functions/generate-issue';
|
||||
let issuesProcessorBuilder: IssuesProcessorBuilder;
|
||||
let issuesProcessor: IssuesProcessorMock;
|
||||
|
||||
describe('only-labels option', (): void => {
|
||||
describe('only-labels options', (): void => {
|
||||
beforeEach((): void => {
|
||||
issuesProcessorBuilder = new IssuesProcessorBuilder();
|
||||
});
|
||||
@@ -1139,7 +1139,6 @@ class IssuesProcessorBuilder {
|
||||
build(): IssuesProcessorMock {
|
||||
return new IssuesProcessorMock(
|
||||
this._options,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? this._issues : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
|
||||
@@ -5,7 +5,7 @@ import {IssuesProcessorMock} from './classes/issues-processor-mock';
|
||||
import {DefaultProcessorOptions} from './constants/default-processor-options';
|
||||
import {generateIssue} from './functions/generate-issue';
|
||||
|
||||
describe('operations per run option', (): void => {
|
||||
describe('operations-per-run option', (): void => {
|
||||
let sut: SUT;
|
||||
|
||||
beforeEach((): void => {
|
||||
@@ -205,7 +205,6 @@ class SUT {
|
||||
private async _setProcessor(): Promise<number> {
|
||||
this.processor = new IssuesProcessorMock(
|
||||
this._opts,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? this._testIssueList : []),
|
||||
async () => [],
|
||||
async () => new Date().toDateString()
|
||||
|
||||
@@ -539,14 +539,14 @@ class IssuesProcessorBuilder {
|
||||
build(): IssuesProcessorMock {
|
||||
return new IssuesProcessorMock(
|
||||
this._options,
|
||||
async () => 'abot',
|
||||
async p => (p === 1 ? this._issues : []),
|
||||
async () => [
|
||||
{
|
||||
user: {
|
||||
login: 'notme',
|
||||
type: 'User'
|
||||
}
|
||||
},
|
||||
body: 'body'
|
||||
}
|
||||
],
|
||||
async () => new Date().toDateString()
|
||||
|
||||
696
__tests__/updates-reset-stale.spec.ts
Normal file
696
__tests__/updates-reset-stale.spec.ts
Normal 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);
|
||||
}
|
||||
}
|
||||
24
action.yml
24
action.yml
@@ -164,10 +164,34 @@ inputs:
|
||||
description: 'Exempt all pull requests with assignees from being marked as stale. Override "exempt-all-assignees" option regarding only the pull requests.'
|
||||
default: ''
|
||||
required: false
|
||||
exempt-draft-pr:
|
||||
description: 'Exempt draft pull requests from being marked as stale. Default to false.'
|
||||
default: 'false'
|
||||
required: false
|
||||
enable-statistics:
|
||||
description: 'Display some statistics at the end regarding the stale workflow (only when the logs are enabled).'
|
||||
default: 'true'
|
||||
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:
|
||||
closed-issues-prs:
|
||||
description: 'List of all closed issues and pull requests.'
|
||||
|
||||
510
dist/index.js
vendored
510
dist/index.js
vendored
@@ -1,4 +1,3 @@
|
||||
module.exports =
|
||||
/******/ (() => { // webpackBootstrap
|
||||
/******/ var __webpack_modules__ = ({
|
||||
|
||||
@@ -142,6 +141,116 @@ class Assignees {
|
||||
exports.Assignees = Assignees;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 854:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.ExemptDraftPullRequest = void 0;
|
||||
const option_1 = __nccwpck_require__(5931);
|
||||
const logger_service_1 = __nccwpck_require__(1973);
|
||||
const issue_logger_1 = __nccwpck_require__(2984);
|
||||
class ExemptDraftPullRequest {
|
||||
constructor(options, issue) {
|
||||
this._options = options;
|
||||
this._issue = issue;
|
||||
this._issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
}
|
||||
shouldExemptDraftPullRequest(pullRequestCallback) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
if (this._issue.isPullRequest) {
|
||||
if (this._options.exemptDraftPr) {
|
||||
this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.Option.ExemptDraftPr)} is enabled`);
|
||||
const pullRequest = yield pullRequestCallback();
|
||||
if ((pullRequest === null || pullRequest === void 0 ? void 0 : pullRequest.draft) === true) {
|
||||
this._issueLogger.info(logger_service_1.LoggerService.white('└──'), `Skip the $$type draft checks`);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
this._issueLogger.info(logger_service_1.LoggerService.white('└──'), `Continuing the process for this $$type because it is not a draft`);
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
});
|
||||
}
|
||||
}
|
||||
exports.ExemptDraftPullRequest = ExemptDraftPullRequest;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2935:
|
||||
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.IgnoreUpdates = void 0;
|
||||
const option_1 = __nccwpck_require__(5931);
|
||||
const issue_logger_1 = __nccwpck_require__(2984);
|
||||
class IgnoreUpdates {
|
||||
constructor(options, issue) {
|
||||
this._options = options;
|
||||
this._issue = issue;
|
||||
this._issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
}
|
||||
shouldIgnoreUpdates() {
|
||||
return this._shouldIgnoreUpdates();
|
||||
}
|
||||
_shouldIgnoreUpdates() {
|
||||
return this._issue.isPullRequest
|
||||
? this._shouldIgnorePullRequestUpdates()
|
||||
: this._shouldIgnoreIssueUpdates();
|
||||
}
|
||||
_shouldIgnorePullRequestUpdates() {
|
||||
if (this._options.ignorePrUpdates === true) {
|
||||
this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.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_1.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;
|
||||
}
|
||||
_shouldIgnoreIssueUpdates() {
|
||||
if (this._options.ignoreIssueUpdates === true) {
|
||||
this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.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_1.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;
|
||||
}
|
||||
_logIgnoreUpdates() {
|
||||
if (this._options.ignoreUpdates) {
|
||||
this._issueLogger.info(`The option ${this._issueLogger.createOptionLink(option_1.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_1.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`);
|
||||
}
|
||||
}
|
||||
}
|
||||
exports.IgnoreUpdates = IgnoreUpdates;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 4783:
|
||||
@@ -233,9 +342,12 @@ const is_date_more_recent_than_1 = __nccwpck_require__(1473);
|
||||
const is_valid_date_1 = __nccwpck_require__(891);
|
||||
const is_boolean_1 = __nccwpck_require__(8236);
|
||||
const is_labeled_1 = __nccwpck_require__(6792);
|
||||
const clean_label_1 = __nccwpck_require__(7752);
|
||||
const should_mark_when_stale_1 = __nccwpck_require__(2461);
|
||||
const words_to_list_1 = __nccwpck_require__(1883);
|
||||
const assignees_1 = __nccwpck_require__(7236);
|
||||
const ignore_updates_1 = __nccwpck_require__(2935);
|
||||
const exempt_draft_pull_request_1 = __nccwpck_require__(854);
|
||||
const issue_1 = __nccwpck_require__(4783);
|
||||
const issue_logger_1 = __nccwpck_require__(2984);
|
||||
const logger_1 = __nccwpck_require__(6212);
|
||||
@@ -248,12 +360,13 @@ const logger_service_1 = __nccwpck_require__(1973);
|
||||
*/
|
||||
class IssuesProcessor {
|
||||
constructor(options) {
|
||||
this._logger = new logger_1.Logger();
|
||||
this.staleIssues = [];
|
||||
this.closedIssues = [];
|
||||
this.deletedBranchIssues = [];
|
||||
this.removedLabelIssues = [];
|
||||
this.addedLabelIssues = [];
|
||||
this.addedCloseCommentIssues = [];
|
||||
this._logger = new logger_1.Logger();
|
||||
this.options = options;
|
||||
this.client = github_1.getOctokit(this.options.repoToken);
|
||||
this.operations = new stale_operations_1.StaleOperations(this.options);
|
||||
@@ -263,7 +376,7 @@ class IssuesProcessor {
|
||||
this._logger.warning(logger_service_1.LoggerService.yellowBright(`The debug output will be written but no issues/PRs will be processed.`));
|
||||
}
|
||||
if (this.options.enableStatistics) {
|
||||
this._statistics = new statistics_1.Statistics();
|
||||
this.statistics = new statistics_1.Statistics();
|
||||
}
|
||||
}
|
||||
static _updatedSince(timestamp, num_days) {
|
||||
@@ -278,11 +391,6 @@ class IssuesProcessor {
|
||||
issueLogger.info(logger_service_1.LoggerService.cyan(consumedOperationsCount), `operation${consumedOperationsCount > 1 ? 's' : ''} consumed for this $$type`);
|
||||
}
|
||||
}
|
||||
static _getStaleMessageUsedOptionName(issue) {
|
||||
return issue.isPullRequest
|
||||
? option_1.Option.StalePrMessage
|
||||
: option_1.Option.StaleIssueMessage;
|
||||
}
|
||||
static _getCloseLabelUsedOptionName(issue) {
|
||||
return issue.isPullRequest ? option_1.Option.ClosePrLabel : option_1.Option.CloseIssueLabel;
|
||||
}
|
||||
@@ -291,10 +399,9 @@ class IssuesProcessor {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
// get the next batch of issues
|
||||
const issues = yield this.getIssues(page);
|
||||
const actor = yield this.getActor();
|
||||
if (issues.length <= 0) {
|
||||
this._logger.info(logger_service_1.LoggerService.green(`No more issues found to process. Exiting...`));
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.setOperationsCount(this.operations.getConsumedOperationsCount()).logStats();
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.setOperationsCount(this.operations.getConsumedOperationsCount()).logStats();
|
||||
return this.operations.getRemainingOperationsCount();
|
||||
}
|
||||
else {
|
||||
@@ -309,13 +416,13 @@ class IssuesProcessor {
|
||||
}
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
yield issueLogger.grouping(`$$type #${issue.number}`, () => __awaiter(this, void 0, void 0, function* () {
|
||||
yield this.processIssue(issue, actor, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale);
|
||||
yield this.processIssue(issue, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale);
|
||||
}));
|
||||
}
|
||||
if (!this.operations.hasRemainingOperations()) {
|
||||
this._logger.warning(logger_service_1.LoggerService.yellowBright(`No more operations left! Exiting...`));
|
||||
this._logger.warning(`${logger_service_1.LoggerService.yellowBright('If you think that not enough issues were processed you could try to increase the quantity related to the')} ${this._logger.createOptionLink(option_1.Option.OperationsPerRun)} ${logger_service_1.LoggerService.yellowBright('option which is currently set to')} ${logger_service_1.LoggerService.cyan(this.options.operationsPerRun)}`);
|
||||
(_b = this._statistics) === null || _b === void 0 ? void 0 : _b.setOperationsCount(this.operations.getConsumedOperationsCount()).logStats();
|
||||
(_b = this.statistics) === null || _b === void 0 ? void 0 : _b.setOperationsCount(this.operations.getConsumedOperationsCount()).logStats();
|
||||
return 0;
|
||||
}
|
||||
this._logger.info(`${logger_service_1.LoggerService.green('Batch')} ${logger_service_1.LoggerService.cyan(`#${page}`)} ${logger_service_1.LoggerService.green('processed.')}`);
|
||||
@@ -323,10 +430,10 @@ class IssuesProcessor {
|
||||
return this.processIssues(page + 1);
|
||||
});
|
||||
}
|
||||
processIssue(issue, actor, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale) {
|
||||
processIssue(issue, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementProcessedItemsCount(issue);
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementProcessedItemsCount(issue);
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
issueLogger.info(`Found this $$type last updated at: ${logger_service_1.LoggerService.cyan(issue.updated_at)}`);
|
||||
// calculate string based messages for this issue
|
||||
@@ -348,6 +455,16 @@ class IssuesProcessor {
|
||||
const daysBeforeStale = issue.isPullRequest
|
||||
? this._getDaysBeforePrStale()
|
||||
: 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 = words_to_list_1.wordsToList(this._getOnlyLabels(issue));
|
||||
if (onlyLabels.length > 0) {
|
||||
issueLogger.info(`The option ${issueLogger.createOptionLink(option_1.Option.OnlyLabels)} was specified to only process issues and pull requests with all those labels (${logger_service_1.LoggerService.cyan(onlyLabels.length)})`);
|
||||
@@ -370,16 +487,6 @@ class IssuesProcessor {
|
||||
}
|
||||
issueLogger.info(`Days before $$type stale: ${logger_service_1.LoggerService.cyan(daysBeforeStale)}`);
|
||||
const shouldMarkAsStale = should_mark_when_stale_1.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
|
||||
yield this._removeCloseLabel(issue, closeLabel);
|
||||
if (this.options.startDate) {
|
||||
@@ -447,14 +554,37 @@ class IssuesProcessor {
|
||||
IssuesProcessor._endIssueProcessing(issue);
|
||||
return; // Don't process exempt assignees
|
||||
}
|
||||
// Should this issue be marked stale?
|
||||
const shouldBeStale = !IssuesProcessor._updatedSince(issue.updated_at, daysBeforeStale);
|
||||
// Ignore draft PR
|
||||
// Note that this check is so far below because it cost one read operation
|
||||
// So it's simply better to do all the stale checks which don't cost more operation before this one
|
||||
const exemptDraftPullRequest = new exempt_draft_pull_request_1.ExemptDraftPullRequest(this.options, issue);
|
||||
if (yield exemptDraftPullRequest.shouldExemptDraftPullRequest(() => __awaiter(this, void 0, void 0, function* () {
|
||||
return this.getPullRequest(issue);
|
||||
}))) {
|
||||
IssuesProcessor._endIssueProcessing(issue);
|
||||
return; // Don't process draft PR
|
||||
}
|
||||
// Determine if this issue needs to be marked stale first
|
||||
if (!issue.isStale) {
|
||||
issueLogger.info(`This $$type is not stale`);
|
||||
const updatedAtDate = new Date(issue.updated_at);
|
||||
const shouldIgnoreUpdates = new ignore_updates_1.IgnoreUpdates(this.options, issue).shouldIgnoreUpdates();
|
||||
// Should this issue be marked as stale?
|
||||
let shouldBeStale;
|
||||
// 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) {
|
||||
issueLogger.info(`This $$type should be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(updatedAtDate)} (${logger_service_1.LoggerService.cyan(issue.updated_at)})`);
|
||||
if (shouldIgnoreUpdates) {
|
||||
issueLogger.info(`This $$type should be stale based on the creation date the ${get_humanized_date_1.getHumanizedDate(new Date(issue.created_at))} (${logger_service_1.LoggerService.cyan(issue.created_at)})`);
|
||||
}
|
||||
else {
|
||||
issueLogger.info(`This $$type should be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(new Date(issue.updated_at))} (${logger_service_1.LoggerService.cyan(issue.updated_at)})`);
|
||||
}
|
||||
if (shouldMarkAsStale) {
|
||||
issueLogger.info(`This $$type should be marked as stale based on the option ${issueLogger.createOptionLink(this._getDaysBeforeStaleUsedOptionName(issue))} (${logger_service_1.LoggerService.cyan(daysBeforeStale)})`);
|
||||
yield this._markStale(issue, staleMessage, staleLabel, skipMessage);
|
||||
@@ -466,13 +596,18 @@ class IssuesProcessor {
|
||||
}
|
||||
}
|
||||
else {
|
||||
issueLogger.info(`This $$type should not be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(updatedAtDate)} (${logger_service_1.LoggerService.cyan(issue.updated_at)})`);
|
||||
if (shouldIgnoreUpdates) {
|
||||
issueLogger.info(`This $$type should not be stale based on the creation date the ${get_humanized_date_1.getHumanizedDate(new Date(issue.created_at))} (${logger_service_1.LoggerService.cyan(issue.created_at)})`);
|
||||
}
|
||||
else {
|
||||
issueLogger.info(`This $$type should not be stale based on the last update date the ${get_humanized_date_1.getHumanizedDate(new Date(issue.updated_at))} (${logger_service_1.LoggerService.cyan(issue.updated_at)})`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Process the issue if it was marked stale
|
||||
if (issue.isStale) {
|
||||
issueLogger.info(`This $$type is already stale`);
|
||||
yield this._processStaleIssue(issue, staleLabel, actor, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale, closeMessage, closeLabel);
|
||||
yield this._processStaleIssue(issue, staleLabel, staleMessage, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale, closeMessage, closeLabel);
|
||||
}
|
||||
IssuesProcessor._endIssueProcessing(issue);
|
||||
});
|
||||
@@ -484,7 +619,7 @@ class IssuesProcessor {
|
||||
// Find any comments since date on the given issue
|
||||
try {
|
||||
this.operations.consumeOperation();
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCommentsCount();
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCommentsCount();
|
||||
const comments = yield this.client.issues.listComments({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
@@ -499,20 +634,6 @@ class IssuesProcessor {
|
||||
}
|
||||
});
|
||||
}
|
||||
// get the actor from the GitHub token or context
|
||||
getActor() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let actor;
|
||||
try {
|
||||
this.operations.consumeOperation();
|
||||
actor = yield this.client.users.getAuthenticated();
|
||||
}
|
||||
catch (error) {
|
||||
return github_1.context.actor;
|
||||
}
|
||||
return actor.data.login;
|
||||
});
|
||||
}
|
||||
// grab issues from github in batches of 100
|
||||
getIssues(page) {
|
||||
var _a;
|
||||
@@ -529,7 +650,7 @@ class IssuesProcessor {
|
||||
direction: this.options.ascending ? 'asc' : 'desc',
|
||||
page
|
||||
});
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCount(issueResult.data.length);
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsCount(issueResult.data.length);
|
||||
return issueResult.data.map((issue) => new issue_1.Issue(this.options, issue));
|
||||
}
|
||||
catch (error) {
|
||||
@@ -546,7 +667,7 @@ class IssuesProcessor {
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
issueLogger.info(`Checking for label on this $$type`);
|
||||
this._consumeIssueOperation(issue);
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsEventsCount();
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedItemsEventsCount();
|
||||
const options = this.client.issues.listEvents.endpoint.merge({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.context.repo.repo,
|
||||
@@ -555,7 +676,8 @@ class IssuesProcessor {
|
||||
});
|
||||
const events = yield this.client.paginate(options);
|
||||
const reversedEvents = events.reverse();
|
||||
const staleLabeledEvent = reversedEvents.find(event => event.event === 'labeled' && event.label.name === label);
|
||||
const staleLabeledEvent = reversedEvents.find(event => event.event === 'labeled' &&
|
||||
clean_label_1.cleanLabel(event.label.name) === clean_label_1.cleanLabel(label));
|
||||
if (!staleLabeledEvent) {
|
||||
// Must be old rather than labeled
|
||||
return undefined;
|
||||
@@ -563,13 +685,32 @@ class IssuesProcessor {
|
||||
return staleLabeledEvent.created_at;
|
||||
});
|
||||
}
|
||||
getPullRequest(issue) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedPullRequestsCount();
|
||||
const pullRequest = yield this.client.pulls.get({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.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
|
||||
_processStaleIssue(issue, staleLabel, actor, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale, closeMessage, closeLabel) {
|
||||
_processStaleIssue(issue, staleLabel, staleMessage, labelsToAddWhenUnstale, labelsToRemoveWhenUnstale, closeMessage, closeLabel) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
const markedStaleOn = (yield this.getLabelCreationDate(issue, staleLabel)) || issue.updated_at;
|
||||
issueLogger.info(`$$type marked stale on: ${logger_service_1.LoggerService.cyan(markedStaleOn)}`);
|
||||
const issueHasComments = yield this._hasCommentsSince(issue, markedStaleOn, actor);
|
||||
const issueHasComments = yield this._hasCommentsSince(issue, markedStaleOn, staleMessage);
|
||||
issueLogger.info(`$$type has been commented on: ${logger_service_1.LoggerService.cyan(issueHasComments)}`);
|
||||
const daysBeforeClose = issue.isPullRequest
|
||||
? this._getDaysBeforePrClose()
|
||||
@@ -603,7 +744,7 @@ class IssuesProcessor {
|
||||
issueLogger.info(`Closing $$type because it was last updated on: ${logger_service_1.LoggerService.cyan(issue.updated_at)}`);
|
||||
yield this._closeIssue(issue, closeMessage, closeLabel);
|
||||
if (this.options.deleteBranch && issue.pull_request) {
|
||||
issueLogger.info(`Deleting the branch since the option ${issueLogger.createOptionLink(option_1.Option.DeleteBranch)} was specified`);
|
||||
issueLogger.info(`Deleting the branch since the option ${issueLogger.createOptionLink(option_1.Option.DeleteBranch)} is enabled`);
|
||||
yield this._deleteBranch(issue);
|
||||
this.deletedBranchIssues.push(issue);
|
||||
}
|
||||
@@ -614,7 +755,7 @@ class IssuesProcessor {
|
||||
});
|
||||
}
|
||||
// checks to see if a given issue is still stale (has had activity on it)
|
||||
_hasCommentsSince(issue, sinceDate, actor) {
|
||||
_hasCommentsSince(issue, sinceDate, staleMessage) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
issueLogger.info(`Checking for comments on $$type since: ${logger_service_1.LoggerService.cyan(sinceDate)}`);
|
||||
@@ -623,8 +764,9 @@ class IssuesProcessor {
|
||||
}
|
||||
// find any comments since the date
|
||||
const comments = yield this.listIssueComments(issue.number, sinceDate);
|
||||
const filteredComments = comments.filter(comment => comment.user.type === 'User' && comment.user.login !== actor);
|
||||
issueLogger.info(`Comments not made by actor or another bot: ${logger_service_1.LoggerService.cyan(filteredComments.length)}`);
|
||||
const filteredComments = comments.filter(comment => comment.user.type === 'User' &&
|
||||
comment.body.toLowerCase() !== staleMessage.toLowerCase());
|
||||
issueLogger.info(`Comments that are not the stale comment or another bot: ${logger_service_1.LoggerService.cyan(filteredComments.length)}`);
|
||||
// if there are any user comments returned
|
||||
return filteredComments.length > 0;
|
||||
});
|
||||
@@ -643,7 +785,7 @@ class IssuesProcessor {
|
||||
if (!skipMessage) {
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsComment(issue);
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsComment(issue);
|
||||
if (!this.options.debugOnly) {
|
||||
yield this.client.issues.createComment({
|
||||
owner: github_1.context.repo.owner,
|
||||
@@ -659,8 +801,8 @@ class IssuesProcessor {
|
||||
}
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
(_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue);
|
||||
(_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementStaleItemsCount(issue);
|
||||
(_b = this.statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue);
|
||||
(_c = this.statistics) === null || _c === void 0 ? void 0 : _c.incrementStaleItemsCount(issue);
|
||||
if (!this.options.debugOnly) {
|
||||
yield this.client.issues.addLabels({
|
||||
owner: github_1.context.repo.owner,
|
||||
@@ -685,7 +827,8 @@ class IssuesProcessor {
|
||||
if (closeMessage) {
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsComment(issue);
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsComment(issue);
|
||||
this.addedCloseCommentIssues.push(issue);
|
||||
if (!this.options.debugOnly) {
|
||||
yield this.client.issues.createComment({
|
||||
owner: github_1.context.repo.owner,
|
||||
@@ -702,7 +845,7 @@ class IssuesProcessor {
|
||||
if (closeLabel) {
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
(_b = this._statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue);
|
||||
(_b = this.statistics) === null || _b === void 0 ? void 0 : _b.incrementAddedItemsLabel(issue);
|
||||
if (!this.options.debugOnly) {
|
||||
yield this.client.issues.addLabels({
|
||||
owner: github_1.context.repo.owner,
|
||||
@@ -718,7 +861,7 @@ class IssuesProcessor {
|
||||
}
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
(_c = this._statistics) === null || _c === void 0 ? void 0 : _c.incrementClosedItemsCount(issue);
|
||||
(_c = this.statistics) === null || _c === void 0 ? void 0 : _c.incrementClosedItemsCount(issue);
|
||||
if (!this.options.debugOnly) {
|
||||
yield this.client.issues.update({
|
||||
owner: github_1.context.repo.owner,
|
||||
@@ -733,32 +876,17 @@ class IssuesProcessor {
|
||||
}
|
||||
});
|
||||
}
|
||||
_getPullRequest(issue) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementFetchedPullRequestsCount();
|
||||
const pullRequest = yield this.client.pulls.get({
|
||||
owner: github_1.context.repo.owner,
|
||||
repo: github_1.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
|
||||
_deleteBranch(issue) {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
issueLogger.info(`Delete branch from closed $$type - ${issue.title}`);
|
||||
const pullRequest = yield this._getPullRequest(issue);
|
||||
issueLogger.info(`Delete
|
||||
branch from closed $
|
||||
$type
|
||||
-
|
||||
${issue.title}`);
|
||||
const pullRequest = yield this.getPullRequest(issue);
|
||||
if (!pullRequest) {
|
||||
issueLogger.info(`Not deleting this branch as no pull request was found for this $$type`);
|
||||
return;
|
||||
@@ -767,7 +895,7 @@ class IssuesProcessor {
|
||||
issueLogger.info(`Deleting the branch "${logger_service_1.LoggerService.cyan(branch)}" from closed $$type`);
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedBranchesCount();
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedBranchesCount();
|
||||
if (!this.options.debugOnly) {
|
||||
yield this.client.git.deleteRef({
|
||||
owner: github_1.context.repo.owner,
|
||||
@@ -790,7 +918,7 @@ class IssuesProcessor {
|
||||
this.removedLabelIssues.push(issue);
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedItemsLabelsCount(issue);
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedItemsLabelsCount(issue);
|
||||
if (!this.options.debugOnly) {
|
||||
yield this.client.issues.removeLabel({
|
||||
owner: github_1.context.repo.owner,
|
||||
@@ -887,7 +1015,7 @@ class IssuesProcessor {
|
||||
this.addedLabelIssues.push(issue);
|
||||
try {
|
||||
this.operations.consumeOperation();
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsLabel(issue);
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementAddedItemsLabel(issue);
|
||||
if (!this.options.debugOnly) {
|
||||
yield this.client.issues.addLabels({
|
||||
owner: github_1.context.repo.owner,
|
||||
@@ -908,7 +1036,7 @@ class IssuesProcessor {
|
||||
const issueLogger = new issue_logger_1.IssueLogger(issue);
|
||||
issueLogger.info(`The $$type is no longer stale. Removing the stale label...`);
|
||||
yield this._removeLabel(issue, staleLabel);
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementUndoStaleItemsCount(issue);
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementUndoStaleItemsCount(issue);
|
||||
});
|
||||
}
|
||||
_removeCloseLabel(issue, closeLabel) {
|
||||
@@ -924,7 +1052,7 @@ class IssuesProcessor {
|
||||
if (is_labeled_1.isLabeled(issue, closeLabel)) {
|
||||
issueLogger.info(logger_service_1.LoggerService.white('├──'), `The $$type has a close label "${logger_service_1.LoggerService.cyan(closeLabel)}". Removing the close label...`);
|
||||
yield this._removeLabel(issue, closeLabel, true);
|
||||
(_a = this._statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedCloseItemsLabelsCount(issue);
|
||||
(_a = this.statistics) === null || _a === void 0 ? void 0 : _a.incrementDeletedCloseItemsLabelsCount(issue);
|
||||
}
|
||||
else {
|
||||
issueLogger.info(logger_service_1.LoggerService.white('└──'), `There is no close label on this $$type. Skipping`);
|
||||
@@ -1335,28 +1463,28 @@ const logger_service_1 = __nccwpck_require__(1973);
|
||||
class Statistics {
|
||||
constructor() {
|
||||
this._logger = new logger_1.Logger();
|
||||
this._processedIssuesCount = 0;
|
||||
this._processedPullRequestsCount = 0;
|
||||
this._staleIssuesCount = 0;
|
||||
this._stalePullRequestsCount = 0;
|
||||
this._undoStaleIssuesCount = 0;
|
||||
this._undoStalePullRequestsCount = 0;
|
||||
this._operationsCount = 0;
|
||||
this._closedIssuesCount = 0;
|
||||
this._closedPullRequestsCount = 0;
|
||||
this._deletedIssuesLabelsCount = 0;
|
||||
this._deletedPullRequestsLabelsCount = 0;
|
||||
this._deletedCloseIssuesLabelsCount = 0;
|
||||
this._deletedClosePullRequestsLabelsCount = 0;
|
||||
this._deletedBranchesCount = 0;
|
||||
this._addedIssuesLabelsCount = 0;
|
||||
this._addedPullRequestsLabelsCount = 0;
|
||||
this._addedIssuesCommentsCount = 0;
|
||||
this._addedPullRequestsCommentsCount = 0;
|
||||
this._fetchedItemsCount = 0;
|
||||
this._fetchedItemsEventsCount = 0;
|
||||
this._fetchedItemsCommentsCount = 0;
|
||||
this._fetchedPullRequestsCount = 0;
|
||||
this.processedIssuesCount = 0;
|
||||
this.processedPullRequestsCount = 0;
|
||||
this.staleIssuesCount = 0;
|
||||
this.stalePullRequestsCount = 0;
|
||||
this.undoStaleIssuesCount = 0;
|
||||
this.undoStalePullRequestsCount = 0;
|
||||
this.operationsCount = 0;
|
||||
this.closedIssuesCount = 0;
|
||||
this.closedPullRequestsCount = 0;
|
||||
this.deletedIssuesLabelsCount = 0;
|
||||
this.deletedPullRequestsLabelsCount = 0;
|
||||
this.deletedCloseIssuesLabelsCount = 0;
|
||||
this.deletedClosePullRequestsLabelsCount = 0;
|
||||
this.deletedBranchesCount = 0;
|
||||
this.addedIssuesLabelsCount = 0;
|
||||
this.addedPullRequestsLabelsCount = 0;
|
||||
this.addedIssuesCommentsCount = 0;
|
||||
this.addedPullRequestsCommentsCount = 0;
|
||||
this.fetchedItemsCount = 0;
|
||||
this.fetchedItemsEventsCount = 0;
|
||||
this.fetchedItemsCommentsCount = 0;
|
||||
this.fetchedPullRequestsCount = 0;
|
||||
}
|
||||
incrementProcessedItemsCount(issue, increment = 1) {
|
||||
if (issue.isPullRequest) {
|
||||
@@ -1377,7 +1505,7 @@ class Statistics {
|
||||
return this._incrementUndoStaleIssuesCount(increment);
|
||||
}
|
||||
setOperationsCount(operationsCount) {
|
||||
this._operationsCount = operationsCount;
|
||||
this.operationsCount = operationsCount;
|
||||
return this;
|
||||
}
|
||||
incrementClosedItemsCount(issue, increment = 1) {
|
||||
@@ -1399,7 +1527,7 @@ class Statistics {
|
||||
return this._incrementDeletedCloseIssuesLabelsCount(increment);
|
||||
}
|
||||
incrementDeletedBranchesCount(increment = 1) {
|
||||
this._deletedBranchesCount += increment;
|
||||
this.deletedBranchesCount += increment;
|
||||
return this;
|
||||
}
|
||||
incrementAddedItemsLabel(issue, increment = 1) {
|
||||
@@ -1415,19 +1543,19 @@ class Statistics {
|
||||
return this._incrementAddedIssuesComment(increment);
|
||||
}
|
||||
incrementFetchedItemsCount(increment = 1) {
|
||||
this._fetchedItemsCount += increment;
|
||||
this.fetchedItemsCount += increment;
|
||||
return this;
|
||||
}
|
||||
incrementFetchedItemsEventsCount(increment = 1) {
|
||||
this._fetchedItemsEventsCount += increment;
|
||||
this.fetchedItemsEventsCount += increment;
|
||||
return this;
|
||||
}
|
||||
incrementFetchedItemsCommentsCount(increment = 1) {
|
||||
this._fetchedItemsCommentsCount += increment;
|
||||
this.fetchedItemsCommentsCount += increment;
|
||||
return this;
|
||||
}
|
||||
incrementFetchedPullRequestsCount(increment = 1) {
|
||||
this._fetchedPullRequestsCount += increment;
|
||||
this.fetchedPullRequestsCount += increment;
|
||||
return this;
|
||||
}
|
||||
logStats() {
|
||||
@@ -1449,78 +1577,78 @@ class Statistics {
|
||||
return this;
|
||||
}
|
||||
_incrementProcessedIssuesCount(increment = 1) {
|
||||
this._processedIssuesCount += increment;
|
||||
this.processedIssuesCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementProcessedPullRequestsCount(increment = 1) {
|
||||
this._processedPullRequestsCount += increment;
|
||||
this.processedPullRequestsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementStaleIssuesCount(increment = 1) {
|
||||
this._staleIssuesCount += increment;
|
||||
this.staleIssuesCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementStalePullRequestsCount(increment = 1) {
|
||||
this._stalePullRequestsCount += increment;
|
||||
this.stalePullRequestsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementUndoStaleIssuesCount(increment = 1) {
|
||||
this._undoStaleIssuesCount += increment;
|
||||
this.undoStaleIssuesCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementUndoStalePullRequestsCount(increment = 1) {
|
||||
this._undoStalePullRequestsCount += increment;
|
||||
this.undoStalePullRequestsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementClosedIssuesCount(increment = 1) {
|
||||
this._closedIssuesCount += increment;
|
||||
this.closedIssuesCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementClosedPullRequestsCount(increment = 1) {
|
||||
this._closedPullRequestsCount += increment;
|
||||
this.closedPullRequestsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementDeletedIssuesLabelsCount(increment = 1) {
|
||||
this._deletedIssuesLabelsCount += increment;
|
||||
this.deletedIssuesLabelsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementDeletedPullRequestsLabelsCount(increment = 1) {
|
||||
this._deletedPullRequestsLabelsCount += increment;
|
||||
this.deletedPullRequestsLabelsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementDeletedCloseIssuesLabelsCount(increment = 1) {
|
||||
this._deletedCloseIssuesLabelsCount += increment;
|
||||
this.deletedCloseIssuesLabelsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementDeletedClosePullRequestsLabelsCount(increment = 1) {
|
||||
this._deletedClosePullRequestsLabelsCount += increment;
|
||||
this.deletedClosePullRequestsLabelsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementAddedIssuesLabel(increment = 1) {
|
||||
this._addedIssuesLabelsCount += increment;
|
||||
this.addedIssuesLabelsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementAddedPullRequestsLabel(increment = 1) {
|
||||
this._addedPullRequestsLabelsCount += increment;
|
||||
this.addedPullRequestsLabelsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementAddedIssuesComment(increment = 1) {
|
||||
this._addedIssuesCommentsCount += increment;
|
||||
this.addedIssuesCommentsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_incrementAddedPullRequestsComment(increment = 1) {
|
||||
this._addedPullRequestsCommentsCount += increment;
|
||||
this.addedPullRequestsCommentsCount += increment;
|
||||
return this;
|
||||
}
|
||||
_logProcessedIssuesAndPullRequestsCount() {
|
||||
this._logGroup('Processed items', [
|
||||
{
|
||||
name: 'Processed issues',
|
||||
count: this._processedIssuesCount
|
||||
count: this.processedIssuesCount
|
||||
},
|
||||
{
|
||||
name: 'Processed PRs',
|
||||
count: this._processedPullRequestsCount
|
||||
count: this.processedPullRequestsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -1528,11 +1656,11 @@ class Statistics {
|
||||
this._logGroup('New stale items', [
|
||||
{
|
||||
name: 'New stale issues',
|
||||
count: this._staleIssuesCount
|
||||
count: this.staleIssuesCount
|
||||
},
|
||||
{
|
||||
name: 'New stale PRs',
|
||||
count: this._stalePullRequestsCount
|
||||
count: this.stalePullRequestsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -1540,11 +1668,11 @@ class Statistics {
|
||||
this._logGroup('No longer stale items', [
|
||||
{
|
||||
name: 'No longer stale issues',
|
||||
count: this._undoStaleIssuesCount
|
||||
count: this.undoStaleIssuesCount
|
||||
},
|
||||
{
|
||||
name: 'No longer stale PRs',
|
||||
count: this._undoStalePullRequestsCount
|
||||
count: this.undoStalePullRequestsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -1552,11 +1680,11 @@ class Statistics {
|
||||
this._logGroup('Closed items', [
|
||||
{
|
||||
name: 'Closed issues',
|
||||
count: this._closedIssuesCount
|
||||
count: this.closedIssuesCount
|
||||
},
|
||||
{
|
||||
name: 'Closed PRs',
|
||||
count: this._closedPullRequestsCount
|
||||
count: this.closedPullRequestsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -1564,11 +1692,11 @@ class Statistics {
|
||||
this._logGroup('Deleted items labels', [
|
||||
{
|
||||
name: 'Deleted issues labels',
|
||||
count: this._deletedIssuesLabelsCount
|
||||
count: this.deletedIssuesLabelsCount
|
||||
},
|
||||
{
|
||||
name: 'Deleted PRs labels',
|
||||
count: this._deletedPullRequestsLabelsCount
|
||||
count: this.deletedPullRequestsLabelsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -1576,26 +1704,26 @@ class Statistics {
|
||||
this._logGroup('Deleted close items labels', [
|
||||
{
|
||||
name: 'Deleted close issues labels',
|
||||
count: this._deletedCloseIssuesLabelsCount
|
||||
count: this.deletedCloseIssuesLabelsCount
|
||||
},
|
||||
{
|
||||
name: 'Deleted close PRs labels',
|
||||
count: this._deletedClosePullRequestsLabelsCount
|
||||
count: this.deletedClosePullRequestsLabelsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
_logDeletedBranchesCount() {
|
||||
this._logCount('Deleted branches', this._deletedBranchesCount);
|
||||
this._logCount('Deleted branches', this.deletedBranchesCount);
|
||||
}
|
||||
_logAddedIssuesAndPullRequestsLabelsCount() {
|
||||
this._logGroup('Added items labels', [
|
||||
{
|
||||
name: 'Added issues labels',
|
||||
count: this._addedIssuesLabelsCount
|
||||
count: this.addedIssuesLabelsCount
|
||||
},
|
||||
{
|
||||
name: 'Added PRs labels',
|
||||
count: this._addedPullRequestsLabelsCount
|
||||
count: this.addedPullRequestsLabelsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -1603,28 +1731,28 @@ class Statistics {
|
||||
this._logGroup('Added items comments', [
|
||||
{
|
||||
name: 'Added issues comments',
|
||||
count: this._addedIssuesCommentsCount
|
||||
count: this.addedIssuesCommentsCount
|
||||
},
|
||||
{
|
||||
name: 'Added PRs comments',
|
||||
count: this._addedPullRequestsCommentsCount
|
||||
count: this.addedPullRequestsCommentsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
_logFetchedItemsCount() {
|
||||
this._logCount('Fetched items', this._fetchedItemsCount);
|
||||
this._logCount('Fetched items', this.fetchedItemsCount);
|
||||
}
|
||||
_logFetchedItemsEventsCount() {
|
||||
this._logCount('Fetched items events', this._fetchedItemsEventsCount);
|
||||
this._logCount('Fetched items events', this.fetchedItemsEventsCount);
|
||||
}
|
||||
_logFetchedItemsCommentsCount() {
|
||||
this._logCount('Fetched items comments', this._fetchedItemsCommentsCount);
|
||||
this._logCount('Fetched items comments', this.fetchedItemsCommentsCount);
|
||||
}
|
||||
_logFetchedPullRequestsCount() {
|
||||
this._logCount('Fetched pull requests', this._fetchedPullRequestsCount);
|
||||
this._logCount('Fetched pull requests', this.fetchedPullRequestsCount);
|
||||
}
|
||||
_logOperationsCount() {
|
||||
this._logCount('Operations performed', this._operationsCount);
|
||||
this._logCount('Operations performed', this.operationsCount);
|
||||
}
|
||||
_logCount(name, count) {
|
||||
if (count > 0) {
|
||||
@@ -1742,9 +1870,40 @@ var Option;
|
||||
Option["EnableStatistics"] = "enable-statistics";
|
||||
Option["LabelsToRemoveWhenUnstale"] = "labels-to-remove-when-unstale";
|
||||
Option["LabelsToAddWhenUnstale"] = "labels-to-add-when-unstale";
|
||||
Option["IgnoreUpdates"] = "ignore-updates";
|
||||
Option["IgnoreIssueUpdates"] = "ignore-issue-updates";
|
||||
Option["IgnorePrUpdates"] = "ignore-pr-updates";
|
||||
Option["ExemptDraftPr"] = "exempt-draft-pr";
|
||||
})(Option = exports.Option || (exports.Option = {}));
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 7752:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.cleanLabel = void 0;
|
||||
const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601));
|
||||
/**
|
||||
* @description
|
||||
* Clean a label by lowercasing it and deburring it for consistency
|
||||
*
|
||||
* @param {string} label A raw GitHub label
|
||||
*
|
||||
* @return {string} A lowercased, deburred version of the passed in label
|
||||
*/
|
||||
function cleanLabel(label) {
|
||||
return lodash_deburr_1.default(label.toLowerCase());
|
||||
}
|
||||
exports.cleanLabel = cleanLabel;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 965:
|
||||
@@ -1831,16 +1990,13 @@ exports.isBoolean = isBoolean;
|
||||
/***/ }),
|
||||
|
||||
/***/ 6792:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.isLabeled = void 0;
|
||||
const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601));
|
||||
const clean_label_1 = __nccwpck_require__(7752);
|
||||
/**
|
||||
* @description
|
||||
* Check if the given label is listed as a label of the given issue
|
||||
@@ -1852,13 +2008,10 @@ const lodash_deburr_1 = __importDefault(__nccwpck_require__(1601));
|
||||
*/
|
||||
function isLabeled(issue, label) {
|
||||
return !!issue.labels.find((issueLabel) => {
|
||||
return cleanLabel(label) === cleanLabel(issueLabel.name);
|
||||
return clean_label_1.cleanLabel(label) === clean_label_1.cleanLabel(issueLabel.name);
|
||||
});
|
||||
}
|
||||
exports.isLabeled = isLabeled;
|
||||
function cleanLabel(label) {
|
||||
return lodash_deburr_1.default(label.toLowerCase());
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
@@ -2005,8 +2158,8 @@ function _getAndValidateArgs() {
|
||||
anyOfPrLabels: core.getInput('any-of-pr-labels'),
|
||||
operationsPerRun: parseInt(core.getInput('operations-per-run', { required: true })),
|
||||
removeStaleWhenUpdated: !(core.getInput('remove-stale-when-updated') === 'false'),
|
||||
removeIssueStaleWhenUpdated: _toOptionalBoolean(core.getInput('remove-issue-stale-when-updated')),
|
||||
removePrStaleWhenUpdated: _toOptionalBoolean(core.getInput('remove-pr-stale-when-updated')),
|
||||
removeIssueStaleWhenUpdated: _toOptionalBoolean('remove-issue-stale-when-updated'),
|
||||
removePrStaleWhenUpdated: _toOptionalBoolean('remove-pr-stale-when-updated'),
|
||||
debugOnly: core.getInput('debug-only') === 'true',
|
||||
ascending: core.getInput('ascending') === 'true',
|
||||
deleteBranch: core.getInput('delete-branch') === 'true',
|
||||
@@ -2027,7 +2180,11 @@ function _getAndValidateArgs() {
|
||||
exemptAllPrAssignees: _toOptionalBoolean('exempt-all-pr-assignees'),
|
||||
enableStatistics: core.getInput('enable-statistics') === 'true',
|
||||
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'
|
||||
};
|
||||
for (const numberInput of [
|
||||
'days-before-stale',
|
||||
@@ -2058,6 +2215,17 @@ function processOutput(staledIssues, 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(argumentName) {
|
||||
const argument = core.getInput(argumentName);
|
||||
if (argument === 'true') {
|
||||
@@ -8945,8 +9113,9 @@ module.exports = require("zlib");;
|
||||
/******/ // The require function
|
||||
/******/ function __nccwpck_require__(moduleId) {
|
||||
/******/ // Check if module is in cache
|
||||
/******/ if(__webpack_module_cache__[moduleId]) {
|
||||
/******/ return __webpack_module_cache__[moduleId].exports;
|
||||
/******/ var cachedModule = __webpack_module_cache__[moduleId];
|
||||
/******/ if (cachedModule !== undefined) {
|
||||
/******/ return cachedModule.exports;
|
||||
/******/ }
|
||||
/******/ // Create a new module (and put it into the cache)
|
||||
/******/ var module = __webpack_module_cache__[moduleId] = {
|
||||
@@ -8983,10 +9152,13 @@ module.exports = require("zlib");;
|
||||
/******/
|
||||
/******/ /* webpack/runtime/compat */
|
||||
/******/
|
||||
/******/ __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
|
||||
/******/ // module exports must be returned from runtime so entry inlining is disabled
|
||||
/******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/";/************************************************************************/
|
||||
/******/
|
||||
/******/ // startup
|
||||
/******/ // Load entry module and return exports
|
||||
/******/ return __nccwpck_require__(3109);
|
||||
/******/ // This entry module is referenced by other modules so it can't be inlined
|
||||
/******/ var __webpack_exports__ = __nccwpck_require__(3109);
|
||||
/******/ module.exports = __webpack_exports__;
|
||||
/******/
|
||||
/******/ })()
|
||||
;
|
||||
7778
package-lock.json
generated
7778
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
23
package.json
23
package.json
@@ -17,6 +17,7 @@
|
||||
"test:only-errors": "jest --reporters jest-silent-reporter --silent",
|
||||
"test:watch": "jest --watch --notify --expand",
|
||||
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test",
|
||||
"all:ci": "npm run build && npm run lint:all && npm run pack && npm run test:only-errors",
|
||||
"prerelease": "npm run build && npm run pack",
|
||||
"release": "standard-version",
|
||||
"release:dry-run": "standard-version --dry-run"
|
||||
@@ -43,25 +44,25 @@
|
||||
"semver": "^7.3.5"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^26.0.23",
|
||||
"@types/jest": "^27.0.2",
|
||||
"@types/lodash.deburr": "^4.1.6",
|
||||
"@types/node": "^15.0.2",
|
||||
"@types/semver": "^7.3.5",
|
||||
"@typescript-eslint/eslint-plugin": "^4.26.0",
|
||||
"@typescript-eslint/parser": "^4.26.1",
|
||||
"@vercel/ncc": "^0.27.0",
|
||||
"@typescript-eslint/eslint-plugin": "^4.31.1",
|
||||
"@typescript-eslint/parser": "^4.31.1",
|
||||
"@vercel/ncc": "^0.28.6",
|
||||
"ansi-styles": "5.2.0",
|
||||
"eslint": "^7.28.0",
|
||||
"eslint-plugin-github": "^4.1.2",
|
||||
"eslint-plugin-jest": "^24.3.6",
|
||||
"jest": "^26.6.3",
|
||||
"jest-circus": "^26.6.3",
|
||||
"jest-silent-reporter": "^0.4.0",
|
||||
"eslint-plugin-jest": "^24.4.2",
|
||||
"jest": "^27.2.5",
|
||||
"jest-circus": "^27.2.0",
|
||||
"jest-silent-reporter": "^0.5.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"prettier": "^2.3.1",
|
||||
"standard-version": "^9.2.0",
|
||||
"prettier": "^2.4.1",
|
||||
"standard-version": "^9.3.1",
|
||||
"terminal-link": "^2.1.1",
|
||||
"ts-jest": "^26.5.6",
|
||||
"ts-jest": "^27.0.5",
|
||||
"typescript": "^4.3.2"
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,7 +1,7 @@
|
||||
import deburr from 'lodash.deburr';
|
||||
import {Option} from '../enums/option';
|
||||
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 {Issue} from './issue';
|
||||
import {IssueLogger} from './loggers/issue-logger';
|
||||
@@ -10,10 +10,6 @@ import {LoggerService} from '../services/logger.service';
|
||||
type CleanAssignee = string;
|
||||
|
||||
export class Assignees {
|
||||
private static _cleanAssignee(assignee: Readonly<string>): CleanAssignee {
|
||||
return deburr(assignee.toLowerCase());
|
||||
}
|
||||
|
||||
private readonly _options: IIssuesProcessorOptions;
|
||||
private readonly _issue: Issue;
|
||||
private readonly _issueLogger: IssueLogger;
|
||||
@@ -24,6 +20,10 @@ export class Assignees {
|
||||
this._issueLogger = new IssueLogger(issue);
|
||||
}
|
||||
|
||||
private static _cleanAssignee(assignee: Readonly<string>): CleanAssignee {
|
||||
return deburr(assignee.toLowerCase());
|
||||
}
|
||||
|
||||
shouldExemptAssignees(): boolean {
|
||||
if (!this._issue.hasAssignees) {
|
||||
this._issueLogger.info('This $$type has no assignee');
|
||||
@@ -195,7 +195,7 @@ export class Assignees {
|
||||
const cleanAssignee: CleanAssignee = Assignees._cleanAssignee(assignee);
|
||||
|
||||
return this._issue.assignees.some(
|
||||
(issueAssignee: Readonly<IAssignee>): boolean => {
|
||||
(issueAssignee: Readonly<Assignee>): boolean => {
|
||||
const isSameAssignee: boolean =
|
||||
cleanAssignee === Assignees._cleanAssignee(issueAssignee.login);
|
||||
|
||||
|
||||
51
src/classes/exempt-draft-pull-request.ts
Normal file
51
src/classes/exempt-draft-pull-request.ts
Normal 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;
|
||||
}
|
||||
}
|
||||
251
src/classes/ignore-updates.spec.ts
Normal file
251
src/classes/ignore-updates.spec.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
90
src/classes/ignore-updates.ts
Normal file
90
src/classes/ignore-updates.ts
Normal 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`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import {IAssignee} from '../interfaces/assignee';
|
||||
import {IUserAssignee} from '../interfaces/assignee';
|
||||
import {IIssue} from '../interfaces/issue';
|
||||
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
|
||||
import {ILabel} from '../interfaces/label';
|
||||
@@ -57,7 +57,11 @@ describe('Issue', (): void => {
|
||||
exemptAllPrAssignees: undefined,
|
||||
enableStatistics: false,
|
||||
labelsToRemoveWhenUnstale: '',
|
||||
labelsToAddWhenUnstale: ''
|
||||
labelsToAddWhenUnstale: '',
|
||||
ignoreUpdates: false,
|
||||
ignoreIssueUpdates: undefined,
|
||||
ignorePrUpdates: undefined,
|
||||
exemptDraftPr: false
|
||||
};
|
||||
issueInterface = {
|
||||
title: 'dummy-title',
|
||||
@@ -77,7 +81,8 @@ describe('Issue', (): void => {
|
||||
},
|
||||
assignees: [
|
||||
{
|
||||
login: 'dummy-login'
|
||||
login: 'dummy-login',
|
||||
type: 'User'
|
||||
}
|
||||
]
|
||||
};
|
||||
@@ -150,8 +155,9 @@ describe('Issue', (): void => {
|
||||
|
||||
expect(issue.assignees).toStrictEqual([
|
||||
{
|
||||
login: 'dummy-login'
|
||||
} as IAssignee
|
||||
login: 'dummy-login',
|
||||
type: 'User'
|
||||
} as IUserAssignee
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -272,7 +278,8 @@ describe('Issue', (): void => {
|
||||
beforeEach((): void => {
|
||||
issueInterface.assignees = [
|
||||
{
|
||||
login: 'dummy-login'
|
||||
login: 'dummy-login',
|
||||
type: 'User'
|
||||
}
|
||||
];
|
||||
issue = new Issue(optionsInterface, issueInterface);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import {isLabeled} from '../functions/is-labeled';
|
||||
import {isPullRequest} from '../functions/is-pull-request';
|
||||
import {IAssignee} from '../interfaces/assignee';
|
||||
import {Assignee} from '../interfaces/assignee';
|
||||
import {IIssue} from '../interfaces/issue';
|
||||
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
|
||||
import {ILabel} from '../interfaces/label';
|
||||
@@ -9,7 +9,6 @@ import {IsoDateString} from '../types/iso-date-string';
|
||||
import {Operations} from './operations';
|
||||
|
||||
export class Issue implements IIssue {
|
||||
private readonly _options: IIssuesProcessorOptions;
|
||||
readonly title: string;
|
||||
readonly number: number;
|
||||
created_at: IsoDateString;
|
||||
@@ -19,21 +18,10 @@ export class Issue implements IIssue {
|
||||
readonly state: string | 'closed' | 'open';
|
||||
readonly locked: boolean;
|
||||
readonly milestone: IMilestone | undefined;
|
||||
readonly assignees: IAssignee[];
|
||||
readonly assignees: Assignee[];
|
||||
isStale: boolean;
|
||||
operations = new Operations();
|
||||
|
||||
get isPullRequest(): boolean {
|
||||
return isPullRequest(this);
|
||||
}
|
||||
|
||||
get staleLabel(): string {
|
||||
return this._getStaleLabel();
|
||||
}
|
||||
|
||||
get hasAssignees(): boolean {
|
||||
return this.assignees.length > 0;
|
||||
}
|
||||
private readonly _options: IIssuesProcessorOptions;
|
||||
|
||||
constructor(
|
||||
options: Readonly<IIssuesProcessorOptions>,
|
||||
@@ -50,10 +38,21 @@ export class Issue implements IIssue {
|
||||
this.locked = issue.locked;
|
||||
this.milestone = issue.milestone;
|
||||
this.assignees = issue.assignees;
|
||||
|
||||
this.isStale = isLabeled(this, this.staleLabel);
|
||||
}
|
||||
|
||||
get isPullRequest(): boolean {
|
||||
return isPullRequest(this);
|
||||
}
|
||||
|
||||
get staleLabel(): string {
|
||||
return this._getStaleLabel();
|
||||
}
|
||||
|
||||
get hasAssignees(): boolean {
|
||||
return this.assignees.length > 0;
|
||||
}
|
||||
|
||||
private _getStaleLabel(): string {
|
||||
return this.isPullRequest
|
||||
? this._options.stalePrLabel
|
||||
|
||||
@@ -8,14 +8,16 @@ import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than'
|
||||
import {isValidDate} from '../functions/dates/is-valid-date';
|
||||
import {isBoolean} from '../functions/is-boolean';
|
||||
import {isLabeled} from '../functions/is-labeled';
|
||||
import {cleanLabel} from '../functions/clean-label';
|
||||
import {shouldMarkWhenStale} from '../functions/should-mark-when-stale';
|
||||
import {wordsToList} from '../functions/words-to-list';
|
||||
import {IComment} from '../interfaces/comment';
|
||||
import {IIssue} from '../interfaces/issue';
|
||||
import {IIssueEvent} from '../interfaces/issue-event';
|
||||
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
|
||||
import {IPullRequest} from '../interfaces/pull-request';
|
||||
import {Assignees} from './assignees';
|
||||
import {IgnoreUpdates} from './ignore-updates';
|
||||
import {ExemptDraftPullRequest} from './exempt-draft-pull-request';
|
||||
import {Issue} from './issue';
|
||||
import {IssueLogger} from './loggers/issue-logger';
|
||||
import {Logger} from './loggers/logger';
|
||||
@@ -23,6 +25,7 @@ import {Milestones} from './milestones';
|
||||
import {StaleOperations} from './stale-operations';
|
||||
import {Statistics} from './statistics';
|
||||
import {LoggerService} from '../services/logger.service';
|
||||
import {IIssue} from '../interfaces/issue';
|
||||
|
||||
/***
|
||||
* Handle processing of issues for staleness/closure.
|
||||
@@ -52,22 +55,12 @@ export class IssuesProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private static _getStaleMessageUsedOptionName(
|
||||
issue: Readonly<Issue>
|
||||
): Option.StalePrMessage | Option.StaleIssueMessage {
|
||||
return issue.isPullRequest
|
||||
? Option.StalePrMessage
|
||||
: Option.StaleIssueMessage;
|
||||
}
|
||||
|
||||
private static _getCloseLabelUsedOptionName(
|
||||
issue: Readonly<Issue>
|
||||
): 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 client: InstanceType<typeof GitHub>;
|
||||
readonly options: IIssuesProcessorOptions;
|
||||
@@ -76,6 +69,9 @@ export class IssuesProcessor {
|
||||
readonly deletedBranchIssues: Issue[] = [];
|
||||
readonly removedLabelIssues: Issue[] = [];
|
||||
readonly addedLabelIssues: Issue[] = [];
|
||||
readonly addedCloseCommentIssues: Issue[] = [];
|
||||
readonly statistics: Statistics | undefined;
|
||||
private readonly _logger: Logger = new Logger();
|
||||
|
||||
constructor(options: IIssuesProcessorOptions) {
|
||||
this.options = options;
|
||||
@@ -98,20 +94,19 @@ export class IssuesProcessor {
|
||||
}
|
||||
|
||||
if (this.options.enableStatistics) {
|
||||
this._statistics = new Statistics();
|
||||
this.statistics = new Statistics();
|
||||
}
|
||||
}
|
||||
|
||||
async processIssues(page: Readonly<number> = 1): Promise<number> {
|
||||
// get the next batch of issues
|
||||
const issues: Issue[] = await this.getIssues(page);
|
||||
const actor: string = await this.getActor();
|
||||
|
||||
if (issues.length <= 0) {
|
||||
this._logger.info(
|
||||
LoggerService.green(`No more issues found to process. Exiting...`)
|
||||
);
|
||||
this._statistics
|
||||
this.statistics
|
||||
?.setOperationsCount(this.operations.getConsumedOperationsCount())
|
||||
.logStats();
|
||||
|
||||
@@ -145,7 +140,6 @@ export class IssuesProcessor {
|
||||
await issueLogger.grouping(`$$type #${issue.number}`, async () => {
|
||||
await this.processIssue(
|
||||
issue,
|
||||
actor,
|
||||
labelsToAddWhenUnstale,
|
||||
labelsToRemoveWhenUnstale
|
||||
);
|
||||
@@ -165,7 +159,7 @@ export class IssuesProcessor {
|
||||
'option which is currently set to'
|
||||
)} ${LoggerService.cyan(this.options.operationsPerRun)}`
|
||||
);
|
||||
this._statistics
|
||||
this.statistics
|
||||
?.setOperationsCount(this.operations.getConsumedOperationsCount())
|
||||
.logStats();
|
||||
|
||||
@@ -184,11 +178,10 @@ export class IssuesProcessor {
|
||||
|
||||
async processIssue(
|
||||
issue: Issue,
|
||||
actor: string,
|
||||
labelsToAddWhenUnstale: Readonly<string>[],
|
||||
labelsToRemoveWhenUnstale: Readonly<string>[]
|
||||
): Promise<void> {
|
||||
this._statistics?.incrementProcessedItemsCount(issue);
|
||||
this.statistics?.incrementProcessedItemsCount(issue);
|
||||
|
||||
const issueLogger: IssueLogger = new IssueLogger(issue);
|
||||
issueLogger.info(
|
||||
@@ -216,6 +209,19 @@ export class IssuesProcessor {
|
||||
const daysBeforeStale: number = issue.isPullRequest
|
||||
? this._getDaysBeforePrStale()
|
||||
: 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));
|
||||
|
||||
if (onlyLabels.length > 0) {
|
||||
@@ -269,18 +275,6 @@ export class IssuesProcessor {
|
||||
|
||||
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
|
||||
await this._removeCloseLabel(issue, closeLabel);
|
||||
|
||||
@@ -406,23 +400,63 @@ export class IssuesProcessor {
|
||||
return; // Don't process exempt assignees
|
||||
}
|
||||
|
||||
// Should this issue be marked stale?
|
||||
const shouldBeStale = !IssuesProcessor._updatedSince(
|
||||
issue.updated_at,
|
||||
daysBeforeStale
|
||||
);
|
||||
// Ignore draft PR
|
||||
// Note that this check is so far below because it cost one read operation
|
||||
// So it's simply better to do all the stale checks which don't cost more operation before this one
|
||||
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
|
||||
if (!issue.isStale) {
|
||||
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) {
|
||||
issueLogger.info(
|
||||
`This $$type should be stale based on the last update date the ${getHumanizedDate(
|
||||
updatedAtDate
|
||||
)} (${LoggerService.cyan(issue.updated_at)})`
|
||||
);
|
||||
if (shouldIgnoreUpdates) {
|
||||
issueLogger.info(
|
||||
`This $$type should be stale based on the creation date the ${getHumanizedDate(
|
||||
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) {
|
||||
issueLogger.info(
|
||||
@@ -441,11 +475,19 @@ export class IssuesProcessor {
|
||||
);
|
||||
}
|
||||
} else {
|
||||
issueLogger.info(
|
||||
`This $$type should not be stale based on the last update date the ${getHumanizedDate(
|
||||
updatedAtDate
|
||||
)} (${LoggerService.cyan(issue.updated_at)})`
|
||||
);
|
||||
if (shouldIgnoreUpdates) {
|
||||
issueLogger.info(
|
||||
`This $$type should not be stale based on the creation date the ${getHumanizedDate(
|
||||
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)})`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -455,7 +497,7 @@ export class IssuesProcessor {
|
||||
await this._processStaleIssue(
|
||||
issue,
|
||||
staleLabel,
|
||||
actor,
|
||||
staleMessage,
|
||||
labelsToAddWhenUnstale,
|
||||
labelsToRemoveWhenUnstale,
|
||||
closeMessage,
|
||||
@@ -474,7 +516,7 @@ export class IssuesProcessor {
|
||||
// Find any comments since date on the given issue
|
||||
try {
|
||||
this.operations.consumeOperation();
|
||||
this._statistics?.incrementFetchedItemsCommentsCount();
|
||||
this.statistics?.incrementFetchedItemsCommentsCount();
|
||||
const comments = await this.client.issues.listComments({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
@@ -488,20 +530,6 @@ export class IssuesProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
// get the actor from the GitHub token or context
|
||||
async getActor(): Promise<string> {
|
||||
let actor;
|
||||
|
||||
try {
|
||||
this.operations.consumeOperation();
|
||||
actor = await this.client.users.getAuthenticated();
|
||||
} catch (error) {
|
||||
return context.actor;
|
||||
}
|
||||
|
||||
return actor.data.login;
|
||||
}
|
||||
|
||||
// grab issues from github in batches of 100
|
||||
async getIssues(page: number): Promise<Issue[]> {
|
||||
// generate type for response
|
||||
@@ -519,7 +547,7 @@ export class IssuesProcessor {
|
||||
direction: this.options.ascending ? 'asc' : 'desc',
|
||||
page
|
||||
});
|
||||
this._statistics?.incrementFetchedItemsCount(issueResult.data.length);
|
||||
this.statistics?.incrementFetchedItemsCount(issueResult.data.length);
|
||||
|
||||
return issueResult.data.map(
|
||||
(issue: Readonly<IIssue>): Issue => new Issue(this.options, issue)
|
||||
@@ -541,7 +569,7 @@ export class IssuesProcessor {
|
||||
issueLogger.info(`Checking for label on this $$type`);
|
||||
|
||||
this._consumeIssueOperation(issue);
|
||||
this._statistics?.incrementFetchedItemsEventsCount();
|
||||
this.statistics?.incrementFetchedItemsEventsCount();
|
||||
const options = this.client.issues.listEvents.endpoint.merge({
|
||||
owner: context.repo.owner,
|
||||
repo: context.repo.repo,
|
||||
@@ -553,7 +581,9 @@ export class IssuesProcessor {
|
||||
const reversedEvents = events.reverse();
|
||||
|
||||
const staleLabeledEvent = reversedEvents.find(
|
||||
event => event.event === 'labeled' && event.label.name === label
|
||||
event =>
|
||||
event.event === 'labeled' &&
|
||||
cleanLabel(event.label.name) === cleanLabel(label)
|
||||
);
|
||||
|
||||
if (!staleLabeledEvent) {
|
||||
@@ -564,11 +594,30 @@ export class IssuesProcessor {
|
||||
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.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
|
||||
private async _processStaleIssue(
|
||||
issue: Issue,
|
||||
staleLabel: string,
|
||||
actor: string,
|
||||
staleMessage: string,
|
||||
labelsToAddWhenUnstale: Readonly<string>[],
|
||||
labelsToRemoveWhenUnstale: Readonly<string>[],
|
||||
closeMessage?: string,
|
||||
@@ -584,7 +633,7 @@ export class IssuesProcessor {
|
||||
const issueHasComments: boolean = await this._hasCommentsSince(
|
||||
issue,
|
||||
markedStaleOn,
|
||||
actor
|
||||
staleMessage
|
||||
);
|
||||
issueLogger.info(
|
||||
`$$type has been commented on: ${LoggerService.cyan(issueHasComments)}`
|
||||
@@ -656,7 +705,7 @@ export class IssuesProcessor {
|
||||
issueLogger.info(
|
||||
`Deleting the branch since the option ${issueLogger.createOptionLink(
|
||||
Option.DeleteBranch
|
||||
)} was specified`
|
||||
)} is enabled`
|
||||
);
|
||||
await this._deleteBranch(issue);
|
||||
this.deletedBranchIssues.push(issue);
|
||||
@@ -672,7 +721,7 @@ export class IssuesProcessor {
|
||||
private async _hasCommentsSince(
|
||||
issue: Issue,
|
||||
sinceDate: string,
|
||||
actor: string
|
||||
staleMessage: string
|
||||
): Promise<boolean> {
|
||||
const issueLogger: IssueLogger = new IssueLogger(issue);
|
||||
|
||||
@@ -688,11 +737,13 @@ export class IssuesProcessor {
|
||||
const comments = await this.listIssueComments(issue.number, sinceDate);
|
||||
|
||||
const filteredComments = comments.filter(
|
||||
comment => comment.user.type === 'User' && comment.user.login !== actor
|
||||
comment =>
|
||||
comment.user.type === 'User' &&
|
||||
comment.body.toLowerCase() !== staleMessage.toLowerCase()
|
||||
);
|
||||
|
||||
issueLogger.info(
|
||||
`Comments not made by actor or another bot: ${LoggerService.cyan(
|
||||
`Comments that are not the stale comment or another bot: ${LoggerService.cyan(
|
||||
filteredComments.length
|
||||
)}`
|
||||
);
|
||||
@@ -721,7 +772,7 @@ export class IssuesProcessor {
|
||||
if (!skipMessage) {
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
this._statistics?.incrementAddedItemsComment(issue);
|
||||
this.statistics?.incrementAddedItemsComment(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.createComment({
|
||||
@@ -738,8 +789,8 @@ export class IssuesProcessor {
|
||||
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
this._statistics?.incrementAddedItemsLabel(issue);
|
||||
this._statistics?.incrementStaleItemsCount(issue);
|
||||
this.statistics?.incrementAddedItemsLabel(issue);
|
||||
this.statistics?.incrementStaleItemsCount(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.addLabels({
|
||||
@@ -768,7 +819,8 @@ export class IssuesProcessor {
|
||||
if (closeMessage) {
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
this._statistics?.incrementAddedItemsComment(issue);
|
||||
this.statistics?.incrementAddedItemsComment(issue);
|
||||
this.addedCloseCommentIssues.push(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.createComment({
|
||||
@@ -786,7 +838,7 @@ export class IssuesProcessor {
|
||||
if (closeLabel) {
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
this._statistics?.incrementAddedItemsLabel(issue);
|
||||
this.statistics?.incrementAddedItemsLabel(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.addLabels({
|
||||
@@ -803,7 +855,7 @@ export class IssuesProcessor {
|
||||
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
this._statistics?.incrementClosedItemsCount(issue);
|
||||
this.statistics?.incrementClosedItemsCount(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.update({
|
||||
@@ -818,34 +870,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
|
||||
private async _deleteBranch(issue: Issue): Promise<void> {
|
||||
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) {
|
||||
issueLogger.info(
|
||||
@@ -861,7 +897,7 @@ export class IssuesProcessor {
|
||||
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
this._statistics?.incrementDeletedBranchesCount();
|
||||
this.statistics?.incrementDeletedBranchesCount();
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.git.deleteRef({
|
||||
@@ -896,7 +932,7 @@ export class IssuesProcessor {
|
||||
|
||||
try {
|
||||
this._consumeIssueOperation(issue);
|
||||
this._statistics?.incrementDeletedItemsLabelsCount(issue);
|
||||
this.statistics?.incrementDeletedItemsLabelsCount(issue);
|
||||
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.removeLabel({
|
||||
@@ -1030,7 +1066,7 @@ export class IssuesProcessor {
|
||||
|
||||
try {
|
||||
this.operations.consumeOperation();
|
||||
this._statistics?.incrementAddedItemsLabel(issue);
|
||||
this.statistics?.incrementAddedItemsLabel(issue);
|
||||
if (!this.options.debugOnly) {
|
||||
await this.client.issues.addLabels({
|
||||
owner: context.repo.owner,
|
||||
@@ -1057,7 +1093,7 @@ export class IssuesProcessor {
|
||||
);
|
||||
|
||||
await this._removeLabel(issue, staleLabel);
|
||||
this._statistics?.incrementUndoStaleItemsCount(issue);
|
||||
this.statistics?.incrementUndoStaleItemsCount(issue);
|
||||
}
|
||||
|
||||
private async _removeCloseLabel(
|
||||
@@ -1094,7 +1130,7 @@ export class IssuesProcessor {
|
||||
);
|
||||
|
||||
await this._removeLabel(issue, closeLabel, true);
|
||||
this._statistics?.incrementDeletedCloseItemsLabelsCount(issue);
|
||||
this.statistics?.incrementDeletedCloseItemsLabelsCount(issue);
|
||||
} else {
|
||||
issueLogger.info(
|
||||
LoggerService.white('└──'),
|
||||
|
||||
@@ -9,28 +9,28 @@ interface IGroupValue {
|
||||
|
||||
export class Statistics {
|
||||
private readonly _logger: Logger = new Logger();
|
||||
private _processedIssuesCount = 0;
|
||||
private _processedPullRequestsCount = 0;
|
||||
private _staleIssuesCount = 0;
|
||||
private _stalePullRequestsCount = 0;
|
||||
private _undoStaleIssuesCount = 0;
|
||||
private _undoStalePullRequestsCount = 0;
|
||||
private _operationsCount = 0;
|
||||
private _closedIssuesCount = 0;
|
||||
private _closedPullRequestsCount = 0;
|
||||
private _deletedIssuesLabelsCount = 0;
|
||||
private _deletedPullRequestsLabelsCount = 0;
|
||||
private _deletedCloseIssuesLabelsCount = 0;
|
||||
private _deletedClosePullRequestsLabelsCount = 0;
|
||||
private _deletedBranchesCount = 0;
|
||||
private _addedIssuesLabelsCount = 0;
|
||||
private _addedPullRequestsLabelsCount = 0;
|
||||
private _addedIssuesCommentsCount = 0;
|
||||
private _addedPullRequestsCommentsCount = 0;
|
||||
private _fetchedItemsCount = 0;
|
||||
private _fetchedItemsEventsCount = 0;
|
||||
private _fetchedItemsCommentsCount = 0;
|
||||
private _fetchedPullRequestsCount = 0;
|
||||
processedIssuesCount = 0;
|
||||
processedPullRequestsCount = 0;
|
||||
staleIssuesCount = 0;
|
||||
stalePullRequestsCount = 0;
|
||||
undoStaleIssuesCount = 0;
|
||||
undoStalePullRequestsCount = 0;
|
||||
operationsCount = 0;
|
||||
closedIssuesCount = 0;
|
||||
closedPullRequestsCount = 0;
|
||||
deletedIssuesLabelsCount = 0;
|
||||
deletedPullRequestsLabelsCount = 0;
|
||||
deletedCloseIssuesLabelsCount = 0;
|
||||
deletedClosePullRequestsLabelsCount = 0;
|
||||
deletedBranchesCount = 0;
|
||||
addedIssuesLabelsCount = 0;
|
||||
addedPullRequestsLabelsCount = 0;
|
||||
addedIssuesCommentsCount = 0;
|
||||
addedPullRequestsCommentsCount = 0;
|
||||
fetchedItemsCount = 0;
|
||||
fetchedItemsEventsCount = 0;
|
||||
fetchedItemsCommentsCount = 0;
|
||||
fetchedPullRequestsCount = 0;
|
||||
|
||||
incrementProcessedItemsCount(
|
||||
issue: Readonly<Issue>,
|
||||
@@ -66,7 +66,7 @@ export class Statistics {
|
||||
}
|
||||
|
||||
setOperationsCount(operationsCount: Readonly<number>): Statistics {
|
||||
this._operationsCount = operationsCount;
|
||||
this.operationsCount = operationsCount;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -105,7 +105,7 @@ export class Statistics {
|
||||
}
|
||||
|
||||
incrementDeletedBranchesCount(increment: Readonly<number> = 1): Statistics {
|
||||
this._deletedBranchesCount += increment;
|
||||
this.deletedBranchesCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -133,7 +133,7 @@ export class Statistics {
|
||||
}
|
||||
|
||||
incrementFetchedItemsCount(increment: Readonly<number> = 1): Statistics {
|
||||
this._fetchedItemsCount += increment;
|
||||
this.fetchedItemsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -141,7 +141,7 @@ export class Statistics {
|
||||
incrementFetchedItemsEventsCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._fetchedItemsEventsCount += increment;
|
||||
this.fetchedItemsEventsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -149,7 +149,7 @@ export class Statistics {
|
||||
incrementFetchedItemsCommentsCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._fetchedItemsCommentsCount += increment;
|
||||
this.fetchedItemsCommentsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -157,7 +157,7 @@ export class Statistics {
|
||||
incrementFetchedPullRequestsCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._fetchedPullRequestsCount += increment;
|
||||
this.fetchedPullRequestsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -185,7 +185,7 @@ export class Statistics {
|
||||
private _incrementProcessedIssuesCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._processedIssuesCount += increment;
|
||||
this.processedIssuesCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -193,7 +193,7 @@ export class Statistics {
|
||||
private _incrementProcessedPullRequestsCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._processedPullRequestsCount += increment;
|
||||
this.processedPullRequestsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -201,7 +201,7 @@ export class Statistics {
|
||||
private _incrementStaleIssuesCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._staleIssuesCount += increment;
|
||||
this.staleIssuesCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -209,7 +209,7 @@ export class Statistics {
|
||||
private _incrementStalePullRequestsCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._stalePullRequestsCount += increment;
|
||||
this.stalePullRequestsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -217,7 +217,7 @@ export class Statistics {
|
||||
private _incrementUndoStaleIssuesCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._undoStaleIssuesCount += increment;
|
||||
this.undoStaleIssuesCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -225,7 +225,7 @@ export class Statistics {
|
||||
private _incrementUndoStalePullRequestsCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._undoStalePullRequestsCount += increment;
|
||||
this.undoStalePullRequestsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -233,7 +233,7 @@ export class Statistics {
|
||||
private _incrementClosedIssuesCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._closedIssuesCount += increment;
|
||||
this.closedIssuesCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -241,7 +241,7 @@ export class Statistics {
|
||||
private _incrementClosedPullRequestsCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._closedPullRequestsCount += increment;
|
||||
this.closedPullRequestsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -249,7 +249,7 @@ export class Statistics {
|
||||
private _incrementDeletedIssuesLabelsCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._deletedIssuesLabelsCount += increment;
|
||||
this.deletedIssuesLabelsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -257,7 +257,7 @@ export class Statistics {
|
||||
private _incrementDeletedPullRequestsLabelsCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._deletedPullRequestsLabelsCount += increment;
|
||||
this.deletedPullRequestsLabelsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -265,7 +265,7 @@ export class Statistics {
|
||||
private _incrementDeletedCloseIssuesLabelsCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._deletedCloseIssuesLabelsCount += increment;
|
||||
this.deletedCloseIssuesLabelsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -273,7 +273,7 @@ export class Statistics {
|
||||
private _incrementDeletedClosePullRequestsLabelsCount(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._deletedClosePullRequestsLabelsCount += increment;
|
||||
this.deletedClosePullRequestsLabelsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -281,7 +281,7 @@ export class Statistics {
|
||||
private _incrementAddedIssuesLabel(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._addedIssuesLabelsCount += increment;
|
||||
this.addedIssuesLabelsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -289,7 +289,7 @@ export class Statistics {
|
||||
private _incrementAddedPullRequestsLabel(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._addedPullRequestsLabelsCount += increment;
|
||||
this.addedPullRequestsLabelsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -297,7 +297,7 @@ export class Statistics {
|
||||
private _incrementAddedIssuesComment(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._addedIssuesCommentsCount += increment;
|
||||
this.addedIssuesCommentsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -305,7 +305,7 @@ export class Statistics {
|
||||
private _incrementAddedPullRequestsComment(
|
||||
increment: Readonly<number> = 1
|
||||
): Statistics {
|
||||
this._addedPullRequestsCommentsCount += increment;
|
||||
this.addedPullRequestsCommentsCount += increment;
|
||||
|
||||
return this;
|
||||
}
|
||||
@@ -314,11 +314,11 @@ export class Statistics {
|
||||
this._logGroup('Processed items', [
|
||||
{
|
||||
name: 'Processed issues',
|
||||
count: this._processedIssuesCount
|
||||
count: this.processedIssuesCount
|
||||
},
|
||||
{
|
||||
name: 'Processed PRs',
|
||||
count: this._processedPullRequestsCount
|
||||
count: this.processedPullRequestsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -327,11 +327,11 @@ export class Statistics {
|
||||
this._logGroup('New stale items', [
|
||||
{
|
||||
name: 'New stale issues',
|
||||
count: this._staleIssuesCount
|
||||
count: this.staleIssuesCount
|
||||
},
|
||||
{
|
||||
name: 'New stale PRs',
|
||||
count: this._stalePullRequestsCount
|
||||
count: this.stalePullRequestsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -340,11 +340,11 @@ export class Statistics {
|
||||
this._logGroup('No longer stale items', [
|
||||
{
|
||||
name: 'No longer stale issues',
|
||||
count: this._undoStaleIssuesCount
|
||||
count: this.undoStaleIssuesCount
|
||||
},
|
||||
{
|
||||
name: 'No longer stale PRs',
|
||||
count: this._undoStalePullRequestsCount
|
||||
count: this.undoStalePullRequestsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -353,11 +353,11 @@ export class Statistics {
|
||||
this._logGroup('Closed items', [
|
||||
{
|
||||
name: 'Closed issues',
|
||||
count: this._closedIssuesCount
|
||||
count: this.closedIssuesCount
|
||||
},
|
||||
{
|
||||
name: 'Closed PRs',
|
||||
count: this._closedPullRequestsCount
|
||||
count: this.closedPullRequestsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -366,11 +366,11 @@ export class Statistics {
|
||||
this._logGroup('Deleted items labels', [
|
||||
{
|
||||
name: 'Deleted issues labels',
|
||||
count: this._deletedIssuesLabelsCount
|
||||
count: this.deletedIssuesLabelsCount
|
||||
},
|
||||
{
|
||||
name: 'Deleted PRs labels',
|
||||
count: this._deletedPullRequestsLabelsCount
|
||||
count: this.deletedPullRequestsLabelsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -379,28 +379,28 @@ export class Statistics {
|
||||
this._logGroup('Deleted close items labels', [
|
||||
{
|
||||
name: 'Deleted close issues labels',
|
||||
count: this._deletedCloseIssuesLabelsCount
|
||||
count: this.deletedCloseIssuesLabelsCount
|
||||
},
|
||||
{
|
||||
name: 'Deleted close PRs labels',
|
||||
count: this._deletedClosePullRequestsLabelsCount
|
||||
count: this.deletedClosePullRequestsLabelsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
private _logDeletedBranchesCount(): void {
|
||||
this._logCount('Deleted branches', this._deletedBranchesCount);
|
||||
this._logCount('Deleted branches', this.deletedBranchesCount);
|
||||
}
|
||||
|
||||
private _logAddedIssuesAndPullRequestsLabelsCount(): void {
|
||||
this._logGroup('Added items labels', [
|
||||
{
|
||||
name: 'Added issues labels',
|
||||
count: this._addedIssuesLabelsCount
|
||||
count: this.addedIssuesLabelsCount
|
||||
},
|
||||
{
|
||||
name: 'Added PRs labels',
|
||||
count: this._addedPullRequestsLabelsCount
|
||||
count: this.addedPullRequestsLabelsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
@@ -409,33 +409,33 @@ export class Statistics {
|
||||
this._logGroup('Added items comments', [
|
||||
{
|
||||
name: 'Added issues comments',
|
||||
count: this._addedIssuesCommentsCount
|
||||
count: this.addedIssuesCommentsCount
|
||||
},
|
||||
{
|
||||
name: 'Added PRs comments',
|
||||
count: this._addedPullRequestsCommentsCount
|
||||
count: this.addedPullRequestsCommentsCount
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
private _logFetchedItemsCount(): void {
|
||||
this._logCount('Fetched items', this._fetchedItemsCount);
|
||||
this._logCount('Fetched items', this.fetchedItemsCount);
|
||||
}
|
||||
|
||||
private _logFetchedItemsEventsCount(): void {
|
||||
this._logCount('Fetched items events', this._fetchedItemsEventsCount);
|
||||
this._logCount('Fetched items events', this.fetchedItemsEventsCount);
|
||||
}
|
||||
|
||||
private _logFetchedItemsCommentsCount(): void {
|
||||
this._logCount('Fetched items comments', this._fetchedItemsCommentsCount);
|
||||
this._logCount('Fetched items comments', this.fetchedItemsCommentsCount);
|
||||
}
|
||||
|
||||
private _logFetchedPullRequestsCount(): void {
|
||||
this._logCount('Fetched pull requests', this._fetchedPullRequestsCount);
|
||||
this._logCount('Fetched pull requests', this.fetchedPullRequestsCount);
|
||||
}
|
||||
|
||||
private _logOperationsCount(): void {
|
||||
this._logCount('Operations performed', this._operationsCount);
|
||||
this._logCount('Operations performed', this.operationsCount);
|
||||
}
|
||||
|
||||
private _logCount(name: Readonly<string>, count: Readonly<number>): void {
|
||||
|
||||
@@ -42,5 +42,9 @@ export enum Option {
|
||||
ExemptAllPrAssignees = 'exempt-all-pr-assignees',
|
||||
EnableStatistics = 'enable-statistics',
|
||||
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'
|
||||
}
|
||||
|
||||
14
src/functions/clean-label.ts
Normal file
14
src/functions/clean-label.ts
Normal file
@@ -0,0 +1,14 @@
|
||||
import deburr from 'lodash.deburr';
|
||||
import {CleanLabel} from '../types/clean-label';
|
||||
|
||||
/**
|
||||
* @description
|
||||
* Clean a label by lowercasing it and deburring it for consistency
|
||||
*
|
||||
* @param {string} label A raw GitHub label
|
||||
*
|
||||
* @return {string} A lowercased, deburred version of the passed in label
|
||||
*/
|
||||
export function cleanLabel(label: Readonly<string>): CleanLabel {
|
||||
return deburr(label.toLowerCase());
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import deburr from 'lodash.deburr';
|
||||
import {Issue} from '../classes/issue';
|
||||
import {ILabel} from '../interfaces/label';
|
||||
import {CleanLabel} from '../types/clean-label';
|
||||
import {cleanLabel} from './clean-label';
|
||||
|
||||
/**
|
||||
* @description
|
||||
@@ -20,7 +19,3 @@ export function isLabeled(
|
||||
return cleanLabel(label) === cleanLabel(issueLabel.name);
|
||||
});
|
||||
}
|
||||
|
||||
function cleanLabel(label: Readonly<string>): CleanLabel {
|
||||
return deburr(label.toLowerCase());
|
||||
}
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
export interface IAssignee {
|
||||
login: string;
|
||||
}
|
||||
// @todo improve to include the notion of team?
|
||||
interface IAssignee {
|
||||
type: string;
|
||||
}
|
||||
|
||||
export interface IUserAssignee extends IAssignee {
|
||||
login: string;
|
||||
type: 'User' | string;
|
||||
}
|
||||
|
||||
export type Assignee = IUserAssignee;
|
||||
|
||||
@@ -2,4 +2,5 @@ import {IUser} from './user';
|
||||
|
||||
export interface IComment {
|
||||
user: IUser;
|
||||
body: string;
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
import {IsoDateString} from '../types/iso-date-string';
|
||||
import {IAssignee} from './assignee';
|
||||
import {ILabel} from './label';
|
||||
import {IMilestone} from './milestone';
|
||||
|
||||
export interface IIssue {
|
||||
title: string;
|
||||
number: number;
|
||||
created_at: IsoDateString;
|
||||
updated_at: IsoDateString;
|
||||
labels: ILabel[];
|
||||
pull_request: Object | null | undefined;
|
||||
state: string;
|
||||
locked: boolean;
|
||||
milestone: IMilestone | undefined;
|
||||
assignees: IAssignee[];
|
||||
}
|
||||
import {IsoDateString} from '../types/iso-date-string';
|
||||
import {Assignee} from './assignee';
|
||||
import {ILabel} from './label';
|
||||
import {IMilestone} from './milestone';
|
||||
|
||||
export interface IIssue {
|
||||
title: string;
|
||||
number: number;
|
||||
created_at: IsoDateString;
|
||||
updated_at: IsoDateString;
|
||||
labels: ILabel[];
|
||||
pull_request: Object | null | undefined;
|
||||
state: string;
|
||||
locked: boolean;
|
||||
milestone: IMilestone | undefined;
|
||||
assignees: Assignee[];
|
||||
}
|
||||
|
||||
@@ -47,4 +47,8 @@ export interface IIssuesProcessorOptions {
|
||||
enableStatistics: boolean;
|
||||
labelsToRemoveWhenUnstale: string;
|
||||
labelsToAddWhenUnstale: string;
|
||||
ignoreUpdates: boolean;
|
||||
ignoreIssueUpdates: boolean | undefined;
|
||||
ignorePrUpdates: boolean | undefined;
|
||||
exemptDraftPr: boolean;
|
||||
}
|
||||
|
||||
@@ -3,4 +3,5 @@ export interface IPullRequest {
|
||||
head: {
|
||||
ref: string;
|
||||
};
|
||||
draft: boolean;
|
||||
}
|
||||
|
||||
21
src/main.ts
21
src/main.ts
@@ -57,10 +57,10 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
|
||||
core.getInput('remove-stale-when-updated') === 'false'
|
||||
),
|
||||
removeIssueStaleWhenUpdated: _toOptionalBoolean(
|
||||
core.getInput('remove-issue-stale-when-updated')
|
||||
'remove-issue-stale-when-updated'
|
||||
),
|
||||
removePrStaleWhenUpdated: _toOptionalBoolean(
|
||||
core.getInput('remove-pr-stale-when-updated')
|
||||
'remove-pr-stale-when-updated'
|
||||
),
|
||||
debugOnly: core.getInput('debug-only') === 'true',
|
||||
ascending: core.getInput('ascending') === 'true',
|
||||
@@ -83,7 +83,11 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
|
||||
exemptAllPrAssignees: _toOptionalBoolean('exempt-all-pr-assignees'),
|
||||
enableStatistics: core.getInput('enable-statistics') === 'true',
|
||||
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'
|
||||
};
|
||||
|
||||
for (const numberInput of [
|
||||
@@ -120,6 +124,17 @@ async function processOutput(
|
||||
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(
|
||||
argumentName: Readonly<string>
|
||||
): boolean | undefined {
|
||||
|
||||
Reference in New Issue
Block a user