Compare commits

..

7 Commits

Author SHA1 Message Date
Luke Tomlinson
489c8a69b9 More debugging 2021-06-29 11:50:32 -04:00
Luke Tomlinson
31eafc7219 Debug events 2021-06-29 11:44:24 -04:00
Luke Tomlinson
75a803e008 Filter comments based on content, not author 2021-06-24 16:50:23 -04:00
Luke Tomlinson
cce770077c Print comments 2021-06-24 15:28:15 -04:00
Luke Tomlinson
b95063d0a1 Print more user info 2021-06-24 15:23:23 -04:00
Luke Tomlinson
7370047184 Print actor 2021-06-24 14:09:38 -04:00
Luke Tomlinson
a7d1a14092 Testing 2021-06-24 14:00:41 -04:00
83 changed files with 8685 additions and 23460 deletions

View File

@@ -1,35 +0,0 @@
---
name: Bug report
about: Create a bug report
title: ''
labels: bug, needs triage
assignees: ''
---
<!--- Please direct any generic questions related to actions to our support community forum at https://github.com/orgs/community/discussions --->
<!--- Before opening up a new bug report, please make sure to check for similar existing issues -->
**Description:**
A clear and concise description of what the bug is.
**Action version:**
Specify the action version
**Platform:**
- [ ] Ubuntu
- [ ] macOS
- [ ] Windows
**Runner type:**
- [ ] Hosted
- [ ] Self-hosted
**Repro steps:**
A description with steps to reproduce the issue. If your have a public example or repo to share, please provide the link.
**Expected behavior:**
A description of what you expected to happen.
**Actual behavior:**
A description of what is actually happening.

View File

@@ -1,19 +1,11 @@
---
name: Feature request
about: Suggest an idea for this project
about: Propose a new feature or an enhancement
title: ''
labels: feature request, needs triage
labels: enhancement
assignees: ''
---
<!--- Please direct any generic questions related to actions to our support community forum at https://github.com/orgs/community/discussions --->
<!--- Before opening up a new bug report, please make sure to check for similar existing issues -->
## The problem
**Description:**
Describe your proposal.
**Justification:**
Justification or a use case for your proposal.
**Are you willing to submit a PR?**
<!--- We accept contributions! -->
## The solution

View File

@@ -0,0 +1,13 @@
---
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

@@ -0,0 +1,28 @@
---
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

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

View File

@@ -1,9 +1,10 @@
**Description:**
Describe your changes.
<!-- List the change(s) you're making with this PR. -->
**Related issue:**
Add link to the related issue.
## Changes
**Check list:**
- [ ] Mark if documentation changes are required.
- [ ] Mark if tests were added or updated to cover the 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

@@ -1,17 +0,0 @@
name: Basic validation
on:
pull_request:
paths-ignore:
- '**.md'
push:
branches:
- main
- releases/*
paths-ignore:
- '**.md'
jobs:
call-basic-validation:
name: Basic validation
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main

View File

@@ -1,17 +0,0 @@
name: Check dist/
on:
push:
branches:
- main
paths-ignore:
- '**.md'
pull_request:
paths-ignore:
- '**.md'
workflow_dispatch:
jobs:
call-check-dist:
name: Check dist/
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main

View File

@@ -1,14 +0,0 @@
name: 'Code scanning'
on:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: '0 3 * * 0'
jobs:
call-codeQL-analysis:
name: CodeQL analysis
uses: actions/reusable-workflows/.github/workflows/codeql-analysis.yml@main

25
.github/workflows/codeql.yml vendored Normal file
View File

@@ -0,0 +1,25 @@
name: 'Code scanning'
on:
push:
branches:
- main
pull_request:
schedule:
- cron: '0 19 * * 0'
jobs:
CodeQL-Build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v2
- name: Initialize CodeQL
uses: github/codeql-action/init@v1
- name: Autobuild
uses: github/codeql-action/autobuild@v1
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1

View File

@@ -1,26 +0,0 @@
name: e2e tests
on:
pull_request:
paths-ignore:
- '**.md'
push:
branches:
- main
- releases/*
paths-ignore:
- '**.md'
jobs:
dry-run-test: # make sure the action works on a clean machine without building
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- 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 ${{ format('{0},{1}', toJSON(steps.stale.outputs.staled-issues-prs), toJSON(steps.stale.outputs.closed-issues-prs)) }}

20
.github/workflows/licensed.off vendored Normal file
View File

@@ -0,0 +1,20 @@
name: Licensed
on:
push: {branches: main}
pull_request: {branches: main}
jobs:
test:
runs-on: ubuntu-latest
name: Check licenses
steps:
- uses: actions/checkout@v2
- run: npm ci
- name: Install licensed
run: |
cd $RUNNER_TEMP
curl -Lfs -o licensed.tar.gz https://github.com/github/licensed/releases/download/2.12.2/licensed-2.12.2-linux-x64.tar.gz
sudo tar -xzf licensed.tar.gz
sudo mv licensed /usr/local/bin/licensed
- run: licensed status

View File

@@ -1,15 +0,0 @@
name: Licensed
on:
push:
branches:
- main
pull_request:
branches:
- main
workflow_dispatch:
jobs:
call-licensed:
name: Licensed
uses: actions/reusable-workflows/.github/workflows/licensed.yml@main

View File

@@ -1,28 +0,0 @@
name: Release new action version
on:
release:
types: [released]
workflow_dispatch:
inputs:
TAG_NAME:
description: 'Tag name that the major tag will point to'
required: true
env:
TAG_NAME: ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }}
permissions:
contents: write
jobs:
update_tag:
name: Update the major tag to include the ${{ github.event.inputs.TAG_NAME || github.event.release.tag_name }} changes
environment:
name: releaseNewActionVersion
runs-on: ubuntu-latest
steps:
- name: Update the ${{ env.TAG_NAME }} tag
uses: actions/publish-action@v0.2.1
with:
source-tag: ${{ env.TAG_NAME }}
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}

19
.github/workflows/stale.yml vendored Normal file
View File

@@ -0,0 +1,19 @@
name: 'Stale issue handler'
on:
workflow_dispatch:
schedule:
- cron: '0 0 * * *'
jobs:
stale:
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.*, ',') }}

28
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,28 @@
name: 'Build'
on: # rebuild any PRs and main branch changes
pull_request:
push:
branches:
- main
- 'releases/*'
jobs:
build: # make sure build/ci work properly
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- run: |
npm ci
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,6 +1,6 @@
---
name: "@actions/core"
version: 1.10.0
version: 1.2.4
type: npm
summary: Actions core lib
homepage: https://github.com/actions/toolkit/tree/master/packages/core

View File

@@ -1,6 +1,6 @@
---
name: "@actions/github"
version: 5.0.1
version: 4.0.0
type: npm
summary: Actions github lib
homepage: https://github.com/actions/toolkit/tree/master/packages/github

View File

@@ -1,32 +0,0 @@
---
name: "@actions/http-client"
version: 1.0.11
type: npm
summary: Actions Http Client
homepage: https://github.com/actions/http-client#readme
license: mit
licenses:
- sources: LICENSE
text: |
Actions Http Client for Node.js
Copyright (c) GitHub, Inc.
All rights reserved.
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
associated documentation files (the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
notices: []

View File

@@ -1,6 +1,6 @@
---
name: "@actions/http-client"
version: 2.0.1
version: 1.0.8
type: npm
summary: Actions Http Client
homepage: https://github.com/actions/http-client#readme

View File

@@ -1,6 +1,6 @@
---
name: "@octokit/auth-token"
version: 2.5.0
version: 2.4.2
type: npm
summary: GitHub API token authentication for browsers and Node.js
homepage: https://github.com/octokit/auth-token.js#readme

View File

@@ -1,6 +1,6 @@
---
name: "@octokit/core"
version: 3.6.0
version: 3.1.1
type: npm
summary: Extendable client for GitHub's REST & GraphQL APIs
homepage: https://github.com/octokit/core.js#readme

View File

@@ -1,6 +1,6 @@
---
name: "@octokit/endpoint"
version: 6.0.12
version: 6.0.5
type: npm
summary: Turns REST API endpoints into generic request options
homepage: https://github.com/octokit/endpoint.js#readme

View File

@@ -1,6 +1,6 @@
---
name: "@octokit/graphql"
version: 4.8.0
version: 4.5.2
type: npm
summary: GitHub GraphQL API client for browsers and Node
homepage: https://github.com/octokit/graphql.js#readme

View File

@@ -1,6 +1,6 @@
---
name: "@octokit/plugin-paginate-rest"
version: 2.17.0
version: 2.2.4
type: npm
summary: Octokit plugin to paginate REST API endpoint responses
homepage: https://github.com/octokit/plugin-paginate-rest.js#readme

View File

@@ -1,18 +1,18 @@
---
name: "@octokit/openapi-types"
version: 11.2.0
name: "@octokit/plugin-request-log"
version: 1.0.0
type: npm
summary: Generated TypeScript definitions based on GitHub's OpenAPI spec for api.github.com
homepage:
summary: Log all requests and request errors
homepage: https://github.com/octokit/plugin-request-log.js#readme
license: mit
licenses:
- sources: LICENSE
text: |-
Copyright 2020 Gregor Martynus
text: |
MIT License Copyright (c) 2020 Octokit contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- sources: README.md

View File

@@ -1,6 +1,6 @@
---
name: "@octokit/plugin-rest-endpoint-methods"
version: 5.13.0
version: 4.1.1
type: npm
summary: Octokit plugin adding one method for all of api.github.com REST API endpoints
homepage: https://github.com/octokit/plugin-rest-endpoint-methods.js#readme

View File

@@ -1,20 +1,20 @@
---
name: uuid
version: 8.3.2
name: "@octokit/plugin-rest-endpoint-methods"
version: 4.1.2
type: npm
summary: RFC4122 (v1, v4, and v5) UUIDs
homepage:
summary: Octokit plugin adding one method for all of api.github.com REST API endpoints
homepage: https://github.com/octokit/plugin-rest-endpoint-methods.js#readme
license: mit
licenses:
- sources: LICENSE.md
- sources: LICENSE
text: |
The MIT License (MIT)
Copyright (c) 2010-2020 Robert Kieffer and other contributors
MIT License Copyright (c) 2019 Octokit contributors
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
The above copyright notice and this permission notice (including the next paragraph) shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- sources: README.md
text: "[MIT](LICENSE)"
notices: []

View File

@@ -1,6 +1,6 @@
---
name: "@octokit/request-error"
version: 2.1.0
version: 2.0.2
type: npm
summary: Error class for Octokit request errors
homepage: https://github.com/octokit/request-error.js#readme

View File

@@ -1,6 +1,6 @@
---
name: "@octokit/request"
version: 5.6.3
version: 5.4.7
type: npm
summary: Send parameterized requests to GitHubs APIs with sensible defaults in browsers
and Node

View File

@@ -1,16 +1,17 @@
---
name: whatwg-url
version: 5.0.0
name: "@octokit/rest"
version: 18.0.2
type: npm
summary: An implementation of the WHATWG URL Standard's URL API and parsing machinery
homepage:
summary: GitHub REST API client for Node.js
homepage: https://github.com/octokit/rest.js#readme
license: mit
licenses:
- sources: LICENSE.txt
- sources: LICENSE
text: |
The MIT License (MIT)
The MIT License
Copyright (c) 20152016 Sebastian Mayr
Copyright (c) 2012 Cloud9 IDE, Inc. (Mike de Boer)
Copyright (c) 2017-2018 Octokit contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -29,4 +30,6 @@ licenses:
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
- sources: README.md
text: "[MIT](LICENSE)"
notices: []

View File

@@ -1,6 +1,6 @@
---
name: "@octokit/types"
version: 6.34.0
version: 5.1.2
type: npm
summary: Shared TypeScript definitions for Octokit projects
homepage: https://github.com/octokit/types.ts#readme

32
.licenses/npm/@types/node.dep.yml generated Normal file
View File

@@ -0,0 +1,32 @@
---
name: "@types/node"
version: 14.6.0
type: npm
summary: TypeScript definitions for Node.js
homepage: https://github.com/DefinitelyTyped/DefinitelyTyped#readme
license: mit
licenses:
- sources: LICENSE
text: |2
MIT License
Copyright (c) Microsoft Corporation.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE
notices: []

View File

@@ -1,6 +1,6 @@
---
name: before-after-hook
version: 2.2.2
version: 2.1.0
type: npm
summary: asynchronous before/error/after hooks for internal functionality
homepage: https://github.com/gr2m/before-after-hook#readme

View File

@@ -1,6 +1,6 @@
---
name: is-plain-object
version: 5.0.0
version: 4.1.1
type: npm
summary: Returns true if an object was created by the `Object` constructor, or Object.create(null).
homepage: https://github.com/jonschlinkert/is-plain-object

View File

@@ -1,58 +0,0 @@
---
name: lodash.deburr
version: 4.1.0
type: npm
summary: The lodash method `_.deburr` exported as a module.
homepage: https://lodash.com/
license: mit
licenses:
- sources: LICENSE
text: |
Copyright jQuery Foundation and other contributors <https://jquery.org/>
Based on Underscore.js, copyright Jeremy Ashkenas,
DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
This software consists of voluntary contributions made by many
individuals. For exact contribution history, see the revision history
available at https://github.com/lodash/lodash
The following license applies to all parts of this software except as
documented below:
====
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
====
Copyright and related rights for sample code are waived via CC0. Sample
code is defined as all source code displayed within the prose of the
documentation.
CC0: http://creativecommons.org/publicdomain/zero/1.0/
====
Files located in the node_modules and vendor directories are externally
maintained libraries used by this software which have their own
licenses; we recommend you read them, as their terms may differ from the
terms above.
notices: []

View File

@@ -1,26 +0,0 @@
---
name: lru-cache
version: 6.0.0
type: npm
summary: A cache object that deletes the least-recently-used items.
homepage:
license: isc
licenses:
- sources: LICENSE
text: |
The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
notices: []

View File

@@ -1,6 +1,6 @@
---
name: node-fetch
version: 2.6.7
version: 2.6.0
type: npm
summary: A light-weight module that brings window.fetch to node.js
homepage: https://github.com/bitinn/node-fetch
@@ -42,10 +42,6 @@ licenses:
[codecov-url]: https://codecov.io/gh/bitinn/node-fetch
[install-size-image]: https://flat.badgen.net/packagephobia/install/node-fetch
[install-size-url]: https://packagephobia.now.sh/result?p=node-fetch
[discord-image]: https://img.shields.io/discord/619915844268326952?color=%237289DA&label=Discord&style=flat-square
[discord-url]: https://discord.gg/Zxbndcm
[opencollective-image]: https://opencollective.com/node-fetch/backers.svg
[opencollective-url]: https://opencollective.com/node-fetch
[whatwg-fetch]: https://fetch.spec.whatwg.org/
[response-init]: https://fetch.spec.whatwg.org/#responseinit
[node-readable]: https://nodejs.org/api/stream.html#stream_readable_streams

View File

@@ -1,9 +1,9 @@
---
name: semver
version: 7.3.5
version: 7.3.2
type: npm
summary: The semantic version parser used by npm.
homepage:
homepage: https://github.com/npm/node-semver#readme
license: isc
licenses:
- sources: LICENSE

View File

@@ -1,30 +0,0 @@
---
name: tr46
version: 0.0.3
type: npm
summary: An implementation of the Unicode TR46 spec
homepage: https://github.com/Sebmaster/tr46.js#readme
license: mit
licenses:
- sources: Auto-generated MIT license text
text: |
MIT License
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
notices: []

View File

@@ -1,23 +0,0 @@
---
name: webidl-conversions
version: 3.0.1
type: npm
summary: Implements the WebIDL algorithms for converting to and from JavaScript values
homepage:
license: bsd-2-clause
licenses:
- sources: LICENSE.md
text: |
# The BSD 2-Clause License
Copyright (c) 2014, Domenic Denicola
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
notices: []

View File

@@ -1,26 +0,0 @@
---
name: yallist
version: 4.0.0
type: npm
summary: Yet Another Linked List
homepage:
license: isc
licenses:
- sources: LICENSE
text: |
The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
notices: []

View File

@@ -1,53 +0,0 @@
# Changelog
# [7.0.0]
:warning: Breaking change :warning:
* Allow daysBeforeStale options to be float by @irega in https://github.com/actions/stale/pull/841
* Use cache in check-dist.yml by @jongwooo in https://github.com/actions/stale/pull/876
* fix print outputs step in existing workflows by @irega in https://github.com/actions/stale/pull/859
* Update issue and PR templates, add/delete workflow files by @IvanZosimov in https://github.com/actions/stale/pull/880
* Update how stale handles exempt items by @johnsudol in https://github.com/actions/stale/pull/874
# [6.0.1]
Update @actions/core to v1.10.0 ([#839](https://github.com/actions/stale/pull/839))
# [6.0.0]
:warning: Breaking change :warning:
Issues/PRs default `close-issue-reason` is now `not_planned`([#789](https://github.com/actions/stale/issues/789))
# [5.1.0]
[Don't process stale issues right after they're marked stale](https://github.com/actions/stale/issues/696)
[Add close-issue-reason option][#764](https://github.com/actions/stale/pull/764)[#772](https://github.com/actions/stale/pull/772)
Various dependabot/dependency updates
## [4.1.0](https://github.com/actions/stale/compare/v3.0.19...v4.1.0) (2021-07-14)
## Features
- [Ability to exempt draft PRs](https://github.com/actions/stale/commit/9912fa74d1c01b5d6187793d97441019cbe325d0)
## [4.0.0](https://github.com/actions/stale/compare/v3.0.19...v4.0.0) (2021-07-14)
### 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,2 +1 @@
* @actions/actions-runtime
* @actions/runner-images-team

View File

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

214
README.md
View File

@@ -2,94 +2,94 @@
Warns and then closes issues and PRs that have had no activity for a specified amount of time.
The configuration must be on the default branch and the default values will:
The default configuration will:
- Add a label "Stale" on issues and pull requests after 60 days of inactivity and comment on them
- 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, delete branch, 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:
contents: write # only for delete-branch option
issues: read
pull-requests: read
```
In addition, based on the provided configuration, the action could require more permission(s) (e.g.: add label, remove label, comment, close, etc.).
You can find more information about the required permissions under the corresponding options that you wish to use.
However, if don't want to bother, you can use these permissions:
```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
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 | |
| [close-issue-reason](#close-issue-reason) | Reason to use when closing issues | `not_planned` |
| [stale-pr-label](#stale-pr-label) | Label to apply on staled PRs | `Stale` |
| [close-pr-label](#close-pr-label) | Label to apply on closed PRs | |
| [exempt-issue-labels](#exempt-issue-labels) | Labels on issues exempted from stale | |
| [exempt-pr-labels](#exempt-pr-labels) | Labels on PRs exempted from stale | |
| [only-labels](#only-labels) | Only issues/PRs with ALL these labels are checked | |
| [only-issue-labels](#only-issue-labels) | Override [only-labels](#only-labels) for issues only | |
| [only-pr-labels](#only-pr-labels) | Override [only-labels](#only-labels) for PRs only | |
| [any-of-labels](#any-of-labels) | Only issues/PRs with ANY of these labels are checked | |
| [any-of-issue-labels](#any-of-issue-labels) | Override [any-of-labels](#any-of-labels) for issues only | |
| [any-of-pr-labels](#any-of-pr-labels) | Override [any-of-labels](#any-of-labels) for PRs only | |
| [operations-per-run](#operations-per-run) | Max number of operations per run | `30` |
| [remove-stale-when-updated](#remove-stale-when-updated) | Remove stale label from issues/PRs on updates | `true` |
| [remove-issue-stale-when-updated](#remove-issue-stale-when-updated) | Remove stale label from issues on updates/comments | |
| [remove-pr-stale-when-updated](#remove-pr-stale-when-updated) | Remove stale label from PRs on updates/comments | |
| [labels-to-add-when-unstale](#labels-to-add-when-unstale) | Add specified labels from issues/PRs when they become unstale | |
| [labels-to-remove-when-unstale](#labels-to-remove-when-unstale) | Remove specified labels from issues/PRs when they become unstale | |
| [debug-only](#debug-only) | Dry-run | `false` |
| [ascending](#ascending) | Order to get issues/PRs | `false` |
| [start-date](#start-date) | Skip stale action for issues/PRs created before it | |
| [delete-branch](#delete-branch) | Delete branch after closing a stale PR | `false` |
| [exempt-milestones](#exempt-milestones) | Milestones on issues/PRs exempted from stale | |
| [exempt-issue-milestones](#exempt-issue-milestones) | Override [exempt-milestones](#exempt-milestones) for issues only | |
| [exempt-pr-milestones](#exempt-pr-milestones) | Override [exempt-milestones](#exempt-milestones) for PRs only | |
| [exempt-all-milestones](#exempt-all-milestones) | Exempt all issues/PRs with milestones from stale | `false` |
| [exempt-all-issue-milestones](#exempt-all-issue-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for issues only | |
| [exempt-all-pr-milestones](#exempt-all-pr-milestones) | Override [exempt-all-milestones](#exempt-all-milestones) for PRs only | |
| [exempt-assignees](#exempt-assignees) | Assignees on issues/PRs exempted from stale | |
| [exempt-issue-assignees](#exempt-issue-assignees) | Override [exempt-assignees](#exempt-assignees) for issues only | |
| [exempt-pr-assignees](#exempt-pr-assignees) | Override [exempt-assignees](#exempt-assignees) for PRs only | |
| [exempt-all-assignees](#exempt-all-assignees) | Exempt all issues/PRs with assignees from stale | `false` |
| [exempt-all-issue-assignees](#exempt-all-issue-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for issues only | |
| [exempt-all-pr-assignees](#exempt-all-pr-assignees) | Override [exempt-all-assignees](#exempt-all-assignees) for PRs only | |
| [exempt-draft-pr](#exempt-draft-pr) | Skip the stale action for draft PRs | `false` |
| [enable-statistics](#enable-statistics) | Display statistics in the logs | `true` |
| [ignore-updates](#ignore-updates) | Any update (update/comment) can reset the stale idle time on the issues/PRs | `false` |
| [ignore-issue-updates](#ignore-issue-updates) | Override [ignore-updates](#ignore-updates) for issues only | |
| [ignore-pr-updates](#ignore-pr-updates) | Override [ignore-updates](#ignore-updates) for PRs only | |
| [include-only-assigned](#include-only-assigned) | Process only assigned issues | `false` |
| 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 |
| Output | Description |
| ----------------- | -------------------------------------------- |
| staled-issues-prs | List of all staled issues and pull requests. |
| closed-issues-prs | List of all closed issues and pull requests. |
### Detailed options
@@ -103,9 +103,7 @@ 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.
It means that any updates made, or any comments added to the issues or to the pull requests will restart the counter of days before marking as stale.
However, if you wish to ignore this behaviour so that the creation date (based on [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `created_at`) only matters, you can disable the [ignore-updates](#ignore-updates) option.
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.
@@ -131,7 +129,6 @@ You can fine tune which issues or pull requests should be marked as stale based
- [exempt-all-milestones](#exempt-all-milestones)
- [exempt-assignees](#exempt-assignees)
- [exempt-all-assignees](#exempt-all-assignees)
- [ignore-updates](#ignore-updates)
Default value: `60`
@@ -178,7 +175,7 @@ Default value: unset
The message that will be added as a comment to the issues when the stale workflow marks it automatically as stale with a label.
You can skip the comment sending by passing an empty string.
You can skip the comment sending by omitting the option or by passing an empty string.
Default value: unset
Required Permission: `issues: write`
@@ -187,7 +184,7 @@ Required Permission: `issues: write`
The message that will be added as a comment to the pull requests when the stale workflow marks it automatically as stale with a label.
You can skip the comment sending by passing an empty string.
You can skip the comment sending by omitting the option or by passing an empty string.
Default value: unset
Required Permission: `pull-requests: write`
@@ -222,12 +219,6 @@ It will be automatically removed if the issues are no longer closed nor locked.
Default value: unset
Required Permission: `issues: write`
#### close-issue-reason
Specify the [reason](https://github.blog/changelog/2022-05-19-the-new-github-issues-may-19th-update/) used when closing issues. Valid values are `completed` and `not_planned`.
Default value: `not_planned`
#### stale-pr-label
The label that will be added to the pull requests when automatically marked as stale.
@@ -246,8 +237,8 @@ Required Permission: `pull-requests: write`
#### exempt-issue-labels
Comma separated list of labels that can be assigned to issues to exclude them from being marked as stale
(e.g: `question,bug`)
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.
@@ -255,8 +246,8 @@ Default value: unset
#### exempt-pr-labels
Comma separated list of labels that can be assigned to pull requests to exclude them from being marked as stale
(e.g: `need-help,WIP`)
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.
@@ -398,7 +389,7 @@ Default value: unset
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` and `contents: write`
Required Permission: `pull-requests: write`
#### exempt-milestones
@@ -482,14 +473,6 @@ Override [exempt-all-assignees](#exempt-all-assignees) but only to exempt the pu
Default value: unset
#### exempt-draft-pr
If set to `true`, the pull requests currently in draft will not be marked as stale automatically.
⚠️ This option consume one operation per pull request to process because we need to fetch the pull request with the GitHub API to know if it's a draft one or not.
Default value: `false`
Required Permission: `pull-requests: read`
#### enable-statistics
Collects and display statistics at the end of the stale workflow logs to get a summary of what happened during the run.
@@ -497,33 +480,6 @@ This option is only useful if the debug output secret `ACTIONS_STEP_DEBUG` is se
Default value: `true`
#### ignore-updates
The option [days-before-stale](#days-before-stale) will define the number of days before considering the issues or the pull requests as stale.
In most cases, the purpose of this action is to only stale when necessary so if any update occurs or if a comment is added to them, the counter will restart.
Nonetheless, if you don't care about this, and you prefer to stick to this number of days no matter the update, you can enable this option.
Instead of comparing the number of days based on the [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `updated_at`, it will be based on the [GitHub issue](https://docs.github.com/en/rest/reference/issues) field `created_at`.
Default value: `false`
#### ignore-issue-updates
Useful to override [ignore-updates](#ignore-updates) but only to ignore the updates for the issues.
Default value: unset
#### ignore-pr-updates
Useful to override [ignore-updates](#ignore-updates) but only to ignore the updates for the pull requests.
Default value: unset
#### include-only-assigned
If set to `true`, only the issues or the pull requests with an assignee will be marked as stale automatically.
Default value: `false`
### Usage
See also [action.yml](./action.yml) for a comprehensive list of all the options.
@@ -540,7 +496,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- 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'
@@ -558,7 +514,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- 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
@@ -577,8 +533,9 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- 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.'
@@ -599,8 +556,9 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- 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.'
@@ -623,7 +581,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- uses: actions/stale@v3
with:
stale-issue-message: 'Stale issue message'
stale-pr-message: 'Stale pull request message'
@@ -646,9 +604,9 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- uses: actions/stale@v3
with:
start-date: '2020-04-18T00:00:00Z' # ISO 8601 or RFC 2822
start-date: '2020-18-04T00:00:00Z' # ISO 8601 or RFC 2822
```
Avoid stale for specific milestones:
@@ -663,7 +621,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- uses: actions/stale@v3
with:
exempt-issue-milestones: 'future,alpha,beta'
exempt-pr-milestones: 'bugfix,improvement'
@@ -681,7 +639,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- uses: actions/stale@v3
with:
exempt-all-pr-milestones: true
```
@@ -698,7 +656,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- 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
@@ -717,7 +675,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- uses: actions/stale@v3
with:
exempt-issue-assignees: 'marco,polo'
exempt-pr-assignees: 'marco'
@@ -735,7 +693,7 @@ jobs:
stale:
runs-on: ubuntu-latest
steps:
- uses: actions/stale@v6
- uses: actions/stale@v3
with:
exempt-all-pr-assignees: true
```

View File

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

@@ -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

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

View File

@@ -1,7 +1,5 @@
import {IIssuesProcessorOptions} from '../../src/interfaces/issues-processor-options';
// Default options for use in tests.
// Mirrors the defaults defined in action.yml
export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
repoToken: 'none',
staleIssueMessage: 'This issue is stale',
@@ -48,11 +46,5 @@ export const DefaultProcessorOptions: IIssuesProcessorOptions = Object.freeze({
exemptAllPrAssignees: undefined,
enableStatistics: true,
labelsToRemoveWhenUnstale: '',
labelsToAddWhenUnstale: '',
ignoreUpdates: false,
ignoreIssueUpdates: undefined,
ignorePrUpdates: undefined,
exemptDraftPr: false,
closeIssueReason: 'not_planned',
includeOnlyAssigned: false
labelsToAddWhenUnstale: ''
});

View File

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

View File

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

View File

@@ -16,6 +16,7 @@ test('processing an issue with no label will make it stale and close it, if it i
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -47,6 +48,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -78,6 +80,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -109,6 +112,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -140,6 +144,7 @@ test('processing an issue with no label and a start date as ECMAScript epoch in
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -171,6 +176,7 @@ test('processing an issue with no label and a start date as ISO 8601 being befor
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -202,6 +208,7 @@ test('processing an issue with no label and a start date as ISO 8601 being after
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -233,6 +240,7 @@ test('processing an issue with no label and a start date as RFC 2822 being befor
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -264,6 +272,7 @@ test('processing an issue with no label and a start date as RFC 2822 being after
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -287,6 +296,7 @@ test('processing an issue with no label will make it stale and close it, if it i
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -311,6 +321,7 @@ test('processing an issue with no label will make it stale and not close it, if
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -333,6 +344,7 @@ test('processing an issue with no label will make it stale and not close it if d
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -356,6 +368,7 @@ test('processing an issue with no label will make it stale and not close it if d
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -379,6 +392,7 @@ test('processing an issue with no label will not make it stale if days-before-st
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -403,6 +417,7 @@ test('processing an issue with no label will not make it stale if days-before-st
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -430,6 +445,7 @@ test('processing an issue with no label will make it stale but not close it', as
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -460,6 +476,7 @@ test('processing a stale issue will close it', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -490,6 +507,7 @@ test('processing a stale issue containing a space in the label will close it', a
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -520,6 +538,7 @@ test('processing a stale issue containing a slash in the label will close it', a
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -551,6 +570,7 @@ test('processing a stale issue will close it when days-before-issue-stale overri
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -581,6 +601,7 @@ test('processing a stale PR will close it', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -612,6 +633,7 @@ test('processing a stale PR will close it when days-before-pr-stale override day
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -643,6 +665,7 @@ test('processing a stale issue will close it even if configured not to mark as s
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -675,6 +698,7 @@ test('processing a stale issue will close it even if configured not to mark as s
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -706,6 +730,7 @@ test('processing a stale PR will close it even if configured not to mark as stal
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -738,6 +763,7 @@ test('processing a stale PR will close it even if configured not to mark as stal
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -765,6 +791,7 @@ test('closed issues will not be marked stale', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => []
);
@@ -791,6 +818,7 @@ test('stale closed issues will not be closed', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -818,6 +846,7 @@ test('closed prs will not be marked stale', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -845,6 +874,7 @@ test('stale closed prs will not be closed', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -871,8 +901,10 @@ test('locked issues will not be marked stale', async () => {
true
)
];
const processor = new IssuesProcessorMock(DefaultProcessorOptions, async p =>
p === 1 ? TestIssueList : []
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : [])
);
// process our fake issue list
@@ -898,6 +930,7 @@ test('stale locked issues will not be closed', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -924,8 +957,10 @@ test('locked prs will not be marked stale', async () => {
true
)
];
const processor = new IssuesProcessorMock(DefaultProcessorOptions, async p =>
p === 1 ? TestIssueList : []
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : [])
);
// process our fake issue list
@@ -951,6 +986,7 @@ test('stale locked prs will not be closed', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -980,6 +1016,7 @@ test('exempt issue labels will not be marked stale', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1009,6 +1046,7 @@ test('exempt issue labels will not be marked stale (multi issue label with space
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1037,6 +1075,7 @@ test('exempt issue labels will not be marked stale (multi issue label)', async (
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1083,6 +1122,7 @@ test('exempt pr labels will not be marked stale', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1094,6 +1134,44 @@ test('exempt pr labels will not be marked stale', async () => {
expect(processor.staleIssues).toHaveLength(2); // PR should get processed even though it has an exempt **issue** label
});
test('exempt issue labels will not be marked stale and will remove the existing stale label', async () => {
expect.assertions(3);
const opts = {...DefaultProcessorOptions};
opts.exemptIssueLabels = 'Exempt';
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'My first issue',
'2020-01-01T17:00:00Z',
'2020-01-01T17:00:00Z',
false,
['Exempt', 'Stale']
)
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [
{
user: {
login: 'notme',
type: 'User'
}
}
], // return a fake comment to indicate there was an update
async () => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues.length).toStrictEqual(0);
expect(processor.closedIssues.length).toStrictEqual(0);
expect(processor.removedLabelIssues.length).toStrictEqual(1);
});
test('stale issues should not be closed if days is set to -1', async () => {
const opts = {...DefaultProcessorOptions};
opts.daysBeforeClose = -1;
@@ -1128,6 +1206,7 @@ test('stale issues should not be closed if days is set to -1', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1155,14 +1234,14 @@ test('stale label should be removed if a comment was added to a stale issue', as
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [
{
user: {
login: 'notme',
type: 'User'
},
body: 'Body'
}
}
], // return a fake comment to indicate there was an update
async () => new Date().toDateString()
@@ -1196,14 +1275,14 @@ test('when the option "labelsToAddWhenUnstale" is set, the labels should be adde
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [
{
user: {
login: 'notme',
type: 'User'
},
body: 'Body'
}
}
], // return a fake comment to indicate there was an update
async () => new Date().toDateString()
@@ -1236,14 +1315,14 @@ test('stale label should not be removed if a comment was added by the bot (and t
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [
{
user: {
login: 'abot',
type: 'User'
},
body: 'This issue is stale'
}
}
], // return a fake comment to indicate there was an update by the bot
async () => new Date().toDateString()
@@ -1276,8 +1355,9 @@ test('stale label containing a space should be removed if a comment was added to
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [{user: {login: 'notme', type: 'User'}, body: 'Body'}], // return a fake comment to indicate there was an update
async () => [{user: {login: 'notme', type: 'User'}}], // return a fake comment to indicate there was an update
async () => new Date().toDateString()
);
@@ -1307,6 +1387,7 @@ test('stale issues should not be closed until after the closed number of days',
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1339,6 +1420,7 @@ test('stale issues should be closed if the closed nubmer of days (additive) is a
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1370,6 +1452,7 @@ test('stale issues should not be closed until after the closed number of days (l
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1402,6 +1485,7 @@ test('skips stale message on issues when stale-issue-message is empty', async ()
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1446,6 +1530,7 @@ test('send stale message on issues when stale-issue-message is not empty', async
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1490,6 +1575,7 @@ test('skips stale message on prs when stale-pr-message is empty', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1534,6 +1620,7 @@ test('send stale message on prs when stale-pr-message is not empty', async () =>
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1575,6 +1662,7 @@ test('git branch is deleted when option is enabled', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1604,6 +1692,7 @@ test('git branch is not deleted when issue is not pull request', async () => {
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1635,6 +1724,7 @@ test('an issue without a milestone will be marked as stale', async () => {
];
const processor = new IssuesProcessorMock(
DefaultProcessorOptions,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1668,6 +1758,7 @@ test('an issue without an exempted milestone will be marked as stale', async ()
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1701,6 +1792,7 @@ test('an issue with an exempted milestone will not be marked as stale', async ()
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1734,6 +1826,7 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1767,6 +1860,7 @@ test('an issue with an exempted milestone will not be marked as stale (multi mil
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1801,6 +1895,7 @@ test('an issue with an exempted milestone but without an exempted issue mileston
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1835,6 +1930,7 @@ test('an issue with an exempted milestone but with another exempted issue milest
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1869,6 +1965,7 @@ test('an issue with an exempted milestone and with an exempted issue milestone w
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1896,6 +1993,7 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1922,6 +2020,7 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1948,6 +2047,7 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -1960,84 +2060,6 @@ test('processing an issue opened since 2 days and with the option "daysBeforeIss
expect(processor.closedIssues).toHaveLength(0);
});
test('processing an issue opened since 1 hour and with the option "daysBeforeIssueStale" at 0.1666666667 (4 hours) will not make it stale', async () => {
expect.assertions(2);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeStale: 10,
daysBeforeIssueStale: 0.1666666667
};
const issueDate = new Date();
issueDate.setHours(issueDate.getHours() - 1);
const TestIssueList: Issue[] = [
generateIssue(opts, 1, 'An issue with no label', issueDate.toISOString())
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(0);
expect(processor.closedIssues).toHaveLength(0);
});
test('processing an issue opened since 4 hours and with the option "daysBeforeIssueStale" at 0.1666666667 (4 hours) will make it stale', async () => {
expect.assertions(2);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeStale: 10,
daysBeforeIssueStale: 0.1666666667
};
const issueDate = new Date();
issueDate.setHours(issueDate.getHours() - 4);
const TestIssueList: Issue[] = [
generateIssue(opts, 1, 'An issue with no label', issueDate.toISOString())
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(0);
});
test('processing an issue opened since 5 hours and with the option "daysBeforeIssueStale" at 0.1666666667 (4 hours) will make it stale', async () => {
expect.assertions(2);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeStale: 10,
daysBeforeIssueStale: 0.1666666667
};
const issueDate = new Date();
issueDate.setHours(issueDate.getHours() - 5);
const TestIssueList: Issue[] = [
generateIssue(opts, 1, 'An issue with no label', issueDate.toISOString())
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(0);
});
test('processing a pull request opened since 2 days and with the option "daysBeforePrStale" at 3 will not make it stale', async () => {
expect.assertions(2);
const opts: IIssuesProcessorOptions = {
@@ -2059,6 +2081,7 @@ test('processing a pull request opened since 2 days and with the option "daysBef
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2092,6 +2115,7 @@ test('processing a pull request opened since 2 days and with the option "daysBef
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2125,6 +2149,7 @@ test('processing a pull request opened since 2 days and with the option "daysBef
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2137,105 +2162,6 @@ test('processing a pull request opened since 2 days and with the option "daysBef
expect(processor.closedIssues).toHaveLength(0);
});
test('processing a pull request opened since 1 hour and with the option "daysBeforePrStale" at 0.1666666667 (4 hours) will not make it stale', async () => {
expect.assertions(2);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeStale: 10,
daysBeforePrStale: 0.1666666667
};
const issueDate = new Date();
issueDate.setHours(issueDate.getHours() - 1);
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'A pull request with no label',
issueDate.toISOString(),
issueDate.toISOString(),
true
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(0);
expect(processor.closedIssues).toHaveLength(0);
});
test('processing a pull request opened since 4 hours and with the option "daysBeforePrStale" at 0.1666666667 (4 hours) will make it stale', async () => {
expect.assertions(2);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeStale: 10,
daysBeforePrStale: 0.1666666667
};
const issueDate = new Date();
issueDate.setHours(issueDate.getHours() - 4);
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'A pull request with no label',
issueDate.toISOString(),
issueDate.toISOString(),
true
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(0);
});
test('processing a pull request opened since 5 hours and with the option "daysBeforePrStale" at 0.1666666667 (4 hours) will make it stale', async () => {
expect.assertions(2);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
daysBeforeStale: 10,
daysBeforePrStale: 0.1666666667
};
const issueDate = new Date();
issueDate.setHours(issueDate.getHours() - 5);
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'A pull request with no label',
issueDate.toISOString(),
issueDate.toISOString(),
true
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toISOString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(0);
});
test('processing a previously closed issue with a close label will remove the close label', async () => {
expect.assertions(1);
const opts: IIssuesProcessorOptions = {
@@ -2260,6 +2186,7 @@ test('processing a previously closed issue with a close label will remove the cl
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2295,6 +2222,7 @@ test('processing a closed issue with a close label will not remove the close lab
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2330,6 +2258,7 @@ test('processing a locked issue with a close label will not remove the close lab
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
@@ -2369,6 +2298,7 @@ test('processing an issue stale since less than the daysBeforeStale with a stale
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async (): Promise<IComment[]> => Promise.resolve([]),
async () => labelCreatedAt.toDateString()
@@ -2409,6 +2339,7 @@ test('processing an issue stale since less than the daysBeforeStale without a st
];
const processor = new IssuesProcessorMock(
opts,
async () => 'abot',
async p => (p === 1 ? TestIssueList : []),
async (): Promise<IComment[]> => Promise.resolve([]),
async () => new Date().toDateString()
@@ -2421,139 +2352,3 @@ test('processing an issue stale since less than the daysBeforeStale without a st
expect(processor.deletedBranchIssues).toHaveLength(0);
expect(processor.closedIssues).toHaveLength(0);
});
test('processing a pull request to be stale with the "stalePrMessage" option set will send a PR comment', async () => {
expect.assertions(3);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
stalePrMessage: 'This PR is stale',
daysBeforeStale: 10,
daysBeforePrStale: 1
};
const issueDate = new Date();
issueDate.setDate(issueDate.getDate() - 2);
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'A pull request with no label and a stale message',
issueDate.toDateString(),
issueDate.toDateString(),
true
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(0);
expect(processor.statistics?.addedPullRequestsCommentsCount).toStrictEqual(1);
});
test('processing a pull request to be stale with the "stalePrMessage" option set to empty will not send a PR comment', async () => {
expect.assertions(3);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
stalePrMessage: '',
daysBeforeStale: 10,
daysBeforePrStale: 1
};
const issueDate = new Date();
issueDate.setDate(issueDate.getDate() - 2);
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'A pull request with no label and a stale message',
issueDate.toDateString(),
issueDate.toDateString(),
true
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(0);
expect(processor.statistics?.addedPullRequestsCommentsCount).toStrictEqual(0);
});
test('processing an issue with the "includeOnlyAssigned" option and nonempty assignee list will stale the issue', async () => {
const issueDate = new Date();
issueDate.setDate(issueDate.getDate() - 2);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
staleIssueLabel: 'This issue is stale',
includeOnlyAssigned: true
};
const TestIssueList: Issue[] = [
generateIssue(
opts,
1,
'An issue with no label',
issueDate.toDateString(),
issueDate.toDateString(),
false,
[],
false,
false,
undefined,
['assignee1']
)
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(1);
expect(processor.closedIssues).toHaveLength(0);
});
test('processing an issue with the "includeOnlyAssigned" option set and no assignees will not stale the issue', async () => {
const issueDate = new Date();
issueDate.setDate(issueDate.getDate() - 2);
const opts: IIssuesProcessorOptions = {
...DefaultProcessorOptions,
staleIssueLabel: 'This issue is stale',
includeOnlyAssigned: true
};
const TestIssueList: Issue[] = [
generateIssue(opts, 1, 'An issue with no label', issueDate.toDateString())
];
const processor = new IssuesProcessorMock(
opts,
async p => (p === 1 ? TestIssueList : []),
async () => [],
async () => new Date().toDateString()
);
// process our fake issue list
await processor.processIssues(1);
expect(processor.staleIssues).toHaveLength(0);
expect(processor.closedIssues).toHaveLength(0);
});

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

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

@@ -5,7 +5,7 @@ import {IssuesProcessorMock} from './classes/issues-processor-mock';
import {DefaultProcessorOptions} from './constants/default-processor-options';
import {generateIssue} from './functions/generate-issue';
describe('operations-per-run option', (): void => {
describe('operations per run option', (): void => {
let sut: SUT;
beforeEach((): void => {
@@ -205,6 +205,7 @@ class SUT {
private async _setProcessor(): Promise<number> {
this.processor = new IssuesProcessorMock(
this._opts,
async () => 'abot',
async p => (p === 1 ? this._testIssueList : []),
async () => [],
async () => new Date().toDateString()

View File

@@ -455,7 +455,7 @@ class IssuesProcessorBuilder {
issue.updated_at ?? new Date().toDateString(),
issue.created_at ?? new Date().toDateString(),
!!issue.pull_request,
issue.labels ? issue.labels.map(label => label.name || '') : []
issue.labels ? issue.labels.map(label => label.name) : []
)
);
@@ -539,14 +539,14 @@ class IssuesProcessorBuilder {
build(): IssuesProcessorMock {
return new IssuesProcessorMock(
this._options,
async () => 'abot',
async p => (p === 1 ? this._issues : []),
async () => [
{
user: {
login: 'notme',
type: 'User'
},
body: 'body'
}
}
],
async () => new Date().toDateString()

View File

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

View File

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

6672
dist/index.js vendored

File diff suppressed because one or more lines are too long

20160
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -1,23 +1,23 @@
{
"name": "stale-action",
"version": "7.0.0",
"version": "2.0.0",
"private": true,
"description": "Marks old issues and PRs as stale",
"main": "lib/main.js",
"scripts": {
"build": "tsc --project tsconfig.app.json && ncc build",
"format": "prettier --write --ignore-unknown **/*.{json,yml,ts}",
"format-check": "prettier --check --ignore-unknown **/*.{json,yml,ts}",
"build": "tsc --project tsconfig.app.json",
"format": "prettier --write --ignore-unknown **/*.{md,json,yml,ts}",
"format-check": "prettier --check --ignore-unknown **/*.{md,json,yml,ts}",
"lint": "eslint src/**/*.ts",
"lint:fix": "eslint src/**/*.ts --fix",
"lint:all": "npm run format-check && npm run lint",
"lint:all:fix": "npm run format && npm run lint:fix",
"test": "jest --config ./jest.config.js",
"pack": "ncc build",
"test": "jest",
"test:only-errors": "jest --reporters jest-silent-reporter --silent",
"test:watch": "jest --watch --notify --expand",
"all": "npm run format && npm run lint && npm run build && npm test",
"all:ci": "npm run format && npm run lint && npm run build && npm run test:only-errors",
"prerelease": "npm run build",
"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"
},
@@ -37,31 +37,31 @@
"author": "GitHub",
"license": "MIT",
"dependencies": {
"@actions/core": "^1.10.0",
"@actions/github": "^5.0.1",
"@actions/core": "^1.2.6",
"@actions/github": "^4.0.0",
"lodash.deburr": "^4.1.0",
"semver": "^7.3.5"
},
"devDependencies": {
"@types/jest": "^27.0.2",
"@types/jest": "^26.0.23",
"@types/lodash.deburr": "^4.1.6",
"@types/node": "^15.0.2",
"@types/semver": "^7.3.5",
"@typescript-eslint/eslint-plugin": "^4.31.1",
"@typescript-eslint/parser": "^4.31.1",
"@vercel/ncc": "^0.28.6",
"@typescript-eslint/eslint-plugin": "^4.26.0",
"@typescript-eslint/parser": "^4.26.1",
"@vercel/ncc": "^0.27.0",
"ansi-styles": "5.2.0",
"eslint": "^7.28.0",
"eslint-plugin-github": "^4.1.2",
"eslint-plugin-jest": "^25.3.2",
"jest": "^27.2.5",
"jest-circus": "^27.4.6",
"jest-silent-reporter": "^0.5.0",
"eslint-plugin-jest": "^24.3.6",
"jest": "^26.6.3",
"jest-circus": "^26.6.3",
"jest-silent-reporter": "^0.4.0",
"js-yaml": "^4.1.0",
"prettier": "^2.5.1",
"standard-version": "^9.3.1",
"prettier": "^2.3.1",
"standard-version": "^9.2.0",
"terminal-link": "^2.1.1",
"ts-jest": "^27.1.2",
"ts-jest": "^26.5.6",
"typescript": "^4.3.2"
}
}

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -1,22 +1,21 @@
import * as core from '@actions/core';
import {context, getOctokit} from '@actions/github';
import {GitHub} from '@actions/github/lib/utils';
import {GetResponseTypeFromEndpointMethod} from '@octokit/types';
import {Option} from '../enums/option';
import {getHumanizedDate} from '../functions/dates/get-humanized-date';
import {isDateMoreRecentThan} from '../functions/dates/is-date-more-recent-than';
import {isValidDate} from '../functions/dates/is-valid-date';
import {isBoolean} from '../functions/is-boolean';
import {isLabeled} from '../functions/is-labeled';
import {cleanLabel} from '../functions/clean-label';
import {shouldMarkWhenStale} from '../functions/should-mark-when-stale';
import {wordsToList} from '../functions/words-to-list';
import {IComment} from '../interfaces/comment';
import {IIssue} from '../interfaces/issue';
import {IIssueEvent} from '../interfaces/issue-event';
import {IIssuesProcessorOptions} from '../interfaces/issues-processor-options';
import {IPullRequest} from '../interfaces/pull-request';
import {Assignees} from './assignees';
import {IgnoreUpdates} from './ignore-updates';
import {ExemptDraftPullRequest} from './exempt-draft-pull-request';
import {Issue} from './issue';
import {IssueLogger} from './loggers/issue-logger';
import {Logger} from './loggers/logger';
@@ -24,14 +23,13 @@ import {Milestones} from './milestones';
import {StaleOperations} from './stale-operations';
import {Statistics} from './statistics';
import {LoggerService} from '../services/logger.service';
import {OctokitIssue} from '../interfaces/issue';
/***
* Handle processing of issues for staleness/closure.
*/
export class IssuesProcessor {
private static _updatedSince(timestamp: string, num_days: number): boolean {
const daysInMillis = 1000 * 60 * 60 * 24 * num_days;
const daysInMillis = 1000 * 60 * num_days; //temporarily number of minutes
const millisSinceLastUpdated =
new Date().getTime() - new Date(timestamp).getTime();
@@ -54,12 +52,22 @@ export class IssuesProcessor {
}
}
private static _getStaleMessageUsedOptionName(
issue: Readonly<Issue>
): Option.StalePrMessage | Option.StaleIssueMessage {
return issue.isPullRequest
? Option.StalePrMessage
: Option.StaleIssueMessage;
}
private static _getCloseLabelUsedOptionName(
issue: Readonly<Issue>
): Option.ClosePrLabel | Option.CloseIssueLabel {
return issue.isPullRequest ? Option.ClosePrLabel : Option.CloseIssueLabel;
}
private readonly _logger: Logger = new Logger();
private readonly _statistics: Statistics | undefined;
readonly operations: StaleOperations;
readonly client: InstanceType<typeof GitHub>;
readonly options: IIssuesProcessorOptions;
@@ -68,9 +76,6 @@ export class IssuesProcessor {
readonly deletedBranchIssues: Issue[] = [];
readonly removedLabelIssues: Issue[] = [];
readonly addedLabelIssues: Issue[] = [];
readonly addedCloseCommentIssues: Issue[] = [];
readonly statistics: Statistics | undefined;
private readonly _logger: Logger = new Logger();
constructor(options: IIssuesProcessorOptions) {
this.options = options;
@@ -93,19 +98,20 @@ export class IssuesProcessor {
}
if (this.options.enableStatistics) {
this.statistics = new Statistics();
this._statistics = new Statistics();
}
}
async processIssues(page: Readonly<number> = 1): Promise<number> {
// get the next batch of issues
const issues: Issue[] = await this.getIssues(page);
const actor: string = await this.getActor();
if (issues.length <= 0) {
this._logger.info(
LoggerService.green(`No more issues found to process. Exiting...`)
);
this.statistics
this._statistics
?.setOperationsCount(this.operations.getConsumedOperationsCount())
.logStats();
@@ -113,11 +119,11 @@ export class IssuesProcessor {
} else {
this._logger.info(
`${LoggerService.yellow(
'Processing the batch of issues '
'Processing the batch of issues'
)} ${LoggerService.cyan(`#${page}`)} ${LoggerService.yellow(
' containing '
'containing'
)} ${LoggerService.cyan(issues.length)} ${LoggerService.yellow(
` issue${issues.length > 1 ? 's' : ''}...`
`issue${issues.length > 1 ? 's' : ''}...`
)}`
);
}
@@ -139,6 +145,7 @@ export class IssuesProcessor {
await issueLogger.grouping(`$$type #${issue.number}`, async () => {
await this.processIssue(
issue,
actor,
labelsToAddWhenUnstale,
labelsToRemoveWhenUnstale
);
@@ -151,14 +158,14 @@ export class IssuesProcessor {
);
this._logger.warning(
`${LoggerService.yellowBright(
'If you think that not enough issues were processed you could try to increase the quantity related to the '
'If you think that not enough issues were processed you could try to increase the quantity related to the'
)} ${this._logger.createOptionLink(
Option.OperationsPerRun
)} ${LoggerService.yellowBright(
' option which is currently set to '
'option which is currently set to'
)} ${LoggerService.cyan(this.options.operationsPerRun)}`
);
this.statistics
this._statistics
?.setOperationsCount(this.operations.getConsumedOperationsCount())
.logStats();
@@ -166,9 +173,9 @@ export class IssuesProcessor {
}
this._logger.info(
`${LoggerService.green('Batch ')} ${LoggerService.cyan(
`${LoggerService.green('Batch')} ${LoggerService.cyan(
`#${page}`
)} ${LoggerService.green(' processed.')}`
)} ${LoggerService.green('processed.')}`
);
// Do the next batch
@@ -177,10 +184,11 @@ export class IssuesProcessor {
async processIssue(
issue: Issue,
actor: string,
labelsToAddWhenUnstale: Readonly<string>[],
labelsToRemoveWhenUnstale: Readonly<string>[]
): Promise<void> {
this.statistics?.incrementProcessedItemsCount(issue);
this._statistics?.incrementProcessedItemsCount(issue);
const issueLogger: IssueLogger = new IssueLogger(issue);
issueLogger.info(
@@ -208,27 +216,6 @@ export class IssuesProcessor {
const daysBeforeStale: number = issue.isPullRequest
? this._getDaysBeforePrStale()
: this._getDaysBeforeIssueStale();
if (issue.state === 'closed') {
issueLogger.info(`Skipping this $$type because it is closed`);
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process closed issues
}
if (issue.locked) {
issueLogger.info(`Skipping this $$type because it is locked`);
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process locked issues
}
if (this._isIncludeOnlyAssigned(issue)) {
issueLogger.info(
`Skipping this $$type because its assignees list is empty`
);
IssuesProcessor._endIssueProcessing(issue);
return; // If the issue has an 'include-only-assigned' option set, process only issues with nonempty assignees list
}
const onlyLabels: string[] = wordsToList(this._getOnlyLabels(issue));
if (onlyLabels.length > 0) {
@@ -282,6 +269,18 @@ export class IssuesProcessor {
const shouldMarkAsStale: boolean = shouldMarkWhenStale(daysBeforeStale);
if (issue.state === 'closed') {
issueLogger.info(`Skipping this $$type because it is closed`);
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process closed issues
}
if (issue.locked) {
issueLogger.info(`Skipping this $$type because it is locked`);
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process locked issues
}
// Try to remove the close label when not close/locked issue or PR
await this._removeCloseLabel(issue, closeLabel);
@@ -321,9 +320,9 @@ export class IssuesProcessor {
}
if (issue.isStale) {
issueLogger.info(`This $$type includes a stale label`);
issueLogger.info(`This $$type has a stale label`);
} else {
issueLogger.info(`This $$type does not include a stale label`);
issueLogger.info(`This $$type hasn't a stale label`);
}
const exemptLabels: string[] = wordsToList(
@@ -332,16 +331,17 @@ export class IssuesProcessor {
: this.options.exemptIssueLabels
);
const hasExemptLabel = exemptLabels.some((exemptLabel: Readonly<string>) =>
isLabeled(issue, exemptLabel)
);
if (
exemptLabels.some((exemptLabel: Readonly<string>): boolean =>
isLabeled(issue, exemptLabel)
)
) {
if (issue.isStale) {
issueLogger.info(`An exempt label was added after the stale label.`);
await this._removeStaleLabel(issue, staleLabel);
}
if (hasExemptLabel) {
issueLogger.info(
`Skipping this $$type because it contains an exempt label, see ${issueLogger.createOptionLink(
issue.isPullRequest ? Option.ExemptPrLabels : Option.ExemptIssueLabels
)} for more details`
);
issueLogger.info(`Skipping this $$type because it has an exempt label`);
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process exempt issues
}
@@ -406,64 +406,23 @@ export class IssuesProcessor {
return; // Don't process exempt assignees
}
// Ignore draft PR
// Note that this check is so far below because it cost one read operation
// So it's simply better to do all the stale checks which don't cost more operation before this one
const exemptDraftPullRequest: ExemptDraftPullRequest =
new ExemptDraftPullRequest(this.options, issue);
if (
await exemptDraftPullRequest.shouldExemptDraftPullRequest(
async (): Promise<IPullRequest | undefined | void> => {
return this.getPullRequest(issue);
}
)
) {
IssuesProcessor._endIssueProcessing(issue);
return; // Don't process draft PR
}
// Should this issue be marked stale?
const shouldBeStale = !IssuesProcessor._updatedSince(
issue.updated_at,
daysBeforeStale
);
// Determine if this issue needs to be marked stale first
if (!issue.isStale) {
issueLogger.info(`This $$type is not stale`);
const shouldIgnoreUpdates: boolean = new IgnoreUpdates(
this.options,
issue
).shouldIgnoreUpdates();
// Should this issue be marked as stale?
let shouldBeStale: boolean;
// Ignore the last update and only use the creation date
if (shouldIgnoreUpdates) {
shouldBeStale = !IssuesProcessor._updatedSince(
issue.created_at,
daysBeforeStale
);
}
// Use the last update to check if we need to stale
else {
shouldBeStale = !IssuesProcessor._updatedSince(
issue.updated_at,
daysBeforeStale
);
}
const updatedAtDate: Date = new Date(issue.updated_at);
if (shouldBeStale) {
if (shouldIgnoreUpdates) {
issueLogger.info(
`This $$type should be stale based on the creation date the ${getHumanizedDate(
new Date(issue.created_at)
)} (${LoggerService.cyan(issue.created_at)})`
);
} else {
issueLogger.info(
`This $$type should be stale based on the last update date the ${getHumanizedDate(
new Date(issue.updated_at)
)} (${LoggerService.cyan(issue.updated_at)})`
);
}
issueLogger.info(
`This $$type should be stale based on the last update date the ${getHumanizedDate(
updatedAtDate
)} (${LoggerService.cyan(issue.updated_at)})`
);
if (shouldMarkAsStale) {
issueLogger.info(
@@ -473,7 +432,6 @@ export class IssuesProcessor {
);
await this._markStale(issue, staleMessage, staleLabel, skipMessage);
issue.isStale = true; // This issue is now considered stale
issue.markedStaleThisRun = true;
issueLogger.info(`This $$type is now stale`);
} else {
issueLogger.info(
@@ -483,19 +441,11 @@ export class IssuesProcessor {
);
}
} else {
if (shouldIgnoreUpdates) {
issueLogger.info(
`This $$type should not be stale based on the creation date the ${getHumanizedDate(
new Date(issue.created_at)
)} (${LoggerService.cyan(issue.created_at)})`
);
} else {
issueLogger.info(
`This $$type should not be stale based on the last update date the ${getHumanizedDate(
new Date(issue.updated_at)
)} (${LoggerService.cyan(issue.updated_at)})`
);
}
issueLogger.info(
`This $$type should not be stale based on the last update date the ${getHumanizedDate(
updatedAtDate
)} (${LoggerService.cyan(issue.updated_at)})`
);
}
}
@@ -505,7 +455,7 @@ export class IssuesProcessor {
await this._processStaleIssue(
issue,
staleLabel,
staleMessage,
actor,
labelsToAddWhenUnstale,
labelsToRemoveWhenUnstale,
closeMessage,
@@ -518,17 +468,17 @@ export class IssuesProcessor {
// Grab comments for an issue since a given date
async listIssueComments(
issue: Readonly<Issue>,
issueNumber: Readonly<number>,
sinceDate: Readonly<string>
): Promise<IComment[]> {
// Find any comments since date on the given issue
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementFetchedItemsCommentsCount();
const comments = await this.client.rest.issues.listComments({
this.operations.consumeOperation();
this._statistics?.incrementFetchedItemsCommentsCount();
const comments = await this.client.issues.listComments({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
issue_number: issueNumber,
since: sinceDate
});
return comments.data;
@@ -538,22 +488,41 @@ export class IssuesProcessor {
}
}
// grab issues from github in batches of 100
async getIssues(page: number): Promise<Issue[]> {
// get the actor from the GitHub token or context
async getActor(): Promise<string> {
let actor;
try {
this.operations.consumeOperation();
const issueResult = await this.client.rest.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100,
direction: this.options.ascending ? 'asc' : 'desc',
page
});
this.statistics?.incrementFetchedItemsCount(issueResult.data.length);
actor = await this.client.users.getAuthenticated();
} catch (error) {
return context.actor;
}
return actor.data.login;
}
// grab issues from github in batches of 100
async getIssues(page: number): Promise<Issue[]> {
// generate type for response
const endpoint = this.client.issues.listForRepo;
type OctoKitIssueList = GetResponseTypeFromEndpointMethod<typeof endpoint>;
try {
this.operations.consumeOperation();
const issueResult: OctoKitIssueList =
await this.client.issues.listForRepo({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
per_page: 100,
direction: this.options.ascending ? 'asc' : 'desc',
page
});
this._statistics?.incrementFetchedItemsCount(issueResult.data.length);
return issueResult.data.map(
(issue: Readonly<OctokitIssue>): Issue => new Issue(this.options, issue)
(issue: Readonly<IIssue>): Issue => new Issue(this.options, issue)
);
} catch (error) {
this._logger.error(`Get issues for repo error: ${error.message}`);
@@ -572,8 +541,8 @@ export class IssuesProcessor {
issueLogger.info(`Checking for label on this $$type`);
this._consumeIssueOperation(issue);
this.statistics?.incrementFetchedItemsEventsCount();
const options = this.client.rest.issues.listEvents.endpoint.merge({
this._statistics?.incrementFetchedItemsEventsCount();
const options = this.client.issues.listEvents.endpoint.merge({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
@@ -582,11 +551,10 @@ export class IssuesProcessor {
const events: IIssueEvent[] = await this.client.paginate(options);
const reversedEvents = events.reverse();
issueLogger.info(`Reversed Events: ${JSON.stringify(reversedEvents)}`)
const staleLabeledEvent = reversedEvents.find(
event =>
event.event === 'labeled' &&
cleanLabel(event.label.name) === cleanLabel(label)
event => event.event === 'labeled' && event.label.name === label
);
if (!staleLabeledEvent) {
@@ -597,30 +565,11 @@ export class IssuesProcessor {
return staleLabeledEvent.created_at;
}
async getPullRequest(issue: Issue): Promise<IPullRequest | undefined | void> {
const issueLogger: IssueLogger = new IssueLogger(issue);
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementFetchedPullRequestsCount();
const pullRequest = await this.client.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number
});
return pullRequest.data;
} catch (error) {
issueLogger.error(`Error when getting this $$type: ${error.message}`);
}
}
// handle all of the stale issue logic when we find a stale issue
private async _processStaleIssue(
issue: Issue,
staleLabel: string,
staleMessage: string,
actor: string,
labelsToAddWhenUnstale: Readonly<string>[],
labelsToRemoveWhenUnstale: Readonly<string>[],
closeMessage?: string,
@@ -633,15 +582,13 @@ export class IssuesProcessor {
`$$type marked stale on: ${LoggerService.cyan(markedStaleOn)}`
);
const issueHasCommentsSinceStale: boolean = await this._hasCommentsSince(
const issueHasComments: boolean = await this._hasCommentsSince(
issue,
markedStaleOn,
staleMessage
actor
);
issueLogger.info(
`$$type has been commented on: ${LoggerService.cyan(
issueHasCommentsSinceStale
)}`
`$$type has been commented on: ${LoggerService.cyan(issueHasComments)}`
);
const daysBeforeClose: number = issue.isPullRequest
@@ -652,6 +599,14 @@ export class IssuesProcessor {
`Days before $$type close: ${LoggerService.cyan(daysBeforeClose)}`
);
const issueHasUpdate: boolean = IssuesProcessor._updatedSince(
issue.updated_at,
daysBeforeClose
);
issueLogger.info(
`$$type has been updated: ${LoggerService.cyan(issueHasUpdate)}`
);
const shouldRemoveStaleWhenUpdated: boolean =
this._shouldRemoveStaleWhenUpdated(issue);
@@ -669,32 +624,10 @@ export class IssuesProcessor {
);
}
if (issue.markedStaleThisRun) {
issueLogger.info(`marked stale this run, so don't check for updates`);
}
// The issue.updated_at and markedStaleOn are not always exactly in sync (they can be off by a second or 2)
// isDateMoreRecentThan makes sure they are not the same date within a certain tolerance (15 seconds in this case)
const issueHasUpdateSinceStale = isDateMoreRecentThan(
new Date(issue.updated_at),
new Date(markedStaleOn),
15
);
issueLogger.info(
`$$type has been updated since it was marked stale: ${LoggerService.cyan(
issueHasUpdateSinceStale
)}`
);
// Should we un-stale this issue?
if (
shouldRemoveStaleWhenUpdated &&
(issueHasUpdateSinceStale || issueHasCommentsSinceStale) &&
!issue.markedStaleThisRun
) {
if (shouldRemoveStaleWhenUpdated && issueHasComments) {
issueLogger.info(
`Remove the stale label since the $$type has been updated and the workflow should remove the stale label when updated`
`Remove the stale label since the $$type has a comment and the workflow should remove the stale label when updated`
);
await this._removeStaleLabel(issue, staleLabel);
@@ -712,17 +645,7 @@ export class IssuesProcessor {
return; // Nothing to do because we aren't closing stale issues
}
const issueHasUpdateInCloseWindow: boolean = IssuesProcessor._updatedSince(
issue.updated_at,
daysBeforeClose
);
issueLogger.info(
`$$type has been updated in the last ${daysBeforeClose} days: ${LoggerService.cyan(
issueHasUpdateInCloseWindow
)}`
);
if (!issueHasCommentsSinceStale && !issueHasUpdateInCloseWindow) {
if (!issueHasComments && !issueHasUpdate) {
issueLogger.info(
`Closing $$type because it was last updated on: ${LoggerService.cyan(
issue.updated_at
@@ -734,14 +657,14 @@ export class IssuesProcessor {
issueLogger.info(
`Deleting the branch since the option ${issueLogger.createOptionLink(
Option.DeleteBranch
)} is enabled`
)} was specified`
);
await this._deleteBranch(issue);
this.deletedBranchIssues.push(issue);
}
} else {
issueLogger.info(
`Stale $$type is not old enough to close yet (hasComments? ${issueHasCommentsSinceStale}, hasUpdate? ${issueHasUpdateInCloseWindow})`
`Stale $$type is not old enough to close yet (hasComments? ${issueHasComments}, hasUpdate? ${issueHasUpdate})`
);
}
}
@@ -750,7 +673,7 @@ export class IssuesProcessor {
private async _hasCommentsSince(
issue: Issue,
sinceDate: string,
staleMessage: string
actor: string
): Promise<boolean> {
const issueLogger: IssueLogger = new IssueLogger(issue);
@@ -763,16 +686,16 @@ export class IssuesProcessor {
}
// find any comments since the date
const comments = await this.listIssueComments(issue, sinceDate);
const comments = await this.listIssueComments(issue.number, sinceDate);
core.debug(`The actor is: ${actor}`)
core.debug(`The comments are ${JSON.stringify(comments)}`)
const filteredComments = comments.filter(
comment =>
comment.user?.type === 'User' &&
comment.body?.toLowerCase() !== staleMessage.toLowerCase()
comment => comment.user.type === 'User' && comment.body !== IssuesProcessor._getStaleMessageUsedOptionName(issue)
);
issueLogger.info(
`Comments that are not the stale comment or another bot: ${LoggerService.cyan(
`Comments not made by actor or another bot: ${LoggerService.cyan(
filteredComments.length
)}`
);
@@ -801,10 +724,10 @@ export class IssuesProcessor {
if (!skipMessage) {
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementAddedItemsComment(issue);
this._statistics?.incrementAddedItemsComment(issue);
if (!this.options.debugOnly) {
await this.client.rest.issues.createComment({
await this.client.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
@@ -818,11 +741,11 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementAddedItemsLabel(issue);
this.statistics?.incrementStaleItemsCount(issue);
this._statistics?.incrementAddedItemsLabel(issue);
this._statistics?.incrementStaleItemsCount(issue);
if (!this.options.debugOnly) {
await this.client.rest.issues.addLabels({
await this.client.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
@@ -848,11 +771,10 @@ export class IssuesProcessor {
if (closeMessage) {
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementAddedItemsComment(issue);
this.addedCloseCommentIssues.push(issue);
this._statistics?.incrementAddedItemsComment(issue);
if (!this.options.debugOnly) {
await this.client.rest.issues.createComment({
await this.client.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
@@ -867,10 +789,10 @@ export class IssuesProcessor {
if (closeLabel) {
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementAddedItemsLabel(issue);
this._statistics?.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) {
await this.client.rest.issues.addLabels({
await this.client.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
@@ -884,15 +806,14 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementClosedItemsCount(issue);
this._statistics?.incrementClosedItemsCount(issue);
if (!this.options.debugOnly) {
await this.client.rest.issues.update({
await this.client.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
state: 'closed',
state_reason: this.options.closeIssueReason || undefined
state: 'closed'
});
}
} catch (error) {
@@ -900,18 +821,34 @@ export class IssuesProcessor {
}
}
private async _getPullRequest(
issue: Issue
): Promise<IPullRequest | undefined | void> {
const issueLogger: IssueLogger = new IssueLogger(issue);
try {
this._consumeIssueOperation(issue);
this._statistics?.incrementFetchedPullRequestsCount();
const pullRequest = await this.client.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number
});
return pullRequest.data;
} catch (error) {
issueLogger.error(`Error when getting this $$type: ${error.message}`);
}
}
// Delete the branch on closed pull request
private async _deleteBranch(issue: Issue): Promise<void> {
const issueLogger: IssueLogger = new IssueLogger(issue);
issueLogger.info(`Delete
branch from closed $
$type
-
${issue.title}`);
issueLogger.info(`Delete branch from closed $$type - ${issue.title}`);
const pullRequest: IPullRequest | undefined | void =
await this.getPullRequest(issue);
const pullRequest = await this._getPullRequest(issue);
if (!pullRequest) {
issueLogger.info(
@@ -927,10 +864,10 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementDeletedBranchesCount();
this._statistics?.incrementDeletedBranchesCount();
if (!this.options.debugOnly) {
await this.client.rest.git.deleteRef({
await this.client.git.deleteRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: `heads/${branch}`
@@ -962,10 +899,10 @@ export class IssuesProcessor {
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementDeletedItemsLabelsCount(issue);
this._statistics?.incrementDeletedItemsLabelsCount(issue);
if (!this.options.debugOnly) {
await this.client.rest.issues.removeLabel({
await this.client.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
@@ -1025,10 +962,6 @@ export class IssuesProcessor {
return this.options.onlyLabels;
}
private _isIncludeOnlyAssigned(issue: Issue): boolean {
return this.options.includeOnlyAssigned && !issue.hasAssignees;
}
private _getAnyOfLabels(issue: Issue): string {
if (issue.isPullRequest) {
if (this.options.anyOfPrLabels !== '') {
@@ -1099,10 +1032,10 @@ export class IssuesProcessor {
this.addedLabelIssues.push(issue);
try {
this._consumeIssueOperation(issue);
this.statistics?.incrementAddedItemsLabel(issue);
this.operations.consumeOperation();
this._statistics?.incrementAddedItemsLabel(issue);
if (!this.options.debugOnly) {
await this.client.rest.issues.addLabels({
await this.client.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
@@ -1127,7 +1060,7 @@ export class IssuesProcessor {
);
await this._removeLabel(issue, staleLabel);
this.statistics?.incrementUndoStaleItemsCount(issue);
this._statistics?.incrementUndoStaleItemsCount(issue);
}
private async _removeCloseLabel(
@@ -1164,7 +1097,7 @@ export class IssuesProcessor {
);
await this._removeLabel(issue, closeLabel, true);
this.statistics?.incrementDeletedCloseItemsLabelsCount(issue);
this._statistics?.incrementDeletedCloseItemsLabelsCount(issue);
} else {
issueLogger.info(
LoggerService.white('└──'),

View File

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

View File

@@ -42,10 +42,5 @@ export enum Option {
ExemptAllPrAssignees = 'exempt-all-pr-assignees',
EnableStatistics = 'enable-statistics',
LabelsToRemoveWhenUnstale = 'labels-to-remove-when-unstale',
LabelsToAddWhenUnstale = 'labels-to-add-when-unstale',
IgnoreUpdates = 'ignore-updates',
IgnoreIssueUpdates = 'ignore-issue-updates',
IgnorePrUpdates = 'ignore-pr-updates',
ExemptDraftPr = 'exempt-draft-pr',
CloseIssueReason = 'close-issue-reason'
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,4 +1,4 @@
import {isDateEqualTo, isDateMoreRecentThan} from './is-date-more-recent-than';
import {isDateMoreRecentThan} from './is-date-more-recent-than';
describe('isDateMoreRecentThan()', (): void => {
let date: Date;
@@ -48,68 +48,4 @@ describe('isDateMoreRecentThan()', (): void => {
expect(result).toStrictEqual(true);
});
});
describe('date equality', (): void => {
it('should correctly compare a before date outside tolerance', (): void => {
const aDate = new Date('2022-09-09T13:00:00');
const otherDate = new Date('2022-09-09T14:00:00');
expect(isDateEqualTo(aDate, otherDate, 60)).toBe(false);
});
it('should correctly compare a before date inside tolerance', (): void => {
const aDate = new Date('2022-09-09T13:00:00');
const otherDate = new Date('2022-09-09T13:00:42');
expect(isDateEqualTo(aDate, otherDate, 60)).toBe(true);
});
it('should correctly compare an after date outside tolerance', (): void => {
const aDate = new Date('2022-09-09T13:00:00');
const otherDate = new Date('2022-09-09T12:00:00');
expect(isDateEqualTo(aDate, otherDate, 60)).toBe(false);
});
it('should correctly compare an after date inside tolerance', (): void => {
const aDate = new Date('2022-09-09T13:00:00');
const otherDate = new Date('2022-09-09T12:59:42');
expect(isDateEqualTo(aDate, otherDate, 60)).toBe(true);
});
it('should correctly compare an exactly equal date', (): void => {
const aDate = new Date('2022-09-09T13:00:00');
const otherDate = new Date('2022-09-09T13:00:00');
expect(isDateEqualTo(aDate, otherDate, 60)).toBe(true);
});
});
describe('date comparison with tolerances', (): void => {
it('should correctly compare a before date outside tolerance', (): void => {
const aDate = new Date('2022-09-09T13:00:00');
const otherDate = new Date('2022-09-09T14:00:00');
expect(isDateMoreRecentThan(aDate, otherDate)).toBe(false);
});
it('should correctly compare a before date inside tolerance', (): void => {
const aDate = new Date('2022-09-09T13:00:00');
const otherDate = new Date('2022-09-09T13:00:42');
expect(isDateMoreRecentThan(aDate, otherDate, 60)).toBe(false); // considered equal here
});
it('should correctly compare an after date outside tolerance', (): void => {
const aDate = new Date('2022-09-09T13:00:00');
const otherDate = new Date('2022-09-09T12:00:00');
expect(isDateMoreRecentThan(aDate, otherDate, 60)).toBe(true);
});
it('should correctly compare an after date inside tolerance', (): void => {
const aDate = new Date('2022-09-09T13:00:00');
const otherDate = new Date('2022-09-09T12:59:42');
expect(isDateMoreRecentThan(aDate, otherDate, 60)).toBe(false); // considered equal here
});
it('should correctly compare an exactly equal date', (): void => {
const aDate = new Date('2022-09-09T13:00:00');
const otherDate = new Date('2022-09-09T13:00:00');
expect(isDateMoreRecentThan(aDate, otherDate, 60)).toBe(false);
});
});
});

View File

@@ -1,31 +1,6 @@
/// returns false if the dates are equal within the `equalityToleranceInSeconds` number of seconds
/// otherwise returns true if `comparedDate` is after `date`
export function isDateMoreRecentThan(
date: Readonly<Date>,
comparedDate: Readonly<Date>,
equalityToleranceInSeconds = 0
comparedDate: Readonly<Date>
): boolean {
if (equalityToleranceInSeconds > 0) {
const areDatesEqual = isDateEqualTo(
date,
comparedDate,
equalityToleranceInSeconds
);
return !areDatesEqual && date > comparedDate;
}
return date > comparedDate;
}
export function isDateEqualTo(
date: Date,
otherDate: Date,
toleranceInSeconds: number
): boolean {
const timestamp = date.getTime();
const otherTimestamp = otherDate.getTime();
const deltaInSeconds = Math.abs(timestamp - otherTimestamp) / 1000;
return deltaInSeconds <= toleranceInSeconds;
}

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

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -28,11 +28,11 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
stalePrMessage: core.getInput('stale-pr-message'),
closeIssueMessage: core.getInput('close-issue-message'),
closePrMessage: core.getInput('close-pr-message'),
daysBeforeStale: parseFloat(
daysBeforeStale: parseInt(
core.getInput('days-before-stale', {required: true})
),
daysBeforeIssueStale: parseFloat(core.getInput('days-before-issue-stale')),
daysBeforePrStale: parseFloat(core.getInput('days-before-pr-stale')),
daysBeforeIssueStale: parseInt(core.getInput('days-before-issue-stale')),
daysBeforePrStale: parseInt(core.getInput('days-before-pr-stale')),
daysBeforeClose: parseInt(
core.getInput('days-before-close', {required: true})
),
@@ -57,10 +57,10 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
core.getInput('remove-stale-when-updated') === 'false'
),
removeIssueStaleWhenUpdated: _toOptionalBoolean(
'remove-issue-stale-when-updated'
core.getInput('remove-issue-stale-when-updated')
),
removePrStaleWhenUpdated: _toOptionalBoolean(
'remove-pr-stale-when-updated'
core.getInput('remove-pr-stale-when-updated')
),
debugOnly: core.getInput('debug-only') === 'true',
ascending: core.getInput('ascending') === 'true',
@@ -83,24 +83,14 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
exemptAllPrAssignees: _toOptionalBoolean('exempt-all-pr-assignees'),
enableStatistics: core.getInput('enable-statistics') === 'true',
labelsToRemoveWhenUnstale: core.getInput('labels-to-remove-when-unstale'),
labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale'),
ignoreUpdates: core.getInput('ignore-updates') === 'true',
ignoreIssueUpdates: _toOptionalBoolean('ignore-issue-updates'),
ignorePrUpdates: _toOptionalBoolean('ignore-pr-updates'),
exemptDraftPr: core.getInput('exempt-draft-pr') === 'true',
closeIssueReason: core.getInput('close-issue-reason'),
includeOnlyAssigned: core.getInput('include-only-assigned') === 'true'
labelsToAddWhenUnstale: core.getInput('labels-to-add-when-unstale')
};
for (const numberInput of ['days-before-stale']) {
if (isNaN(parseFloat(core.getInput(numberInput)))) {
const errorMessage = `Option "${numberInput}" did not parse to a valid float`;
core.setFailed(errorMessage);
throw new Error(errorMessage);
}
}
for (const numberInput of ['days-before-close', 'operations-per-run']) {
for (const numberInput of [
'days-before-stale',
'days-before-close',
'operations-per-run'
]) {
if (isNaN(parseInt(core.getInput(numberInput)))) {
const errorMessage = `Option "${numberInput}" did not parse to a valid integer`;
core.setFailed(errorMessage);
@@ -119,15 +109,6 @@ function _getAndValidateArgs(): IIssuesProcessorOptions {
}
}
const validCloseReasons = ['', 'completed', 'not_planned'];
if (!validCloseReasons.includes(args.closeIssueReason)) {
const errorMessage = `Unrecognized close-issue-reason "${
args.closeIssueReason
}", valid values are: ${validCloseReasons.filter(Boolean).join(', ')}`;
core.setFailed(errorMessage);
throw new Error(errorMessage);
}
return args;
}
@@ -139,17 +120,6 @@ async function processOutput(
core.setOutput('closed-issues-prs', JSON.stringify(closedIssues));
}
/**
* @description
* From an argument name, get the value as an optional boolean
* This is very useful for all the arguments that override others
* It will allow us to easily use the original one when the return value is `undefined`
* Which is different from `true` or `false` that consider the argument as set
*
* @param {Readonly<string>} argumentName The name of the argument to check
*
* @returns {boolean | undefined} The value matching the given argument name
*/
function _toOptionalBoolean(
argumentName: Readonly<string>
): boolean | undefined {