feat(options): add new option ignore-updates to stale even with activity (#540)
* chore(assignees): add logs * docs(readme): use the override syntax to simplify the reading * docs(readme): add missing default options * docs(readme): add 3 new options to ignore activity before stale * chore(action): add 3 new options * fix(removeStaleWhenUpdated): use the value of the action config as expected Fixes #451 * chore(main): add 3 new options * feat(ignore): add new class to ignore all activities before stale * feat(option): add new options to ignore all activities before stale * chore(index): update index file * docs(readme): fix typo * docs(readme): add missing empty row * chore(rebase): fix logger issues due to rebase * chore: aplly changes due to rebase * refactor(naming): change the name of the options as suggested * chore(logs): reverse the logs as well * docs(readme): format the table of options * refactor(naming): rename the the options * style(rename): rename more updates wording to activities * build(ci): run the test step as expected for a CI instead of using a real linter with auto fix and the tests verbose as fuck * chore: handle breaking changes due to new changes * refactor(naming): rename and reverse the options * style(tests): use plural for some describe * docs(days-before-stale): list the new option * chore(index): update index file * chore: keep static methods on top * chore(logs): remove useless log
This commit is contained in:
parent
002bc97450
commit
1cdda06bb3
.github/workflows
CHANGELOG.mdREADME.md__tests__
any-of-labels.spec.ts
action.ymlconstants
functions
only-labels.spec.tsoperations-per-run.spec.tsupdates-reset-stale.spec.tsdist
package.jsonsrc
|
@ -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:
|
||||
|
|
21
CHANGELOG.md
21
CHANGELOG.md
|
@ -1,24 +1,23 @@
|
|||
# Changelog
|
||||
|
||||
Starting in version 4.0.0 we will maintain a changelog
|
||||
|
||||
## [4.0.0](https://github.com/actions/stale/compare/v3.0.19...v4.0.0) (2021-07-14)
|
||||
|
||||
|
||||
### Features
|
||||
|
||||
* **options:** simplify config by removing skip stale message options ([#457](https://github.com/actions/stale/issues/457)) ([6ec637d](https://github.com/actions/stale/commit/6ec637d238067ab8cc96c9289dcdac280bbd3f4a)), closes [#405](https://github.com/actions/stale/issues/405) [#455](https://github.com/actions/stale/issues/455)
|
||||
* **output:** print output parameters ([#458](https://github.com/actions/stale/issues/458)) ([3e6d35b](https://github.com/actions/stale/commit/3e6d35b685f0b2fa1a69be893fa07d3d85e05ee0))
|
||||
|
||||
- **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)
|
||||
- **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.
|
||||
- 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.
|
||||
|
|
133
README.md
133
README.md
|
@ -28,61 +28,64 @@ You can find more information about the required permissions under the correspon
|
|||
|
||||
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 | |
|
||||
| [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
|
||||
|
||||
|
@ -96,7 +99,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.
|
||||
|
@ -122,6 +127,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`
|
||||
|
||||
|
@ -473,6 +479,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.
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -46,5 +46,8 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
|
|||
exemptAllPrAssignees: undefined,
|
||||
enableStatistics: true,
|
||||
labelsToRemoveWhenUnstale: '',
|
||||
labelsToAddWhenUnstale: ''
|
||||
labelsToAddWhenUnstale: '',
|
||||
ignoreUpdates: false,
|
||||
ignoreIssueUpdates: undefined,
|
||||
ignorePrUpdates: undefined
|
||||
});
|
||||
|
|
|
@ -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'
|
||||
};
|
||||
})
|
||||
});
|
||||
|
|
|
@ -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();
|
||||
});
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
12
action.yml
12
action.yml
|
@ -176,6 +176,18 @@ inputs:
|
|||
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.'
|
||||
|
|
|
@ -141,6 +141,67 @@ class Assignees {
|
|||
exports.Assignees = Assignees;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 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:
|
||||
|
@ -236,6 +297,7 @@ 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 issue_1 = __nccwpck_require__(4783);
|
||||
const issue_logger_1 = __nccwpck_require__(2984);
|
||||
const logger_1 = __nccwpck_require__(6212);
|
||||
|
@ -248,12 +310,12 @@ 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._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);
|
||||
|
@ -278,11 +340,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;
|
||||
}
|
||||
|
@ -446,14 +503,27 @@ 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);
|
||||
// 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);
|
||||
|
@ -465,7 +535,12 @@ 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
|
||||
|
@ -1729,6 +1804,9 @@ 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 = exports.Option || (exports.Option = {}));
|
||||
|
||||
|
||||
|
@ -2013,8 +2091,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',
|
||||
|
@ -2035,7 +2113,10 @@ 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')
|
||||
};
|
||||
for (const numberInput of [
|
||||
'days-before-stale',
|
||||
|
@ -2066,6 +2147,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') {
|
||||
|
|
|
@ -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"
|
||||
|
|
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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -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,10 @@ describe('Issue', (): void => {
|
|||
exemptAllPrAssignees: undefined,
|
||||
enableStatistics: false,
|
||||
labelsToRemoveWhenUnstale: '',
|
||||
labelsToAddWhenUnstale: ''
|
||||
labelsToAddWhenUnstale: '',
|
||||
ignoreUpdates: false,
|
||||
ignoreIssueUpdates: undefined,
|
||||
ignorePrUpdates: undefined
|
||||
};
|
||||
issueInterface = {
|
||||
title: 'dummy-title',
|
||||
|
@ -77,7 +80,8 @@ describe('Issue', (): void => {
|
|||
},
|
||||
assignees: [
|
||||
{
|
||||
login: 'dummy-login'
|
||||
login: 'dummy-login',
|
||||
type: 'User'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
@ -150,8 +154,9 @@ describe('Issue', (): void => {
|
|||
|
||||
expect(issue.assignees).toStrictEqual([
|
||||
{
|
||||
login: 'dummy-login'
|
||||
} as IAssignee
|
||||
login: 'dummy-login',
|
||||
type: 'User'
|
||||
} as IUserAssignee
|
||||
]);
|
||||
});
|
||||
|
||||
|
@ -272,7 +277,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
|
||||
|
|
|
@ -12,11 +12,11 @@ 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 {Issue} from './issue';
|
||||
import {IssueLogger} from './loggers/issue-logger';
|
||||
import {Logger} from './loggers/logger';
|
||||
|
@ -24,6 +24,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.
|
||||
|
@ -53,22 +54,12 @@ export class IssuesProcessor {
|
|||
}
|
||||
}
|
||||
|
||||
private static _getStaleMessageUsedOptionName(
|
||||
issue: Readonly<Issue>
|
||||
): Option.StalePrMessage | Option.StaleIssueMessage {
|
||||
return issue.isPullRequest
|
||||
? Option.StalePrMessage
|
||||
: Option.StaleIssueMessage;
|
||||
}
|
||||
|
||||
private static _getCloseLabelUsedOptionName(
|
||||
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;
|
||||
|
@ -77,6 +68,8 @@ export class IssuesProcessor {
|
|||
readonly deletedBranchIssues: Issue[] = [];
|
||||
readonly removedLabelIssues: Issue[] = [];
|
||||
readonly addedLabelIssues: Issue[] = [];
|
||||
private readonly _logger: Logger = new Logger();
|
||||
private readonly _statistics: Statistics | undefined;
|
||||
|
||||
constructor(options: IIssuesProcessorOptions) {
|
||||
this.options = options;
|
||||
|
@ -404,23 +397,46 @@ export class IssuesProcessor {
|
|||
return; // Don't process exempt assignees
|
||||
}
|
||||
|
||||
// Should this issue be marked stale?
|
||||
const shouldBeStale = !IssuesProcessor._updatedSince(
|
||||
issue.updated_at,
|
||||
daysBeforeStale
|
||||
);
|
||||
|
||||
// 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(
|
||||
|
@ -439,11 +455,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)})`
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -42,5 +42,8 @@ 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'
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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,7 @@ export interface IIssuesProcessorOptions {
|
|||
enableStatistics: boolean;
|
||||
labelsToRemoveWhenUnstale: string;
|
||||
labelsToAddWhenUnstale: string;
|
||||
ignoreUpdates: boolean;
|
||||
ignoreIssueUpdates: boolean | undefined;
|
||||
ignorePrUpdates: boolean | undefined;
|
||||
}
|
||||
|
|
20
src/main.ts
20
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,10 @@ 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')
|
||||
};
|
||||
|
||||
for (const numberInput of [
|
||||
|
@ -120,6 +123,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 {
|
||||
|
|
Loading…
Reference in New Issue