Compare commits

..

4 Commits

Author SHA1 Message Date
Luke Tomlinson
cc8ff56517 Revert debugging 2021-05-12 14:02:04 -04:00
Luke Tomlinson
ab559aee86 update 2021-05-12 13:56:50 -04:00
Luke Tomlinson
ffc3c749f4 Dist 2021-05-12 13:37:22 -04:00
Luke Tomlinson
93db9b6708 Update issues-processor.ts 2021-05-12 13:35:50 -04:00
53 changed files with 1893 additions and 9028 deletions

View File

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

View File

@@ -1 +0,0 @@
blank_issues_enabled: false

View File

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

View File

@@ -1,13 +0,0 @@
---
name: Other issue report
about: Report other issue
title: ''
labels: bug
assignees: ''
---
## Describe your issue
## Further context
<!-- If helpful please provide screenshots, logs, links to other related issues. -->

View File

@@ -1,28 +0,0 @@
---
name: Stale issue report
about: Report issues with using the stale action
title: ''
labels: bug
assignees: ''
---
<!-- Have you tried the [debugging](https://github.com/actions/stale#debugging) section of the readme? -->
## Describe your issue
## Your stale action configuration
<!-- This is an example config, please copy/paste your config into it. -->
```yml
jobs:
stale:
runs-on: ...
steps:
- uses: actions/stale@...
with: ...
```
## Further context
<!-- If helpful please provide screenshots, logs, links to other related issues. -->

View File

@@ -1,10 +0,0 @@
<!-- List the change(s) you're making with this PR. -->
## Changes
- [x] ...
## Context
<!-- Explain why you're making the change(s). -->
<!-- If you're closing an issue with this PR, [link them with a keyword](https://docs.github.com/en/github/managing-your-work-on-github/linking-a-pull-request-to-an-issue#linking-a-pull-request-to-an-issue-using-a-keyword). -->

View File

@@ -2,8 +2,6 @@ name: 'Code scanning'
on:
push:
branches:
- main
pull_request:
schedule:
- cron: '0 19 * * 0'

View File

@@ -9,11 +9,8 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@main
id: stale
with:
stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days'
days-before-stale: 30
days-before-close: 5
exempt-issue-labels: 'blocked,must,should,keep'
- name: Print outputs
run: echo ${{ join(steps.stale.outputs.*, ',') }}

View File

@@ -12,17 +12,14 @@ jobs:
steps:
- uses: actions/checkout@v2
- run: |
npm ci
npm install
npm run all
test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: ./
id: stale
with:
stale-issue-message: 'This issue is stale'
stale-pr-message: 'This PR is stale'
debug-only: true
- name: Print outputs
run: echo ${{ join(steps.stale.outputs.*, ',') }}

View File

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

View File

@@ -1,24 +0,0 @@
# Changelog
Starting in version 4.0.0 we will maintain a changelog
## [4.0.0](https://github.com/actions/stale/compare/v3.0.19...v4.0.0) (2021-07-14)
### Features
* **options:** simplify config by removing skip stale message options ([#457](https://github.com/actions/stale/issues/457)) ([6ec637d](https://github.com/actions/stale/commit/6ec637d238067ab8cc96c9289dcdac280bbd3f4a)), closes [#405](https://github.com/actions/stale/issues/405) [#455](https://github.com/actions/stale/issues/455)
* **output:** print output parameters ([#458](https://github.com/actions/stale/issues/458)) ([3e6d35b](https://github.com/actions/stale/commit/3e6d35b685f0b2fa1a69be893fa07d3d85e05ee0))
### Bug Fixes
* **dry-run:** forbid mutations in dry-run ([#500](https://github.com/actions/stale/issues/500)) ([f1017f3](https://github.com/actions/stale/commit/f1017f33dd159ea51366375120c3e6981d7c3097)), closes [#499](https://github.com/actions/stale/issues/499)
* **logs:** coloured logs ([#465](https://github.com/actions/stale/issues/465)) ([5fbbfba](https://github.com/actions/stale/commit/5fbbfba142860ea6512549e96e36e3540c314132))
* **operations:** fail fast the current batch to respect the operations limit ([#474](https://github.com/actions/stale/issues/474)) ([5f6f311](https://github.com/actions/stale/commit/5f6f311ca6aa75babadfc7bac6edf5d85fa3f35d)), closes [#466](https://github.com/actions/stale/issues/466)
* **label comparison**: make label comparison case insensitive [#517](https://github.com/actions/stale/pull/517), closes [#516](https://github.com/actions/stale/pull/516)
* **filtering comments by actor could have strange behavior**: "stale" comments are now detected based on if the message is the stale message not _who_ made the comment([#519](https://github.com/actions/stale/pull/519)), fixes [#441](https://github.com/actions/stale/pull/441), [#509](https://github.com/actions/stale/pull/509), [#518](https://github.com/actions/stale/pull/518)
### Breaking Changes
* The options `skip-stale-issue-message` and `skip-stale-pr-message` were removed. Instead, setting the options `stale-issue-message` and `stale-pr-message` will be enough to let the stale workflow add a comment. If the options are unset, a comment will not be added which was the equivalent of setting `skip-stale-issue-message` to `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.

View File

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

550
README.md
View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@@ -22,14 +22,12 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
onlyIssueLabels: '',
onlyPrLabels: '',
anyOfLabels: '',
anyOfIssueLabels: '',
anyOfPrLabels: '',
operationsPerRun: 100,
debugOnly: true,
removeStaleWhenUpdated: false,
removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined,
ascending: false,
skipStaleIssueMessage: false,
skipStalePrMessage: false,
deleteBranch: false,
startDate: '',
exemptMilestones: '',
@@ -44,7 +42,5 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
exemptAllAssignees: false,
exemptAllIssueAssignees: undefined,
exemptAllPrAssignees: undefined,
enableStatistics: true,
labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: ''
enableStatistics: false
});

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

@@ -1,555 +0,0 @@
import {Issue} from '../src/classes/issue';
import {IIssue} from '../src/interfaces/issue';
import {IIssuesProcessorOptions} from '../src/interfaces/issues-processor-options';
import {ILabel} from '../src/interfaces/label';
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;
/**
* @description
* Assuming there is a comment on the issue
*/
describe('remove-stale-when-updated option', (): void => {
beforeEach((): void => {
issuesProcessorBuilder = new IssuesProcessorBuilder();
});
describe('when the option "remove-stale-when-updated" is disabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.keepStaleWhenUpdated();
});
test('should not remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
test('should not remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the option "remove-stale-when-updated" is enabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.removeStaleWhenUpdated();
});
test('should remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
test('should remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
});
});
describe('remove-issue-stale-when-updated option', (): void => {
beforeEach((): void => {
issuesProcessorBuilder = new IssuesProcessorBuilder();
});
describe('when the option "remove-stale-when-updated" is disabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.keepStaleWhenUpdated();
});
describe('when the option "remove-issue-stale-when-updated" is unset', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.unsetIssueStaleWhenUpdated();
});
test('should not remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
test('should not remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the option "remove-issue-stale-when-updated" is disabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.keepIssueStaleWhenUpdated();
});
test('should not remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
test('should not remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the option "remove-issue-stale-when-updated" is enabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.removeIssueStaleWhenUpdated();
});
test('should remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
test('should not remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
});
});
describe('when the option "remove-stale-when-updated" is enabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.removeStaleWhenUpdated();
});
describe('when the option "remove-issue-stale-when-updated" is unset', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.unsetIssueStaleWhenUpdated();
});
test('should remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
test('should remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
});
describe('when the option "remove-issue-stale-when-updated" is disabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.keepIssueStaleWhenUpdated();
});
test('should not remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
test('should remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
});
describe('when the option "remove-issue-stale-when-updated" is enabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.removeIssueStaleWhenUpdated();
});
test('should remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
test('should remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
});
});
});
describe('remove-pr-stale-when-updated option', (): void => {
beforeEach((): void => {
issuesProcessorBuilder = new IssuesProcessorBuilder();
});
describe('when the option "remove-stale-when-updated" is disabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.keepStaleWhenUpdated();
});
describe('when the option "remove-pr-stale-when-updated" is unset', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.unsetPrStaleWhenUpdated();
});
test('should not remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
test('should not remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the option "remove-pr-stale-when-updated" is disabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.keepPrStaleWhenUpdated();
});
test('should not remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
test('should not remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the option "remove-pr-stale-when-updated" is enabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.removePrStaleWhenUpdated();
});
test('should not remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
test('should remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
});
});
describe('when the option "remove-stale-when-updated" is enabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.removeStaleWhenUpdated();
});
describe('when the option "remove-pr-stale-when-updated" is unset', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.unsetPrStaleWhenUpdated();
});
test('should remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
test('should remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
});
describe('when the option "remove-pr-stale-when-updated" is disabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.keepPrStaleWhenUpdated();
});
test('should remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
test('should not remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(0);
});
});
describe('when the option "remove-pr-stale-when-updated" is enabled', (): void => {
beforeEach((): void => {
issuesProcessorBuilder.removePrStaleWhenUpdated();
});
test('should remove the stale label on the issue', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.staleIssues([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
test('should remove the stale label on the pull request', async (): Promise<void> => {
expect.assertions(1);
issuesProcessor = issuesProcessorBuilder.stalePrs([{}]).build();
await issuesProcessor.processIssues();
expect(issuesProcessor.removedLabelIssues).toHaveLength(1);
});
});
});
});
class IssuesProcessorBuilder {
private _options: IIssuesProcessorOptions = {
...DefaultProcessorOptions
};
private _issues: Issue[] = [];
keepStaleWhenUpdated(): IssuesProcessorBuilder {
this._options.removeStaleWhenUpdated = false;
return this;
}
removeStaleWhenUpdated(): IssuesProcessorBuilder {
this._options.removeStaleWhenUpdated = true;
return this;
}
unsetIssueStaleWhenUpdated(): IssuesProcessorBuilder {
delete this._options.removeIssueStaleWhenUpdated;
return this;
}
keepIssueStaleWhenUpdated(): IssuesProcessorBuilder {
this._options.removeIssueStaleWhenUpdated = false;
return this;
}
removeIssueStaleWhenUpdated(): IssuesProcessorBuilder {
this._options.removeIssueStaleWhenUpdated = true;
return this;
}
unsetPrStaleWhenUpdated(): IssuesProcessorBuilder {
delete this._options.removePrStaleWhenUpdated;
return this;
}
keepPrStaleWhenUpdated(): IssuesProcessorBuilder {
this._options.removePrStaleWhenUpdated = false;
return this;
}
removePrStaleWhenUpdated(): IssuesProcessorBuilder {
this._options.removePrStaleWhenUpdated = true;
return this;
}
issuesOrPrs(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this._issues = issues.map(
(issue: Readonly<Partial<IIssue>>, index: Readonly<number>): Issue =>
generateIssue(
this._options,
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;
}
issues(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issuesOrPrs(
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
pull_request: null
};
})
);
return this;
}
staleIssues(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.issues(
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
updated_at: '2020-01-01T17:00:00Z',
created_at: '2020-01-01T17:00:00Z',
labels: issue.labels?.map((label: Readonly<ILabel>): ILabel => {
return {
...label,
name: 'Stale'
};
}) ?? [
{
name: 'Stale'
}
]
};
})
);
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;
}
stalePrs(issues: Partial<IIssue>[]): IssuesProcessorBuilder {
this.prs(
issues.map((issue: Readonly<Partial<IIssue>>): Partial<IIssue> => {
return {
...issue,
updated_at: '2020-01-01T17:00:00Z',
created_at: '2020-01-01T17:00:00Z',
labels: issue.labels?.map((label: Readonly<ILabel>): ILabel => {
return {
...label,
name: 'Stale'
};
}) ?? [
{
name: 'Stale'
}
]
};
})
);
return this;
}
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
async p => (p === 1 ? this._issues : []),
async () => [
{
user: {
login: 'notme',
type: 'User'
},
body: 'body'
}
],
async () => new Date().toDateString()
);
}
}

View File

@@ -92,14 +92,6 @@ inputs:
description: 'Only issues or pull requests with at least one of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels.'
default: ''
required: false
any-of-issue-labels:
description: 'Only issues with at least one of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels. Override "any-of-labels" option regarding only the issues.'
default: ''
required: false
any-of-pr-labels:
description: 'Only pull requests with at least one of these labels are checked if stale. Defaults to `` (disabled) and can be a comma-separated list of labels. Override "any-of-labels" option regarding only the pull requests.'
default: ''
required: false
only-issue-labels:
description: 'Only issues with all of these labels are checked if stale. Defaults to `[]` (disabled) and can be a comma-separated list of labels. Override "only-labels" option regarding only the issues.'
default: ''
@@ -113,17 +105,9 @@ inputs:
default: '30'
required: false
remove-stale-when-updated:
description: 'Remove stale labels from issues and pull requests when they are updated or commented on.'
description: 'Remove stale labels from issues when they are updated or commented on.'
default: 'true'
required: false
remove-issue-stale-when-updated:
description: 'Remove stale labels from issues when they are updated or commented on. Override "remove-stale-when-updated" option regarding only the issues.'
default: ''
required: false
remove-pr-stale-when-updated:
description: 'Remove stale labels from pull requests when they are updated or commented on. Override "remove-stale-when-updated" option regarding only the pull requests.'
default: ''
required: false
debug-only:
description: 'Run the processor in debug mode without actually performing any operations on live issues.'
default: 'false'
@@ -132,6 +116,14 @@ inputs:
description: 'The order to get issues or pull requests. Defaults to false, which is descending.'
default: 'false'
required: false
skip-stale-pr-message:
description: 'Skip adding stale message when marking a pull request as stale.'
default: 'false'
required: false
skip-stale-issue-message:
description: 'Skip adding stale message when marking an issue as stale.'
default: 'false'
required: false
delete-branch:
description: 'Delete the git branch after closing a stale pull request.'
default: 'false'
@@ -168,11 +160,6 @@ inputs:
description: 'Display some statistics at the end regarding the stale workflow (only when the logs are enabled).'
default: 'true'
required: false
outputs:
closed-issues-prs:
description: 'List of all closed issues and pull requests.'
staled-issues-prs:
description: 'List of all staled issues and pull requests.'
runs:
using: 'node12'
main: 'dist/index.js'

2266
dist/index.js vendored

File diff suppressed because it is too large Load Diff

2216
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -15,11 +15,8 @@
"pack": "ncc build",
"test": "jest",
"test:only-errors": "jest --reporters jest-silent-reporter --silent",
"test:watch": "jest --watch --notify --expand",
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test",
"prerelease": "npm run build && npm run pack",
"release": "standard-version",
"release:dry-run": "standard-version --dry-run"
"test:watch": "jest --watch --notify --expandf",
"all": "npm run build && npm run format && npm run lint && npm run pack && npm test"
},
"repository": {
"type": "git",
@@ -30,38 +27,32 @@
"node",
"stale"
],
"engines": {
"node": "12",
"npm": "6"
},
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0",
"@octokit/rest": "^18.3.3",
"lodash.deburr": "^4.1.0",
"semver": "^7.3.5"
"semver": "^7.3.4"
},
"devDependencies": {
"@types/jest": "^26.0.23",
"@types/jest": "^26.0.20",
"@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.28.6",
"ansi-styles": "5.2.0",
"eslint": "^7.28.0",
"@types/node": "^14.14.31",
"@types/semver": "^7.3.4",
"@typescript-eslint/eslint-plugin": "^4.16.1",
"@typescript-eslint/parser": "^4.16.1",
"@vercel/ncc": "^0.27.0",
"eslint": "^7.21.0",
"eslint-plugin-github": "^4.1.2",
"eslint-plugin-jest": "^24.3.6",
"eslint-plugin-jest": "^24.1.5",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"jest-silent-reporter": "^0.4.0",
"js-yaml": "^4.1.0",
"prettier": "^2.3.1",
"standard-version": "^9.2.0",
"terminal-link": "^2.1.1",
"ts-jest": "^26.5.6",
"typescript": "^4.3.2"
"js-yaml": "^4.0.0",
"prettier": "^2.2.1",
"ts-jest": "^26.5.3",
"typescript": "^4.2.3"
}
}

View File

@@ -2,8 +2,8 @@ import {DefaultProcessorOptions} from '../../__tests__/constants/default-process
import {generateIIssue} from '../../__tests__/functions/generate-iissue';
import {IIssue} from '../interfaces/issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Assignees} from './assignees';
import {Issue} from './issue';
import {Assignees} from './assignees';
describe('Assignees', (): void => {
let assignees: Assignees;
@@ -12,10 +12,7 @@ describe('Assignees', (): void => {
let issueInterface: IIssue;
beforeEach((): void => {
optionsInterface = {
...DefaultProcessorOptions,
exemptAllAssignees: false
};
optionsInterface = {...DefaultProcessorOptions};
issueInterface = generateIIssue();
});
@@ -306,132 +303,6 @@ describe('Assignees', (): void => {
});
});
});
describe('when the given options are configured to exempt all assignees', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllAssignees = true;
});
describe('when the given issue does not have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [];
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(false);
});
});
describe('when the given issue does have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
login: 'dummy-exempt-assignee'
}
];
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(true);
});
});
describe('when the given options are not configured to exempt all issue assignees', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllIssueAssignees = false;
});
describe('when the given issue does not have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [];
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(false);
});
});
describe('when the given issue does have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
login: 'dummy-exempt-assignee'
}
];
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(false);
});
});
});
describe('when the given options are configured to exempt all issue assignees', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllIssueAssignees = true;
});
describe('when the given issue does not have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [];
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(false);
});
});
describe('when the given issue does have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
login: 'dummy-exempt-issue-assignee'
}
];
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(true);
});
});
});
});
});
describe('when the given issue is a pull request', (): void => {
@@ -449,7 +320,7 @@ describe('Assignees', (): void => {
optionsInterface.exemptPrAssignees = '';
});
describe('when the given pull request does not have an assignee', (): void => {
describe('when the given issue does not have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [];
});
@@ -465,7 +336,7 @@ describe('Assignees', (): void => {
});
});
describe('when the given pull request does have an assignee', (): void => {
describe('when the given issue does have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
@@ -491,7 +362,7 @@ describe('Assignees', (): void => {
optionsInterface.exemptPrAssignees = 'dummy-exempt-pr-assignee';
});
describe('when the given pull request does not have an assignee', (): void => {
describe('when the given issue does not have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [];
});
@@ -507,7 +378,7 @@ describe('Assignees', (): void => {
});
});
describe('when the given pull request does have an assignee different than the exempt pull request assignee', (): void => {
describe('when the given issue does have an assignee different than the exempt pull request assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
@@ -527,7 +398,7 @@ describe('Assignees', (): void => {
});
});
describe('when the given pull request does have an assignee equaling the exempt pull request assignee', (): void => {
describe('when the given issue does have an assignee equaling the exempt pull request assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
@@ -559,7 +430,7 @@ describe('Assignees', (): void => {
optionsInterface.exemptPrAssignees = '';
});
describe('when the given pull request does not have an assignee', (): void => {
describe('when the given issue does not have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [];
});
@@ -575,7 +446,7 @@ describe('Assignees', (): void => {
});
});
describe('when the given pull request does have an assignee different than the exempt assignee', (): void => {
describe('when the given issue does have an assignee different than the exempt assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
@@ -595,7 +466,7 @@ describe('Assignees', (): void => {
});
});
describe('when the given pull request does have an assignee equaling the exempt assignee', (): void => {
describe('when the given issue does have an assignee equaling the exempt assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
@@ -621,7 +492,7 @@ describe('Assignees', (): void => {
optionsInterface.exemptPrAssignees = 'dummy-exempt-pr-assignee';
});
describe('when the given pull request does not have an assignee', (): void => {
describe('when the given issue does not have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [];
});
@@ -637,7 +508,7 @@ describe('Assignees', (): void => {
});
});
describe('when the given pull request does have an assignee different than the exempt pull request assignee', (): void => {
describe('when the given issue does have an assignee different than the exempt pull request assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
@@ -657,7 +528,7 @@ describe('Assignees', (): void => {
});
});
describe('when the given pull request does have an assignee equaling the exempt pull request assignee', (): void => {
describe('when the given issue does have an assignee equaling the exempt pull request assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
@@ -677,7 +548,7 @@ describe('Assignees', (): void => {
});
});
describe('when the given pull request does have an assignee different than the exempt assignee', (): void => {
describe('when the given issue does have an assignee different than the exempt assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
@@ -697,7 +568,7 @@ describe('Assignees', (): void => {
});
});
describe('when the given pull request does have an assignee equaling the exempt assignee', (): void => {
describe('when the given issue does have an assignee equaling the exempt assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
@@ -718,132 +589,6 @@ describe('Assignees', (): void => {
});
});
});
describe('when the given options are configured to exempt all assignees', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllAssignees = true;
});
describe('when the given pull request does not have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [];
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(false);
});
});
describe('when the given pull request does have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
login: 'dummy-exempt-assignee'
}
];
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(true);
});
});
describe('when the given options are not configured to exempt all pull request assignees', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllPrAssignees = false;
});
describe('when the given pull request does not have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [];
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(false);
});
});
describe('when the given pull request does have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
login: 'dummy-exempt-assignee'
}
];
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(false);
});
});
});
describe('when the given options are configured to exempt all pull request assignees', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllPrAssignees = true;
});
describe('when the given pull request does not have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [];
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(false);
});
});
describe('when the given pull request does have an assignee', (): void => {
beforeEach((): void => {
issueInterface.assignees = [
{
login: 'dummy-exempt-issue-assignee'
}
];
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
assignees = new Assignees(optionsInterface, issue);
const result = assignees.shouldExemptAssignees();
expect(result).toStrictEqual(true);
});
});
});
});
});
});
});

View File

@@ -1,11 +1,9 @@
import deburr from 'lodash.deburr';
import {Option} from '../enums/option';
import {wordsToList} from '../functions/words-to-list';
import {IAssignee} from '../interfaces/assignee';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
import {LoggerService} from '../services/logger.service';
type CleanAssignee = string;
@@ -34,8 +32,7 @@ export class Assignees {
if (this._shouldExemptAllAssignees()) {
this._issueLogger.info(
LoggerService.white('└──'),
'Skipping this $$type because it has an exempt assignee'
'Skipping $$type because it has an exempt assignee'
);
return true;
@@ -45,8 +42,7 @@ export class Assignees {
if (exemptAssignees.length === 0) {
this._issueLogger.info(
LoggerService.white('├──'),
`No assignee option was specified to skip the stale process for this $$type`
`No option was specified to skip the stale process for this $$type`
);
this._logSkip();
@@ -54,10 +50,9 @@ export class Assignees {
}
this._issueLogger.info(
LoggerService.white('├──'),
`Found ${LoggerService.cyan(exemptAssignees.length)} assignee${
`Found ${exemptAssignees.length} assignee${
exemptAssignees.length > 1 ? 's' : ''
} that can exempt stale on this $$type`
} on this $$type`
);
const hasExemptAssignee: boolean = exemptAssignees.some(
@@ -67,13 +62,11 @@ export class Assignees {
if (!hasExemptAssignee) {
this._issueLogger.info(
LoggerService.white('├──'),
'No assignee on this $$type can exempt the stale process'
);
this._logSkip();
} else {
this._issueLogger.info(
LoggerService.white('└──'),
'Skipping this $$type because it has an exempt assignee'
);
}
@@ -90,18 +83,12 @@ export class Assignees {
private _getExemptIssueAssignees(): string[] {
if (this._options.exemptIssueAssignees === '') {
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
'The option "exemptIssueAssignees" is disabled. No specific assignee can skip the stale process for this $$type'
);
if (this._options.exemptAssignees === '') {
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
'The option "exemptAssignees" is disabled. No specific assignee can skip the stale process for this $$type'
);
return [];
@@ -112,10 +99,9 @@ export class Assignees {
);
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
`The option "exemptAssignees" is set. ${
exemptAssignees.length
} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -128,10 +114,9 @@ export class Assignees {
);
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueAssignees
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
`The option "exemptIssueAssignees" is set. ${
exemptAssignees.length
} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -142,18 +127,12 @@ export class Assignees {
private _getExemptPullRequestAssignees(): string[] {
if (this._options.exemptPrAssignees === '') {
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
'The option "exemptPrAssignees" is disabled. No specific assignee can skip the stale process for this $$type'
);
if (this._options.exemptAssignees === '') {
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is disabled. No specific assignee can skip the stale process for this $$type`
'The option "exemptAssignees" is disabled. No specific assignee can skip the stale process for this $$type'
);
return [];
@@ -164,10 +143,9 @@ export class Assignees {
);
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAssignees
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
`The option "exemptAssignees" is set. ${
exemptAssignees.length
} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -180,10 +158,9 @@ export class Assignees {
);
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrAssignees
)} is set. ${LoggerService.cyan(exemptAssignees.length)} assignee${
`The option "exemptPrAssignees" is set. ${
exemptAssignees.length
} assignee${
exemptAssignees.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
@@ -201,7 +178,6 @@ export class Assignees {
if (isSameAssignee) {
this._issueLogger.info(
LoggerService.white('├──'),
`@${issueAssignee.login} is assigned on this $$type and is an exempt assignee`
);
}
@@ -220,17 +196,13 @@ export class Assignees {
private _shouldExemptAllIssueAssignees(): boolean {
if (this._options.exemptAllIssueAssignees === true) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllIssueAssignees
)} is enabled. Any assignee on this $$type will skip the stale process`
'The option "exemptAllIssueAssignees" is enabled. Any assignee on this $$type will skip the stale process'
);
return true;
} else if (this._options.exemptAllIssueAssignees === false) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllIssueAssignees
)} is disabled. Only some specific assignees on this $$type will skip the stale process`
'The option "exemptAllIssueAssignees" is disabled. Only some specific assignees on this $$type will skip the stale process'
);
return false;
@@ -244,17 +216,13 @@ export class Assignees {
private _shouldExemptAllPullRequestAssignees(): boolean {
if (this._options.exemptAllPrAssignees === true) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllPrAssignees
)} is enabled. Any assignee on this $$type will skip the stale process`
'The option "exemptAllPrAssignees" is enabled. Any assignee on this $$type will skip the stale process'
);
return true;
} else if (this._options.exemptAllPrAssignees === false) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllPrAssignees
)} is disabled. Only some specific assignees on this $$type will skip the stale process`
'The option "exemptAllPrAssignees" is disabled. Only some specific assignees on this $$type will skip the stale process'
);
return false;
@@ -268,23 +236,16 @@ export class Assignees {
private _logExemptAllAssigneesOption(): void {
if (this._options.exemptAllAssignees) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllAssignees
)} is enabled. Any assignee on this $$type will skip the stale process`
'The option "exemptAllAssignees" is enabled. Any assignee on this $$type will skip the stale process'
);
} else {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllAssignees
)} is disabled. Only some specific assignees on this $$type will skip the stale process`
'The option "exemptAllAssignees" is disabled. Only some specific assignees on this $$type will skip the stale process'
);
}
}
private _logSkip(): void {
this._issueLogger.info(
LoggerService.white('└──'),
'Skip the assignees checks'
);
this._issueLogger.info('Skip the assignees checks');
}
}

View File

@@ -31,13 +31,11 @@ describe('Issue', (): void => {
onlyIssueLabels: '',
onlyPrLabels: '',
anyOfLabels: '',
anyOfIssueLabels: '',
anyOfPrLabels: '',
operationsPerRun: 0,
removeStaleWhenUpdated: false,
removeIssueStaleWhenUpdated: undefined,
removePrStaleWhenUpdated: undefined,
repoToken: '',
skipStaleIssueMessage: false,
skipStalePrMessage: false,
staleIssueMessage: '',
stalePrMessage: '',
startDate: undefined,
@@ -55,9 +53,7 @@ describe('Issue', (): void => {
exemptAllAssignees: false,
exemptAllIssueAssignees: undefined,
exemptAllPrAssignees: undefined,
enableStatistics: false,
labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: ''
enableStatistics: false
};
issueInterface = {
title: 'dummy-title',

View File

@@ -6,7 +6,6 @@ import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {ILabel} from '../interfaces/label';
import {IMilestone} from '../interfaces/milestone';
import {IsoDateString} from '../types/iso-date-string';
import {Operations} from './operations';
export class Issue implements IIssue {
private readonly _options: IIssuesProcessorOptions;
@@ -21,19 +20,6 @@ export class Issue implements IIssue {
readonly milestone: IMilestone | undefined;
readonly assignees: IAssignee[];
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;
}
constructor(
options: Readonly<IIssuesProcessorOptions>,
@@ -54,6 +40,18 @@ export class Issue implements IIssue {
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

File diff suppressed because it is too large Load Diff

View File

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

View File

@@ -1,6 +1,6 @@
import * as core from '@actions/core';
import {Issue} from '../issue';
import {Logger} from './logger';
import {LoggerService} from '../../services/logger.service';
/**
* @description
@@ -15,28 +15,23 @@ import {LoggerService} from '../../services/logger.service';
* @example
* warning('The $$type will stale') => "The pull request will stale"
*/
export class IssueLogger extends Logger {
export class IssueLogger implements Logger {
private readonly _issue: Issue;
constructor(issue: Issue) {
super();
this._issue = issue;
}
warning(...message: string[]): void {
super.warning(this._format(...message));
warning(message: Readonly<string>): void {
core.warning(this._format(message));
}
info(...message: string[]): void {
super.info(this._format(...message));
info(message: Readonly<string>): void {
core.info(this._format(message));
}
error(...message: string[]): void {
super.error(this._format(...message));
}
async grouping(message: string, fn: () => Promise<void>): Promise<void> {
return super.grouping(this._format(message), fn);
error(message: Readonly<string>): void {
core.error(this._format(message));
}
private _replaceTokens(message: Readonly<string>): string {
@@ -56,28 +51,14 @@ export class IssueLogger extends Logger {
}
private _prefixWithIssueNumber(message: Readonly<string>): string {
return `${this._getPrefix()} ${message}`;
return `[#${this._getIssueNumber()}] ${message}`;
}
private _getIssueNumber(): number {
return this._issue.number;
}
private _format(...message: string[]): string {
return this._prefixWithIssueNumber(this._replaceTokens(message.join(' ')));
}
private _getPrefix(): string {
return this._issue.isPullRequest
? this._getPullRequestPrefix()
: this._getIssuePrefix();
}
private _getIssuePrefix(): string {
return LoggerService.red(`[#${this._getIssueNumber()}]`);
}
private _getPullRequestPrefix(): string {
return LoggerService.blue(`[#${this._getIssueNumber()}]`);
private _format(message: Readonly<string>): string {
return this._prefixWithIssueNumber(this._replaceTokens(message));
}
}

View File

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

View File

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

View File

@@ -12,7 +12,7 @@ describe('Milestones', (): void => {
let issueInterface: IIssue;
beforeEach((): void => {
optionsInterface = {...DefaultProcessorOptions, exemptAllMilestones: false};
optionsInterface = {...DefaultProcessorOptions};
issueInterface = generateIIssue();
});
@@ -285,126 +285,6 @@ describe('Milestones', (): void => {
});
});
});
describe('when the given options are configured to exempt all milestones', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllMilestones = true;
});
describe('when the given issue does not have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = undefined;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(false);
});
});
describe('when the given issue does have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-exempt-issue-milestone'
};
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(true);
});
});
describe('when the given options are not configured to exempt all issue milestones', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllIssueMilestones = false;
});
describe('when the given issue does not have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = undefined;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(false);
});
});
describe('when the given issue does have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-exempt-milestone'
};
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(false);
});
});
});
describe('when the given options are configured to exempt all issue milestones', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllIssueMilestones = true;
});
describe('when the given issue does not have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = undefined;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(false);
});
});
describe('when the given issue does have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-exempt-issue-milestone'
};
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(true);
});
});
});
});
});
describe('when the given issue is a pull request', (): void => {
@@ -422,7 +302,7 @@ describe('Milestones', (): void => {
optionsInterface.exemptPrMilestones = '';
});
describe('when the given pull request does not have a milestone', (): void => {
describe('when the given issue does not have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = undefined;
});
@@ -438,7 +318,7 @@ describe('Milestones', (): void => {
});
});
describe('when the given pull request does have a milestone', (): void => {
describe('when the given issue does have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-title'
@@ -462,7 +342,7 @@ describe('Milestones', (): void => {
optionsInterface.exemptPrMilestones = 'dummy-exempt-pr-milestone';
});
describe('when the given pull request does not have a milestone', (): void => {
describe('when the given issue does not have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = undefined;
});
@@ -478,7 +358,7 @@ describe('Milestones', (): void => {
});
});
describe('when the given pull request does have a milestone different than the exempt pull request milestone', (): void => {
describe('when the given issue does have a milestone different than the exempt pull request milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-title'
@@ -496,7 +376,7 @@ describe('Milestones', (): void => {
});
});
describe('when the given pull request does have a milestone equaling the exempt pull request milestone', (): void => {
describe('when the given issue does have a milestone equaling the exempt pull request milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-exempt-pr-milestone'
@@ -526,7 +406,7 @@ describe('Milestones', (): void => {
optionsInterface.exemptPrMilestones = '';
});
describe('when the given pull request does not have a milestone', (): void => {
describe('when the given issue does not have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = undefined;
});
@@ -542,7 +422,7 @@ describe('Milestones', (): void => {
});
});
describe('when the given pull request does have a milestone different than the exempt milestone', (): void => {
describe('when the given issue does have a milestone different than the exempt milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-title'
@@ -560,7 +440,7 @@ describe('Milestones', (): void => {
});
});
describe('when the given pull request does have a milestone equaling the exempt milestone', (): void => {
describe('when the given issue does have a milestone equaling the exempt milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-exempt-milestone'
@@ -584,7 +464,7 @@ describe('Milestones', (): void => {
optionsInterface.exemptPrMilestones = 'dummy-exempt-pr-milestone';
});
describe('when the given pull request does not have a milestone', (): void => {
describe('when the given issue does not have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = undefined;
});
@@ -600,7 +480,7 @@ describe('Milestones', (): void => {
});
});
describe('when the given pull request does have a milestone different than the exempt pull request milestone', (): void => {
describe('when the given issue does have a milestone different than the exempt pull request milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-title'
@@ -618,7 +498,7 @@ describe('Milestones', (): void => {
});
});
describe('when the given pull request does have a milestone equaling the exempt pull request milestone', (): void => {
describe('when the given issue does have a milestone equaling the exempt pull request milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-exempt-pr-milestone'
@@ -636,7 +516,7 @@ describe('Milestones', (): void => {
});
});
describe('when the given pull request does have a milestone different than the exempt milestone', (): void => {
describe('when the given issue does have a milestone different than the exempt milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-title'
@@ -654,7 +534,7 @@ describe('Milestones', (): void => {
});
});
describe('when the given pull request does have a milestone equaling the exempt milestone', (): void => {
describe('when the given issue does have a milestone equaling the exempt milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-exempt-milestone'
@@ -673,126 +553,6 @@ describe('Milestones', (): void => {
});
});
});
describe('when the given options are configured to exempt all milestones', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllMilestones = true;
});
describe('when the given pull request does not have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = undefined;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(false);
});
});
describe('when the given pull request does have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-exempt-pr-milestone'
};
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(true);
});
});
describe('when the given options are not configured to exempt all pull request milestones', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllPrMilestones = false;
});
describe('when the given pull request does not have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = undefined;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(false);
});
});
describe('when the given pull request does have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-exempt-milestone'
};
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(false);
});
});
});
describe('when the given options are configured to exempt all pull request milestones', (): void => {
beforeEach((): void => {
optionsInterface.exemptAllPrMilestones = true;
});
describe('when the given pull request does not have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = undefined;
});
it('should return false', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(false);
});
});
describe('when the given pull request does have a milestone', (): void => {
beforeEach((): void => {
issueInterface.milestone = {
title: 'dummy-exempt-pr-milestone'
};
});
it('should return true', (): void => {
expect.assertions(1);
issue = new Issue(optionsInterface, issueInterface);
milestones = new Milestones(optionsInterface, issue);
const result = milestones.shouldExemptMilestones();
expect(result).toStrictEqual(true);
});
});
});
});
});
});
});

View File

@@ -1,10 +1,7 @@
import deburr from 'lodash.deburr';
import {Option} from '../enums/option';
import {wordsToList} from '../functions/words-to-list';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
import {LoggerService} from '../services/logger.service';
type CleanMilestone = string;
@@ -15,179 +12,42 @@ export class Milestones {
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);
}
shouldExemptMilestones(): boolean {
if (!this._issue.milestone) {
this._issueLogger.info('This $$type has no milestone');
this._logSkip();
return false;
}
if (this._shouldExemptAllMilestones()) {
this._issueLogger.info(
LoggerService.white('└──'),
'Skipping this $$type because it has a milestone'
);
return true;
}
const exemptMilestones: string[] = this._getExemptMilestones();
if (exemptMilestones.length === 0) {
this._issueLogger.info(
LoggerService.white('├──'),
`No milestone option was specified to skip the stale process for this $$type`
);
this._logSkip();
return false;
}
this._issueLogger.info(
LoggerService.white('├──'),
`Found ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length > 1 ? 's' : ''
} that can exempt stale on this $$type`
return exemptMilestones.some((exemptMilestone: Readonly<string>): boolean =>
this._hasMilestone(exemptMilestone)
);
const hasExemptMilestone: boolean = exemptMilestones.some(
(exemptMilestone: Readonly<string>): boolean =>
this._hasMilestone(exemptMilestone)
);
if (!hasExemptMilestone) {
this._issueLogger.info(
LoggerService.white('├──'),
'No milestone on this $$type can exempt the stale process'
);
this._logSkip();
} else {
this._issueLogger.info(
LoggerService.white('└──'),
'Skipping this $$type because it has an exempt milestone'
);
}
return hasExemptMilestone;
}
private _getExemptMilestones(): string[] {
return this._issue.isPullRequest
? this._getExemptPullRequestMilestones()
: this._getExemptIssueMilestones();
return wordsToList(
this._issue.isPullRequest
? this._getExemptPullRequestMilestones()
: this._getExemptIssueMilestones()
);
}
private _getExemptIssueMilestones(): string[] {
if (this._options.exemptIssueMilestones === '') {
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
);
if (this._options.exemptMilestones === '') {
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
);
return [];
}
const exemptMilestones: string[] = wordsToList(
this._options.exemptMilestones
);
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
return exemptMilestones;
}
const exemptMilestones: string[] = wordsToList(
this._options.exemptIssueMilestones
);
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptIssueMilestones
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
return exemptMilestones;
private _getExemptIssueMilestones(): string {
return this._options.exemptIssueMilestones !== ''
? this._options.exemptIssueMilestones
: this._options.exemptMilestones;
}
private _getExemptPullRequestMilestones(): string[] {
if (this._options.exemptPrMilestones === '') {
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
);
if (this._options.exemptMilestones === '') {
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is disabled. No specific milestone can skip the stale process for this $$type`
);
return [];
}
const exemptMilestones: string[] = wordsToList(
this._options.exemptMilestones
);
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptMilestones
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
return exemptMilestones;
}
const exemptMilestones: string[] = wordsToList(
this._options.exemptPrMilestones
);
this._issueLogger.info(
LoggerService.white('├──'),
`The option ${this._issueLogger.createOptionLink(
Option.ExemptPrMilestones
)} is set. ${LoggerService.cyan(exemptMilestones.length)} milestone${
exemptMilestones.length === 1 ? '' : 's'
} can skip the stale process for this $$type`
);
return exemptMilestones;
private _getExemptPullRequestMilestones(): string {
return this._options.exemptPrMilestones !== ''
? this._options.exemptPrMilestones
: this._options.exemptMilestones;
}
private _hasMilestone(milestone: Readonly<string>): boolean {
@@ -195,23 +55,10 @@ export class Milestones {
return false;
}
const cleanMilestone: CleanMilestone =
Milestones._cleanMilestone(milestone);
const isSameMilestone: boolean =
cleanMilestone ===
Milestones._cleanMilestone(this._issue.milestone.title);
if (isSameMilestone) {
this._issueLogger.info(
LoggerService.white('├──'),
`The milestone "${LoggerService.cyan(
milestone
)}" is set on this $$type and is an exempt milestone`
);
}
return isSameMilestone;
return (
Milestones._cleanMilestone(milestone) ===
Milestones._cleanMilestone(this._issue.milestone.title)
);
}
private _shouldExemptAllMilestones(): boolean {
@@ -226,72 +73,21 @@ export class Milestones {
private _shouldExemptAllIssueMilestones(): boolean {
if (this._options.exemptAllIssueMilestones === true) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllIssueMilestones
)} is enabled. Any milestone on this $$type will skip the stale process`
);
return true;
} else if (this._options.exemptAllIssueMilestones === false) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllIssueMilestones
)} is disabled. Only some specific milestones on this $$type will skip the stale process`
);
return false;
}
this._logExemptAllMilestonesOption();
return this._options.exemptAllMilestones;
}
private _shouldExemptAllPullRequestMilestones(): boolean {
if (this._options.exemptAllPrMilestones === true) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllPrMilestones
)} is enabled. Any milestone on this $$type will skip the stale process`
);
return true;
} else if (this._options.exemptAllPrMilestones === false) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllPrMilestones
)} is disabled. Only some specific milestones on this $$type will skip the stale process`
);
return false;
}
this._logExemptAllMilestonesOption();
return this._options.exemptAllMilestones;
}
private _logExemptAllMilestonesOption(): void {
if (this._options.exemptAllMilestones) {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllMilestones
)} is enabled. Any milestone on this $$type will skip the stale process`
);
} else {
this._issueLogger.info(
`The option ${this._issueLogger.createOptionLink(
Option.ExemptAllMilestones
)} is disabled. Only some specific milestones on this $$type will skip the stale process`
);
}
}
private _logSkip(): void {
this._issueLogger.info(
LoggerService.white('└──'),
'Skip the milestones checks'
);
}
}

View File

@@ -1,49 +0,0 @@
import {Operations} from './operations';
describe('Operations', (): void => {
let operations: Operations;
describe('consumeOperation()', (): void => {
beforeEach((): void => {
operations = new Operations();
});
it('should increase the count of operation consume by 1', (): void => {
expect.assertions(1);
operations.consumeOperation();
const result = operations.getConsumedOperationsCount();
expect(result).toStrictEqual(1);
});
});
describe('consumeOperations()', (): void => {
beforeEach((): void => {
operations = new Operations();
});
it('should increase the count of operation consume by the provided quantity', (): void => {
expect.assertions(1);
operations.consumeOperations(8);
const result = operations.getConsumedOperationsCount();
expect(result).toStrictEqual(8);
});
});
describe('getConsumedOperationsCount()', (): void => {
beforeEach((): void => {
operations = new Operations();
});
it('should return 0 by default', (): void => {
expect.assertions(1);
const result = operations.getConsumedOperationsCount();
expect(result).toStrictEqual(0);
});
});
});

View File

@@ -1,17 +0,0 @@
export class Operations {
protected _operationsConsumed = 0;
consumeOperation(): Operations {
return this.consumeOperations(1);
}
consumeOperations(quantity: Readonly<number>): Operations {
this._operationsConsumed += quantity;
return this;
}
getConsumedOperationsCount(): number {
return this._operationsConsumed;
}
}

View File

@@ -1,134 +0,0 @@
import {DefaultProcessorOptions} from '../../__tests__/constants/default-processor-options';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {StaleOperations} from './stale-operations';
interface IHasRemainingOperationsMatrix {
operationsPerRun: number;
consumeOperations: number;
hasRemainingOperations: number;
}
interface IGetRemainingOperationsCountMatrix {
operationsPerRun: number;
consumeOperations: number;
getRemainingOperationsCount: number;
}
describe('StaleOperations', (): void => {
let operations: StaleOperations;
let options: IIssuesProcessorOptions;
beforeEach((): void => {
options = {...DefaultProcessorOptions};
});
describe('consumeOperation()', (): void => {
beforeEach((): void => {
operations = new StaleOperations(options);
});
it('should increase the count of operation consume by 1', (): void => {
expect.assertions(1);
operations.consumeOperation();
const result = operations.getConsumedOperationsCount();
expect(result).toStrictEqual(1);
});
});
describe('consumeOperations()', (): void => {
beforeEach((): void => {
operations = new StaleOperations(options);
});
it('should increase the count of operation consume by the provided quantity', (): void => {
expect.assertions(1);
operations.consumeOperations(8);
const result = operations.getConsumedOperationsCount();
expect(result).toStrictEqual(8);
});
});
describe('getConsumedOperationsCount()', (): void => {
beforeEach((): void => {
operations = new StaleOperations(options);
});
it('should return 0 by default', (): void => {
expect.assertions(1);
const result = operations.getConsumedOperationsCount();
expect(result).toStrictEqual(0);
});
});
describe('hasRemainingOperations()', (): void => {
beforeEach((): void => {
operations = new StaleOperations(options);
});
describe.each`
operationsPerRun | consumeOperations | hasRemainingOperations
${1} | ${1} | ${false}
${2} | ${1} | ${true}
`(
'when the operations per run is $operationsPerRun and $consumeOperations operations were consumed',
({
operationsPerRun,
consumeOperations,
hasRemainingOperations
}: IHasRemainingOperationsMatrix): void => {
beforeEach((): void => {
options.operationsPerRun = operationsPerRun;
operations = new StaleOperations(options);
});
it(`should return ${hasRemainingOperations}`, (): void => {
expect.assertions(1);
operations.consumeOperations(consumeOperations);
const result = operations.hasRemainingOperations();
expect(result).toStrictEqual(hasRemainingOperations);
});
}
);
});
describe('getRemainingOperationsCount()', (): void => {
beforeEach((): void => {
operations = new StaleOperations(options);
});
describe.each`
operationsPerRun | consumeOperations | getRemainingOperationsCount
${1} | ${1} | ${0}
${2} | ${1} | ${1}
`(
'when the operations per run is $operationsPerRun and $consumeOperations operations were consumed',
({
operationsPerRun,
consumeOperations,
getRemainingOperationsCount
}: IGetRemainingOperationsCountMatrix): void => {
beforeEach((): void => {
options.operationsPerRun = operationsPerRun;
operations = new StaleOperations(options);
});
it(`should return ${getRemainingOperationsCount}`, (): void => {
expect.assertions(1);
operations.consumeOperations(consumeOperations);
const result = operations.getRemainingOperationsCount();
expect(result).toStrictEqual(getRemainingOperationsCount);
});
}
);
});
});

View File

@@ -1,19 +0,0 @@
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Operations} from './operations';
export class StaleOperations extends Operations {
private readonly _options: IIssuesProcessorOptions;
constructor(options: Readonly<IIssuesProcessorOptions>) {
super();
this._options = options;
}
hasRemainingOperations(): boolean {
return this._operationsConsumed < this._options.operationsPerRun;
}
getRemainingOperationsCount(): number {
return this._options.operationsPerRun - this._operationsConsumed;
}
}

View File

@@ -1,107 +1,70 @@
import {Issue} from './issue';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {Logger} from './loggers/logger';
import {LoggerService} from '../services/logger.service';
interface IGroupValue {
name: string;
count: number;
}
export class Statistics {
private readonly _logger: Logger = new Logger();
private readonly _options: IIssuesProcessorOptions;
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 _deletedLabelsCount = 0;
private _deletedCloseLabelsCount = 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 _addedLabelsCount = 0;
private _addedCommentsCount = 0;
private _fetchedIssuesCount = 0;
private _fetchedIssuesEventsCount = 0;
private _fetchedIssuesCommentsCount = 0;
private _fetchedPullRequestsCount = 0;
incrementProcessedItemsCount(
issue: Readonly<Issue>,
increment: Readonly<number> = 1
): Statistics {
if (issue.isPullRequest) {
return this._incrementProcessedPullRequestsCount(increment);
}
return this._incrementProcessedIssuesCount(increment);
constructor(options: IIssuesProcessorOptions) {
this._options = options;
}
incrementStaleItemsCount(
issue: Readonly<Issue>,
increment: Readonly<number> = 1
): Statistics {
if (issue.isPullRequest) {
return this._incrementStalePullRequestsCount(increment);
}
return this._incrementStaleIssuesCount(increment);
}
incrementUndoStaleItemsCount(
issue: Readonly<Issue>,
increment: Readonly<number> = 1
): Statistics {
if (issue.isPullRequest) {
return this._incrementUndoStalePullRequestsCount(increment);
}
return this._incrementUndoStaleIssuesCount(increment);
}
setOperationsCount(operationsCount: Readonly<number>): Statistics {
this._operationsCount = operationsCount;
incrementProcessedIssuesCount(increment: Readonly<number> = 1): Statistics {
this._processedIssuesCount += increment;
return this;
}
incrementClosedItemsCount(
issue: Readonly<Issue>,
increment: Readonly<number> = 1
): Statistics {
if (issue.isPullRequest) {
return this._incrementClosedPullRequestsCount(increment);
}
incrementStaleIssuesCount(increment: Readonly<number> = 1): Statistics {
this._staleIssuesCount += increment;
return this._incrementClosedIssuesCount(increment);
return this;
}
incrementDeletedItemsLabelsCount(
issue: Readonly<Issue>,
increment: Readonly<number> = 1
): Statistics {
if (issue.isPullRequest) {
return this._incrementDeletedPullRequestsLabelsCount(increment);
}
incrementUndoStaleIssuesCount(increment: Readonly<number> = 1): Statistics {
this._undoStaleIssuesCount += increment;
return this._incrementDeletedIssuesLabelsCount(increment);
return this;
}
incrementDeletedCloseItemsLabelsCount(
issue: Readonly<Issue>,
setOperationsLeft(operationsLeft: Readonly<number>): Statistics {
this._operationsCount = this._options.operationsPerRun - operationsLeft;
return this;
}
incrementClosedIssuesCount(increment: Readonly<number> = 1): Statistics {
this._closedIssuesCount += increment;
return this;
}
incrementDeletedLabelsCount(increment: Readonly<number> = 1): Statistics {
this._deletedLabelsCount += increment;
return this;
}
incrementDeletedCloseLabelsCount(
increment: Readonly<number> = 1
): Statistics {
if (issue.isPullRequest) {
return this._incrementDeletedClosePullRequestsLabelsCount(increment);
}
this._deletedCloseLabelsCount += increment;
return this._incrementDeletedCloseIssuesLabelsCount(increment);
return this;
}
incrementDeletedBranchesCount(increment: Readonly<number> = 1): Statistics {
@@ -110,46 +73,36 @@ export class Statistics {
return this;
}
incrementAddedItemsLabel(
issue: Readonly<Issue>,
increment: Readonly<number> = 1
): Statistics {
if (issue.isPullRequest) {
return this._incrementAddedPullRequestsLabel(increment);
}
return this._incrementAddedIssuesLabel(increment);
}
incrementAddedItemsComment(
issue: Readonly<Issue>,
increment: Readonly<number> = 1
): Statistics {
if (issue.isPullRequest) {
return this._incrementAddedPullRequestsComment(increment);
}
return this._incrementAddedIssuesComment(increment);
}
incrementFetchedItemsCount(increment: Readonly<number> = 1): Statistics {
this._fetchedItemsCount += increment;
incrementAddedLabel(increment: Readonly<number> = 1): Statistics {
this._addedLabelsCount += increment;
return this;
}
incrementFetchedItemsEventsCount(
increment: Readonly<number> = 1
): Statistics {
this._fetchedItemsEventsCount += increment;
incrementAddedComment(increment: Readonly<number> = 1): Statistics {
this._addedCommentsCount += increment;
return this;
}
incrementFetchedItemsCommentsCount(
incrementFetchedIssuesCount(increment: Readonly<number> = 1): Statistics {
this._fetchedIssuesCount += increment;
return this;
}
incrementFetchedIssuesEventsCount(
increment: Readonly<number> = 1
): Statistics {
this._fetchedItemsCommentsCount += increment;
this._fetchedIssuesEventsCount += increment;
return this;
}
incrementFetchedIssuesCommentsCount(
increment: Readonly<number> = 1
): Statistics {
this._fetchedIssuesCommentsCount += increment;
return this;
}
@@ -163,361 +116,85 @@ export class Statistics {
}
logStats(): Statistics {
this._logger.info(LoggerService.yellow(LoggerService.bold(`Statistics:`)));
this._logProcessedIssuesAndPullRequestsCount();
this._logStaleIssuesAndPullRequestsCount();
this._logUndoStaleIssuesAndPullRequestsCount();
this._logClosedIssuesAndPullRequestsCount();
this._logDeletedIssuesAndPullRequestsLabelsCount();
this._logDeletedCloseIssuesAndPullRequestsLabelsCount();
this._logDeletedBranchesCount();
this._logAddedIssuesAndPullRequestsLabelsCount();
this._logAddedIssuesAndPullRequestsCommentsCount();
this._logFetchedItemsCount();
this._logFetchedItemsEventsCount();
this._logFetchedItemsCommentsCount();
this._logFetchedPullRequestsCount();
this._logger.info('Statistics');
this._logProcessedIssuesCount();
this._logStaleIssuesCount();
this._logUndoStaleIssuesCount();
this._logOperationsCount();
this._logClosedIssuesCount();
this._logDeletedLabelsCount();
this._logDeletedCloseLabelsCount();
this._logDeletedBranchesCount();
this._logAddedLabelsCount();
this._logAddedCommentsCount();
this._logFetchedIssuesCount();
this._logFetchedIssuesEventsCount();
this._logFetchedIssuesCommentsCount();
this._logFetchedPullRequestsCount();
this._logger.info('---');
return this;
}
private _incrementProcessedIssuesCount(
increment: Readonly<number> = 1
): Statistics {
this._processedIssuesCount += increment;
return this;
private _logProcessedIssuesCount(): void {
this._logCount('Processed issues/PRs', this._processedIssuesCount);
}
private _incrementProcessedPullRequestsCount(
increment: Readonly<number> = 1
): Statistics {
this._processedPullRequestsCount += increment;
return this;
private _logStaleIssuesCount(): void {
this._logCount('New stale issues/PRs', this._staleIssuesCount);
}
private _incrementStaleIssuesCount(
increment: Readonly<number> = 1
): Statistics {
this._staleIssuesCount += increment;
return this;
}
private _incrementStalePullRequestsCount(
increment: Readonly<number> = 1
): Statistics {
this._stalePullRequestsCount += increment;
return this;
}
private _incrementUndoStaleIssuesCount(
increment: Readonly<number> = 1
): Statistics {
this._undoStaleIssuesCount += increment;
return this;
}
private _incrementUndoStalePullRequestsCount(
increment: Readonly<number> = 1
): Statistics {
this._undoStalePullRequestsCount += increment;
return this;
}
private _incrementClosedIssuesCount(
increment: Readonly<number> = 1
): Statistics {
this._closedIssuesCount += increment;
return this;
}
private _incrementClosedPullRequestsCount(
increment: Readonly<number> = 1
): Statistics {
this._closedPullRequestsCount += increment;
return this;
}
private _incrementDeletedIssuesLabelsCount(
increment: Readonly<number> = 1
): Statistics {
this._deletedIssuesLabelsCount += increment;
return this;
}
private _incrementDeletedPullRequestsLabelsCount(
increment: Readonly<number> = 1
): Statistics {
this._deletedPullRequestsLabelsCount += increment;
return this;
}
private _incrementDeletedCloseIssuesLabelsCount(
increment: Readonly<number> = 1
): Statistics {
this._deletedCloseIssuesLabelsCount += increment;
return this;
}
private _incrementDeletedClosePullRequestsLabelsCount(
increment: Readonly<number> = 1
): Statistics {
this._deletedClosePullRequestsLabelsCount += increment;
return this;
}
private _incrementAddedIssuesLabel(
increment: Readonly<number> = 1
): Statistics {
this._addedIssuesLabelsCount += increment;
return this;
}
private _incrementAddedPullRequestsLabel(
increment: Readonly<number> = 1
): Statistics {
this._addedPullRequestsLabelsCount += increment;
return this;
}
private _incrementAddedIssuesComment(
increment: Readonly<number> = 1
): Statistics {
this._addedIssuesCommentsCount += increment;
return this;
}
private _incrementAddedPullRequestsComment(
increment: Readonly<number> = 1
): Statistics {
this._addedPullRequestsCommentsCount += increment;
return this;
}
private _logProcessedIssuesAndPullRequestsCount(): void {
this._logGroup('Processed items', [
{
name: 'Processed issues',
count: this._processedIssuesCount
},
{
name: 'Processed PRs',
count: this._processedPullRequestsCount
}
]);
}
private _logStaleIssuesAndPullRequestsCount(): void {
this._logGroup('New stale items', [
{
name: 'New stale issues',
count: this._staleIssuesCount
},
{
name: 'New stale PRs',
count: this._stalePullRequestsCount
}
]);
}
private _logUndoStaleIssuesAndPullRequestsCount(): void {
this._logGroup('No longer stale items', [
{
name: 'No longer stale issues',
count: this._undoStaleIssuesCount
},
{
name: 'No longer stale PRs',
count: this._undoStalePullRequestsCount
}
]);
}
private _logClosedIssuesAndPullRequestsCount(): void {
this._logGroup('Closed items', [
{
name: 'Closed issues',
count: this._closedIssuesCount
},
{
name: 'Closed PRs',
count: this._closedPullRequestsCount
}
]);
}
private _logDeletedIssuesAndPullRequestsLabelsCount(): void {
this._logGroup('Deleted items labels', [
{
name: 'Deleted issues labels',
count: this._deletedIssuesLabelsCount
},
{
name: 'Deleted PRs labels',
count: this._deletedPullRequestsLabelsCount
}
]);
}
private _logDeletedCloseIssuesAndPullRequestsLabelsCount(): void {
this._logGroup('Deleted close items labels', [
{
name: 'Deleted close issues labels',
count: this._deletedCloseIssuesLabelsCount
},
{
name: 'Deleted close PRs labels',
count: this._deletedClosePullRequestsLabelsCount
}
]);
}
private _logDeletedBranchesCount(): void {
this._logCount('Deleted branches', this._deletedBranchesCount);
}
private _logAddedIssuesAndPullRequestsLabelsCount(): void {
this._logGroup('Added items labels', [
{
name: 'Added issues labels',
count: this._addedIssuesLabelsCount
},
{
name: 'Added PRs labels',
count: this._addedPullRequestsLabelsCount
}
]);
}
private _logAddedIssuesAndPullRequestsCommentsCount(): void {
this._logGroup('Added items comments', [
{
name: 'Added issues comments',
count: this._addedIssuesCommentsCount
},
{
name: 'Added PRs comments',
count: this._addedPullRequestsCommentsCount
}
]);
}
private _logFetchedItemsCount(): void {
this._logCount('Fetched items', this._fetchedItemsCount);
}
private _logFetchedItemsEventsCount(): void {
this._logCount('Fetched items events', this._fetchedItemsEventsCount);
}
private _logFetchedItemsCommentsCount(): void {
this._logCount('Fetched items comments', this._fetchedItemsCommentsCount);
}
private _logFetchedPullRequestsCount(): void {
this._logCount('Fetched pull requests', this._fetchedPullRequestsCount);
private _logUndoStaleIssuesCount(): void {
this._logCount('No longer stale issues/PRs', this._undoStaleIssuesCount);
}
private _logOperationsCount(): void {
this._logCount('Operations performed', this._operationsCount);
}
private _logClosedIssuesCount(): void {
this._logCount('Closed issues', this._closedIssuesCount);
}
private _logDeletedLabelsCount(): void {
this._logCount('Deleted labels', this._deletedLabelsCount);
}
private _logDeletedCloseLabelsCount(): void {
this._logCount('Deleted close labels', this._deletedCloseLabelsCount);
}
private _logDeletedBranchesCount(): void {
this._logCount('Deleted branches', this._deletedBranchesCount);
}
private _logAddedLabelsCount(): void {
this._logCount('Added labels', this._addedLabelsCount);
}
private _logAddedCommentsCount(): void {
this._logCount('Added comments', this._addedCommentsCount);
}
private _logFetchedIssuesCount(): void {
this._logCount('Fetched issues', this._fetchedIssuesCount);
}
private _logFetchedIssuesEventsCount(): void {
this._logCount('Fetched issues events', this._fetchedIssuesEventsCount);
}
private _logFetchedIssuesCommentsCount(): void {
this._logCount('Fetched issues comments', this._fetchedIssuesCommentsCount);
}
private _logFetchedPullRequestsCount(): void {
this._logCount('Fetched pull requests', this._fetchedPullRequestsCount);
}
private _logCount(name: Readonly<string>, count: Readonly<number>): void {
if (count > 0) {
this._logger.info(`${name}:`, LoggerService.cyan(count));
this._logger.info(`${name}: ${count}`);
}
}
private _logGroup(groupName: Readonly<string>, values: IGroupValue[]): void {
if (this._isGroupValuesPartiallySet(values)) {
this._logCount(groupName, this._getGroupValuesTotalCount(values));
this._logGroupValues(values);
} else {
// Only one value will be display
for (const value of values) {
this._logCount(value.name, value.count);
}
}
}
/**
* @private
* @description
* If there is a least two elements with a valid count then it's partially set
* Useful to defined if we should display the values as a group or not
*
* @param {IGroupValue[]} values The list of group values to check
*/
private _isGroupValuesPartiallySet(values: IGroupValue[]): boolean {
return (
values
.map((value: Readonly<IGroupValue>): boolean => {
return value.count > 0;
})
.filter((isSet: Readonly<boolean>): boolean => isSet).length >= 2
);
}
private _getGroupValuesTotalCount(values: IGroupValue[]): number {
return values.reduce(
(count: Readonly<number>, value: Readonly<IGroupValue>): number => {
return count + value.count;
},
0
);
}
private _getAllGroupValuesSet(values: IGroupValue[]): IGroupValue[] {
return values.filter((value: Readonly<IGroupValue>): boolean => {
return value.count > 0;
});
}
private _logGroupValues(values: IGroupValue[]): void {
const onlyValuesSet: IGroupValue[] = this._getAllGroupValuesSet(values);
const longestValue: number = this._getLongestGroupValue(onlyValuesSet);
for (const [index, value] of onlyValuesSet.entries()) {
const prefix = index === onlyValuesSet.length - 1 ? '└──' : '├──';
this._logCount(
`${LoggerService.white(prefix)} ${value.name.padEnd(
longestValue,
' '
)}`,
value.count
);
}
}
private _getLongestGroupValue(values: IGroupValue[]): number {
return values.reduce(
(
longestValue: Readonly<number>,
value: Readonly<IGroupValue>
): number => {
return value.name.length > longestValue
? value.name.length
: longestValue;
},
0
);
}
}

View File

@@ -1,46 +0,0 @@
export enum Option {
RepoToken = 'repo-token',
StaleIssueMessage = 'stale-issue-message',
StalePrMessage = 'stale-pr-message',
CloseIssueMessage = 'close-issue-message',
ClosePrMessage = 'close-pr-message',
DaysBeforeStale = 'days-before-stale',
DaysBeforeIssueStale = 'days-before-issue-stale',
DaysBeforePrStale = 'days-before-pr-stale',
DaysBeforeClose = 'days-before-close',
DaysBeforeIssueClose = 'days-before-issue-close',
DaysBeforePrClose = 'days-before-pr-close',
StaleIssueLabel = 'stale-issue-label',
CloseIssueLabel = 'close-issue-label',
ExemptIssueLabels = 'exempt-issue-labels',
StalePrLabel = 'stale-pr-label',
ClosePrLabel = 'close-pr-label',
ExemptPrLabels = 'exempt-pr-labels',
OnlyLabels = 'only-labels',
OnlyIssueLabels = 'only-issue-labels',
OnlyPrLabels = 'only-pr-labels',
AnyOfLabels = 'any-of-labels',
OperationsPerRun = 'operations-per-run',
RemoveStaleWhenUpdated = 'remove-stale-when-updated',
RemoveIssueStaleWhenUpdated = 'remove-issue-stale-when-updated',
RemovePrStaleWhenUpdated = 'remove-pr-stale-when-updated',
DebugOnly = 'debug-only',
Ascending = 'ascending',
DeleteBranch = 'delete-branch',
StartDate = 'start-date',
ExemptMilestones = 'exempt-milestones',
ExemptIssueMilestones = 'exempt-issue-milestones',
ExemptPrMilestones = 'exempt-pr-milestones',
ExemptAllMilestones = 'exempt-all-milestones',
ExemptAllIssueMilestones = 'exempt-all-issue-milestones',
ExemptAllPrMilestones = 'exempt-all-pr-milestones',
ExemptAssignees = 'exempt-assignees',
ExemptIssueAssignees = 'exempt-issue-assignees',
ExemptPrAssignees = 'exempt-pr-assignees',
ExemptAllAssignees = 'exempt-all-assignees',
ExemptAllIssueAssignees = 'exempt-all-issue-assignees',
ExemptAllPrAssignees = 'exempt-all-pr-assignees',
EnableStatistics = 'enable-statistics',
LabelsToRemoveWhenUnstale = 'labels-to-remove-when-unstale',
LabelsToAddWhenUnstale = 'labels-to-add-when-unstale'
}

View File

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

View File

@@ -1,29 +0,0 @@
import {isBoolean} from './is-boolean';
describe('isBoolean()', (): void => {
describe.each([0, 1, undefined, null, ''])(
'when the given value is not a boolean',
(value): void => {
it('should return false', (): void => {
expect.assertions(1);
const result = isBoolean(value);
expect(result).toStrictEqual(false);
});
}
);
describe.each([false, true])(
'when the given value is a boolean',
(value): void => {
it('should return true', (): void => {
expect.assertions(1);
const result = isBoolean(value);
expect(result).toStrictEqual(true);
});
}
);
});

View File

@@ -1,3 +0,0 @@
export function isBoolean(value: unknown): value is boolean {
return value === true || value === false;
}

View File

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

View File

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

View File

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

View File

@@ -22,14 +22,12 @@ export interface IIssuesProcessorOptions {
onlyIssueLabels: string;
onlyPrLabels: string;
anyOfLabels: string;
anyOfIssueLabels: string;
anyOfPrLabels: string;
operationsPerRun: number;
removeStaleWhenUpdated: boolean;
removeIssueStaleWhenUpdated: boolean | undefined;
removePrStaleWhenUpdated: boolean | undefined;
debugOnly: boolean;
ascending: boolean;
skipStaleIssueMessage: boolean;
skipStalePrMessage: boolean;
deleteBranch: boolean;
startDate: IsoOrRfcDateString | undefined; // Should be ISO 8601 or RFC 2822
exemptMilestones: string;
@@ -45,6 +43,4 @@ export interface IIssuesProcessorOptions {
exemptAllIssueAssignees: boolean | undefined;
exemptAllPrAssignees: boolean | undefined;
enableStatistics: boolean;
labelsToRemoveWhenUnstale: string;
labelsToAddWhenUnstale: string;
}

View File

@@ -1,20 +1,14 @@
import * as core from '@actions/core';
import {IssuesProcessor} from './classes/issues-processor';
import {isValidDate} from './functions/dates/is-valid-date';
import {IssuesProcessor} from './classes/issues-processor';
import {IIssuesProcessorOptions} from './interfaces/issues-processor-options';
import {Issue} from './classes/issue';
async function _run(): Promise<void> {
try {
const args = _getAndValidateArgs();
const issueProcessor: IssuesProcessor = new IssuesProcessor(args);
await issueProcessor.processIssues();
await processOutput(
issueProcessor.staleIssues,
issueProcessor.closedIssues
);
const processor: IssuesProcessor = new IssuesProcessor(args);
await processor.processIssues();
} catch (error) {
core.error(error);
core.setFailed(error.message);
@@ -48,22 +42,16 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
onlyIssueLabels: core.getInput('only-issue-labels'),
onlyPrLabels: core.getInput('only-pr-labels'),
anyOfLabels: core.getInput('any-of-labels'),
anyOfIssueLabels: core.getInput('any-of-issue-labels'),
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')
),
debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true',
skipStalePrMessage: core.getInput('skip-stale-pr-message') === 'true',
skipStaleIssueMessage: core.getInput('skip-stale-issue-message') === 'true',
deleteBranch: core.getInput('delete-branch') === 'true',
startDate:
core.getInput('start-date') !== ''
@@ -81,9 +69,7 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
exemptAllAssignees: core.getInput('exempt-all-assignees') === 'true',
exemptAllIssueAssignees: _toOptionalBoolean('exempt-all-issue-assignees'),
exemptAllPrAssignees: _toOptionalBoolean('exempt-all-pr-assignees'),
enableStatistics: core.getInput('enable-statistics') === 'true',
labelsToRemoveWhenUnstale: core.getInput('labels-to-remove-when-unstale'),
labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale')
enableStatistics: core.getInput('enable-statistics') === 'true'
};
for (const numberInput of [
@@ -92,9 +78,7 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
'operations-per-run'
]) {
if (isNaN(parseInt(core.getInput(numberInput)))) {
const errorMessage = `Option "${numberInput}" did not parse to a valid integer`;
core.setFailed(errorMessage);
throw new Error(errorMessage);
throw Error(`input ${numberInput} did not parse to a valid integer`);
}
}
@@ -102,9 +86,9 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
// Ignore empty dates because it is considered as the right type for a default value (so a valid one)
if (core.getInput(optionalDateInput) !== '') {
if (!isValidDate(new Date(core.getInput(optionalDateInput)))) {
const errorMessage = `Option "${optionalDateInput}" did not parse to a valid date`;
core.setFailed(errorMessage);
throw new Error(errorMessage);
throw new Error(
`input ${optionalDateInput} did not parse to a valid date`
);
}
}
}
@@ -112,14 +96,6 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
return args;
}
async function processOutput(
staledIssues: Issue[],
closedIssues: Issue[]
): Promise<void> {
core.setOutput('staled-issues-prs', JSON.stringify(staledIssues));
core.setOutput('closed-issues-prs', JSON.stringify(closedIssues));
}
function _toOptionalBoolean(
argumentName: Readonly<string>
): boolean | undefined {

View File

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