mirror of
https://github.com/actions/labeler.git
synced 2025-12-10 11:41:56 +00:00
Merge pull request #709 from actions/v5.0.0-beta
Transfer changes from beta version to main
This commit is contained in:
2
.github/workflows/basic-validation.yml
vendored
2
.github/workflows/basic-validation.yml
vendored
@@ -15,3 +15,5 @@ jobs:
|
||||
call-basic-validation:
|
||||
name: Basic validation
|
||||
uses: actions/reusable-workflows/.github/workflows/basic-validation.yml@main
|
||||
with:
|
||||
node-version: '20.x'
|
||||
|
||||
2
.github/workflows/check-dist.yml
vendored
2
.github/workflows/check-dist.yml
vendored
@@ -15,3 +15,5 @@ jobs:
|
||||
call-check-dist:
|
||||
name: Check dist/
|
||||
uses: actions/reusable-workflows/.github/workflows/check-dist.yml@main
|
||||
with:
|
||||
node-version: '20.x'
|
||||
|
||||
2
.licenses/npm/@actions/core.dep.yml
generated
2
.licenses/npm/@actions/core.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@actions/core"
|
||||
version: 1.10.0
|
||||
version: 1.10.1
|
||||
type: npm
|
||||
summary: Actions core lib
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/core
|
||||
|
||||
2
.licenses/npm/@actions/github.dep.yml
generated
2
.licenses/npm/@actions/github.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@actions/github"
|
||||
version: 5.1.1
|
||||
version: 6.0.0
|
||||
type: npm
|
||||
summary: Actions github lib
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/github
|
||||
|
||||
2
.licenses/npm/@actions/http-client.dep.yml
generated
2
.licenses/npm/@actions/http-client.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@actions/http-client"
|
||||
version: 2.0.1
|
||||
version: 2.2.0
|
||||
type: npm
|
||||
summary: Actions Http Client
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/http-client
|
||||
|
||||
@@ -1,22 +1,20 @@
|
||||
---
|
||||
name: "@octokit/request-error"
|
||||
version: 4.0.2
|
||||
name: "@fastify/busboy"
|
||||
version: 2.0.0
|
||||
type: npm
|
||||
summary: Error class for Octokit request errors
|
||||
summary: A streaming parser for HTML form data for node.js
|
||||
homepage:
|
||||
license: mit
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
text: |
|
||||
The MIT License
|
||||
|
||||
Copyright (c) 2019 Octokit contributors
|
||||
text: |-
|
||||
Copyright Brian White. All rights reserved.
|
||||
|
||||
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
|
||||
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
|
||||
@@ -26,9 +24,7 @@ licenses:
|
||||
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)"
|
||||
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: []
|
||||
2
.licenses/npm/@octokit/auth-token.dep.yml
generated
2
.licenses/npm/@octokit/auth-token.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@octokit/auth-token"
|
||||
version: 2.5.0
|
||||
version: 4.0.0
|
||||
type: npm
|
||||
summary: GitHub API token authentication for browsers and Node.js
|
||||
homepage:
|
||||
|
||||
2
.licenses/npm/@octokit/core.dep.yml
generated
2
.licenses/npm/@octokit/core.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@octokit/core"
|
||||
version: 3.6.0
|
||||
version: 5.0.1
|
||||
type: npm
|
||||
summary: Extendable client for GitHub's REST & GraphQL APIs
|
||||
homepage:
|
||||
|
||||
2
.licenses/npm/@octokit/endpoint.dep.yml
generated
2
.licenses/npm/@octokit/endpoint.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@octokit/endpoint"
|
||||
version: 6.0.12
|
||||
version: 9.0.1
|
||||
type: npm
|
||||
summary: Turns REST API endpoints into generic request options
|
||||
homepage:
|
||||
|
||||
2
.licenses/npm/@octokit/graphql.dep.yml
generated
2
.licenses/npm/@octokit/graphql.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@octokit/graphql"
|
||||
version: 4.8.0
|
||||
version: 7.0.2
|
||||
type: npm
|
||||
summary: GitHub GraphQL API client for browsers and Node
|
||||
homepage:
|
||||
|
||||
20
.licenses/npm/@octokit/openapi-types-12.11.0.dep.yml
generated
20
.licenses/npm/@octokit/openapi-types-12.11.0.dep.yml
generated
@@ -1,20 +0,0 @@
|
||||
---
|
||||
name: "@octokit/openapi-types"
|
||||
version: 12.11.0
|
||||
type: npm
|
||||
summary: Generated TypeScript definitions based on GitHub's OpenAPI spec for api.github.com
|
||||
homepage:
|
||||
license: mit
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
text: |-
|
||||
Copyright 2020 Gregor Martynus
|
||||
|
||||
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.
|
||||
- sources: README.md
|
||||
text: "[MIT](LICENSE)"
|
||||
notices: []
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@octokit/openapi-types"
|
||||
version: 18.0.0
|
||||
version: 19.0.1
|
||||
type: npm
|
||||
summary: Generated TypeScript definitions based on GitHub's OpenAPI spec for api.github.com
|
||||
homepage:
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@octokit/plugin-paginate-rest"
|
||||
version: 2.21.3
|
||||
version: 9.1.0
|
||||
type: npm
|
||||
summary: Octokit plugin to paginate REST API endpoint responses
|
||||
homepage:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@octokit/plugin-rest-endpoint-methods"
|
||||
version: 5.16.2
|
||||
version: 10.1.0
|
||||
type: npm
|
||||
summary: Octokit plugin adding one method for all of api.github.com REST API endpoints
|
||||
homepage:
|
||||
|
||||
2
.licenses/npm/@octokit/plugin-retry.dep.yml
generated
2
.licenses/npm/@octokit/plugin-retry.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@octokit/plugin-retry"
|
||||
version: 5.0.5
|
||||
version: 6.0.1
|
||||
type: npm
|
||||
summary: Automatic retry plugin for octokit
|
||||
homepage:
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@octokit/request-error"
|
||||
version: 2.1.0
|
||||
version: 5.0.1
|
||||
type: npm
|
||||
summary: Error class for Octokit request errors
|
||||
homepage:
|
||||
2
.licenses/npm/@octokit/request.dep.yml
generated
2
.licenses/npm/@octokit/request.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@octokit/request"
|
||||
version: 5.6.3
|
||||
version: 8.1.4
|
||||
type: npm
|
||||
summary: Send parameterized requests to GitHub's APIs with sensible defaults in browsers
|
||||
and Node
|
||||
|
||||
20
.licenses/npm/@octokit/types-6.41.0.dep.yml
generated
20
.licenses/npm/@octokit/types-6.41.0.dep.yml
generated
@@ -1,20 +0,0 @@
|
||||
---
|
||||
name: "@octokit/types"
|
||||
version: 6.41.0
|
||||
type: npm
|
||||
summary: Shared TypeScript definitions for Octokit projects
|
||||
homepage:
|
||||
license: mit
|
||||
licenses:
|
||||
- sources: LICENSE
|
||||
text: |
|
||||
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 (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: []
|
||||
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@octokit/types"
|
||||
version: 10.0.0
|
||||
version: 12.1.0
|
||||
type: npm
|
||||
summary: Shared TypeScript definitions for Octokit projects
|
||||
homepage:
|
||||
56
.licenses/npm/node-fetch.dep.yml
generated
56
.licenses/npm/node-fetch.dep.yml
generated
@@ -1,56 +0,0 @@
|
||||
---
|
||||
name: node-fetch
|
||||
version: 2.6.7
|
||||
type: npm
|
||||
summary: A light-weight module that brings window.fetch to node.js
|
||||
homepage: https://github.com/bitinn/node-fetch
|
||||
license: mit
|
||||
licenses:
|
||||
- sources: LICENSE.md
|
||||
text: |+
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2016 David Frank
|
||||
|
||||
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.
|
||||
|
||||
- sources: README.md
|
||||
text: |-
|
||||
MIT
|
||||
|
||||
[npm-image]: https://flat.badgen.net/npm/v/node-fetch
|
||||
[npm-url]: https://www.npmjs.com/package/node-fetch
|
||||
[travis-image]: https://flat.badgen.net/travis/bitinn/node-fetch
|
||||
[travis-url]: https://travis-ci.org/bitinn/node-fetch
|
||||
[codecov-image]: https://flat.badgen.net/codecov/c/github/bitinn/node-fetch/master
|
||||
[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
|
||||
[mdn-headers]: https://developer.mozilla.org/en-US/docs/Web/API/Headers
|
||||
[LIMITS.md]: https://github.com/bitinn/node-fetch/blob/master/LIMITS.md
|
||||
[ERROR-HANDLING.md]: https://github.com/bitinn/node-fetch/blob/master/ERROR-HANDLING.md
|
||||
[UPGRADE-GUIDE.md]: https://github.com/bitinn/node-fetch/blob/master/UPGRADE-GUIDE.md
|
||||
notices: []
|
||||
@@ -1,15 +1,17 @@
|
||||
---
|
||||
name: tr46
|
||||
version: 0.0.3
|
||||
name: undici
|
||||
version: 5.26.5
|
||||
type: npm
|
||||
summary: An implementation of the Unicode TR46 spec
|
||||
homepage: https://github.com/Sebmaster/tr46.js#readme
|
||||
summary: An HTTP/1.1 client, written from scratch for Node.js
|
||||
homepage: https://undici.nodejs.org
|
||||
license: mit
|
||||
licenses:
|
||||
- sources: Auto-generated MIT license text
|
||||
- sources: LICENSE
|
||||
text: |
|
||||
MIT License
|
||||
|
||||
Copyright (c) Matteo Collina and Undici 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
|
||||
@@ -27,4 +29,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
|
||||
notices: []
|
||||
23
.licenses/npm/webidl-conversions.dep.yml
generated
23
.licenses/npm/webidl-conversions.dep.yml
generated
@@ -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: []
|
||||
32
.licenses/npm/whatwg-url.dep.yml
generated
32
.licenses/npm/whatwg-url.dep.yml
generated
@@ -1,32 +0,0 @@
|
||||
---
|
||||
name: whatwg-url
|
||||
version: 5.0.0
|
||||
type: npm
|
||||
summary: An implementation of the WHATWG URL Standard's URL API and parsing machinery
|
||||
homepage:
|
||||
license: mit
|
||||
licenses:
|
||||
- sources: LICENSE.txt
|
||||
text: |
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015–2016 Sebastian Mayr
|
||||
|
||||
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: []
|
||||
216
README.md
216
README.md
@@ -2,99 +2,133 @@
|
||||
|
||||
[](https://github.com/actions/labeler/actions/workflows/basic-validation.yml)
|
||||
|
||||
Automatically label new pull requests based on the paths of files being changed.
|
||||
Automatically label new pull requests based on the paths of files being changed or the branch name.
|
||||
|
||||
## Breaking changes in V5
|
||||
1) The ability to apply labels based on the names of base and/or head branches was added ([#186](https://github.com/actions/labeler/issues/186) and [#54](https://github.com/actions/labeler/issues/54)). The match object for changed files was expanded with new combinations in order to make it more intuitive and flexible ([#423](https://github.com/actions/labeler/issues/423) and [#101](https://github.com/actions/labeler/issues/101)). As a result, the configuration file structure was significantly redesigned and is not compatible with the structure of the previous version. Please read the documentation below to find out how to adapt your configuration files for use with the new action version.
|
||||
|
||||
2) The bug related to the `sync-labels` input was fixed ([#112](https://github.com/actions/labeler/issues/112)). Now the input value is read correctly.
|
||||
|
||||
3) By default, `dot` input is set to `true`. Now, paths starting with a dot (e.g. `.github`) are matched by default.
|
||||
|
||||
4) Version 5 of this action updated the [runtime to Node.js 20](https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-javascript-actions). All scripts are now run with Node.js 20 instead of Node.js 16 and are affected by any breaking changes between Node.js 16 and 20.
|
||||
|
||||
## Usage
|
||||
|
||||
### Create `.github/labeler.yml`
|
||||
|
||||
Create a `.github/labeler.yml` file with a list of labels and [minimatch](https://github.com/isaacs/minimatch) globs to match to apply the label.
|
||||
Create a `.github/labeler.yml` file with a list of labels and config options to match and apply the label.
|
||||
|
||||
The key is the name of the label in your repository that you want to add (e.g. `merge conflict`, `needs-updating`) and the value is the path (glob) of the changed files (e.g. `src/**`, `tests/*.spec.js`) or a match object.
|
||||
The key is the name of the label in your repository that you want to add (eg: "merge conflict", "needs-updating") and the value is a match object.
|
||||
|
||||
#### Match Object
|
||||
|
||||
For more control over matching, you can provide a match object instead of a simple path glob. The match object is defined as:
|
||||
The match object allows control over the matching options. You can specify the label to be applied based on the files that have changed or the name of either the base branch or the head branch. For the changed files options you provide a [path glob](https://github.com/isaacs/minimatch#minimatch), and for the branches you provide a regexp to match against the branch name.
|
||||
|
||||
The base match object is defined as:
|
||||
```yml
|
||||
- any: ['list', 'of', 'globs']
|
||||
all: ['list', 'of', 'globs']
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['list', 'of', 'globs']
|
||||
- any-glob-to-all-files: ['list', 'of', 'globs']
|
||||
- all-globs-to-any-file: ['list', 'of', 'globs']
|
||||
- all-globs-to-all-files: ['list', 'of', 'globs']
|
||||
- base-branch: ['list', 'of', 'regexps']
|
||||
- head-branch: ['list', 'of', 'regexps']
|
||||
```
|
||||
|
||||
One or both fields can be provided for fine-grained matching. Unlike the top-level list, the list of path globs provided to `any` and `all` must ALL match against a path for the label to be applied.
|
||||
|
||||
The fields are defined as follows:
|
||||
* `any`: match ALL globs against ANY changed path
|
||||
* `all`: match ALL globs against ALL changed paths
|
||||
|
||||
A simple path glob is the equivalent to `any: ['glob']`. More specifically, the following two configurations are equivalent:
|
||||
There are two top-level keys, `any` and `all`, which both accept the same configuration options:
|
||||
```yml
|
||||
label1:
|
||||
- example1/*
|
||||
- any:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['list', 'of', 'globs']
|
||||
- any-glob-to-all-files: ['list', 'of', 'globs']
|
||||
- all-globs-to-any-file: ['list', 'of', 'globs']
|
||||
- all-globs-to-all-files: ['list', 'of', 'globs']
|
||||
- base-branch: ['list', 'of', 'regexps']
|
||||
- head-branch: ['list', 'of', 'regexps']
|
||||
- all:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['list', 'of', 'globs']
|
||||
- any-glob-to-all-files: ['list', 'of', 'globs']
|
||||
- all-globs-to-any-file: ['list', 'of', 'globs']
|
||||
- all-globs-to-all-files: ['list', 'of', 'globs']
|
||||
- base-branch: ['list', 'of', 'regexps']
|
||||
- head-branch: ['list', 'of', 'regexps']
|
||||
```
|
||||
|
||||
From a boolean logic perspective, top-level match objects, and options within `all` are `AND`-ed together and individual match rules within the `any` object are `OR`-ed.
|
||||
|
||||
One or all fields can be provided for fine-grained matching.
|
||||
The fields are defined as follows:
|
||||
- `all`: ALL of the provided options must match for the label to be applied
|
||||
- `any`: if ANY of the provided options match then the label will be applied
|
||||
- `base-branch`: match regexps against the base branch name
|
||||
- `head-branch`: match regexps against the head branch name
|
||||
- `changed-files`: match glob patterns against the changed paths
|
||||
- `any-glob-to-any-file`: ANY glob must match against ANY changed file
|
||||
- `any-glob-to-all-files`: ANY glob must match against ALL changed files
|
||||
- `all-globs-to-any-file`: ALL globs must match against ANY changed file
|
||||
- `all-globs-to-all-files`: ALL globs must match against ALL changed files
|
||||
|
||||
If a base option is provided without a top-level key, then it will default to `any`. More specifically, the following two configurations are equivalent:
|
||||
```yml
|
||||
Documentation:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: 'docs/*'
|
||||
```
|
||||
and
|
||||
```yml
|
||||
label1:
|
||||
- any: ['example1/*']
|
||||
Documentation:
|
||||
- any:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: 'docs/*'
|
||||
```
|
||||
|
||||
From a boolean logic perspective, top-level match objects are `OR`-ed together and individual match rules within an object are `AND`-ed. Combined with `!` negation, you can write complex matching rules.
|
||||
|
||||
> ⚠️ This action uses [minimatch](https://www.npmjs.com/package/minimatch) to apply glob patterns.
|
||||
> For historical reasons, paths starting with dot (e.g. `.github`) are not matched by default.
|
||||
> You need to set `dot: true` to change this behavior.
|
||||
> See [Inputs](#inputs) table below for details.
|
||||
If path globs are combined with `!` negation, you can write complex matching rules. See the examples below for more information.
|
||||
|
||||
#### Basic Examples
|
||||
|
||||
```yml
|
||||
# Add 'label1' to any changes within 'example' folder or any subfolders
|
||||
label1:
|
||||
- example/**
|
||||
# Add 'root' label to any root file changes
|
||||
# Quotation marks are required for the leading asterisk
|
||||
root:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: '*'
|
||||
|
||||
# Add 'label2' to any file changes within 'example2' folder
|
||||
label2: example2/*
|
||||
# Add 'AnyChange' label to any changes within the entire repository
|
||||
AnyChange:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: '**'
|
||||
|
||||
# Add label3 to any change to .txt files within the entire repository. Quotation marks are required for the leading asterisk
|
||||
label3:
|
||||
- '**/*.txt'
|
||||
# Add 'Documentation' label to any changes within 'docs' folder or any subfolders
|
||||
Documentation:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: docs/**
|
||||
|
||||
```
|
||||
# Add 'Documentation' label to any file changes within 'docs' folder
|
||||
Documentation:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: docs/*
|
||||
|
||||
#### Common Examples
|
||||
|
||||
```yml
|
||||
# Add 'repo' label to any root file changes
|
||||
repo:
|
||||
- '*'
|
||||
|
||||
# Add '@domain/core' label to any change within the 'core' package
|
||||
'@domain/core':
|
||||
- package/core/**
|
||||
|
||||
# Add 'test' label to any change to *.spec.js files within the source dir
|
||||
test:
|
||||
- src/**/*.spec.js
|
||||
# Add 'Documentation' label to any change to .md files within the entire repository
|
||||
Documentation:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: '**/*.md'
|
||||
|
||||
# Add 'source' label to any change to src files within the source dir EXCEPT for the docs sub-folder
|
||||
source:
|
||||
- any: ['src/**', '!src/docs/*']
|
||||
- all:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: 'src/**/*'
|
||||
- all-globs-to-all-files: '!src/docs/*'
|
||||
|
||||
# Add 'frontend` label to any change to *.js files as long as the `main.js` hasn't changed
|
||||
frontend:
|
||||
- any: ['src/**/*.js']
|
||||
all: ['!src/main.js']
|
||||
# Add 'feature' label to any PR where the head branch name starts with `feature` or has a `feature` section in the name
|
||||
feature:
|
||||
- head-branch: ['^feature', 'feature']
|
||||
|
||||
# Add the 'AnyChange' label to any changes within the entire repository if the 'dot' option is set to 'false'
|
||||
AnyChange:
|
||||
- '**'
|
||||
- '**/.*'
|
||||
- '**/.*/**'
|
||||
- '**/.*/**/.*'
|
||||
|
||||
# Add the 'AnyChange' label to any changes within the entire repository if the 'dot' option is set to 'true'
|
||||
AnyChange:
|
||||
- '**'
|
||||
# Add 'release' label to any PR that is opened against the `main` branch
|
||||
release:
|
||||
- base-branch: 'main'
|
||||
```
|
||||
|
||||
### Create Workflow
|
||||
@@ -107,13 +141,13 @@ on:
|
||||
- pull_request_target
|
||||
|
||||
jobs:
|
||||
triage:
|
||||
labeler:
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/labeler@v4
|
||||
- uses: actions/labeler@v5
|
||||
```
|
||||
|
||||
#### Inputs
|
||||
@@ -125,7 +159,7 @@ Various inputs are defined in [`action.yml`](action.yml) to let you configure th
|
||||
| `repo-token` | Token to use to authorize label changes. Typically the GITHUB_TOKEN secret | `github.token` |
|
||||
| `configuration-path` | The path to the label configuration file. If the file doesn't exist at the specified path on the runner, action will read from the source repository via the Github API. | `.github/labeler.yml` |
|
||||
| `sync-labels` | Whether or not to remove labels when matching files are reverted or no longer changed by the PR | `false` |
|
||||
| `dot` | Whether or not to auto-include paths starting with dot (e.g. `.github`) | `false` |
|
||||
| `dot` | Whether or not to auto-include paths starting with dot (e.g. `.github`) | `true` |
|
||||
| `pr-number` | The number(s) of pull request to update, rather than detecting from the workflow context | N/A |
|
||||
|
||||
##### Using `configuration-path` input together with the `@actions/checkout` action
|
||||
@@ -133,30 +167,16 @@ You might want to use action called [@actions/checkout](https://github.com/actio
|
||||
|
||||
```yml
|
||||
steps:
|
||||
- uses: actions/checkout@v3 # Uploads repository content to the runner
|
||||
- uses: actions/checkout@v4 # Uploads repository content to the runner
|
||||
with:
|
||||
repository: "owner/repositoryName" # The one of the available inputs, visit https://github.com/actions/checkout#readme to find more
|
||||
- uses: actions/labeler@v4
|
||||
- uses: actions/labeler@v5
|
||||
with:
|
||||
configuration-path: 'path/to/the/uploaded/configuration/file'
|
||||
|
||||
```
|
||||
|
||||
##### Peculiarities of using the `dot` input
|
||||
|
||||
When `dot` is disabled, and you want to include _all_ files in a folder:
|
||||
|
||||
```yml
|
||||
label1:
|
||||
- path/to/folder/**/*
|
||||
- path/to/folder/**/.*
|
||||
```
|
||||
|
||||
If `dot` is enabled:
|
||||
|
||||
```yml
|
||||
label1:
|
||||
- path/to/folder/**
|
||||
```
|
||||
|
||||
##### Example workflow specifying Pull request numbers
|
||||
##### Example workflow specifying pull request numbers
|
||||
|
||||
```yml
|
||||
name: "Label Previous Pull Requests"
|
||||
@@ -165,7 +185,7 @@ on:
|
||||
- cron: "0 1 * * 1"
|
||||
|
||||
jobs:
|
||||
triage:
|
||||
labeler:
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
@@ -173,7 +193,7 @@ jobs:
|
||||
steps:
|
||||
|
||||
# Label PRs 1, 2, and 3
|
||||
- uses: actions/labeler@v4
|
||||
- uses: actions/labeler@v5
|
||||
with:
|
||||
pr-number: |
|
||||
1
|
||||
@@ -183,7 +203,6 @@ jobs:
|
||||
|
||||
**Note:** in normal usage the `pr-number` input is not required as the action will detect the PR number from the workflow context.
|
||||
|
||||
|
||||
#### Outputs
|
||||
|
||||
Labeler provides the following outputs:
|
||||
@@ -195,19 +214,19 @@ Labeler provides the following outputs:
|
||||
|
||||
The following example performs steps based on the output of labeler:
|
||||
```yml
|
||||
name: "My workflow"
|
||||
name: "Pull Request Labeler"
|
||||
on:
|
||||
- pull_request_target
|
||||
|
||||
jobs:
|
||||
triage:
|
||||
labeler:
|
||||
permissions:
|
||||
contents: read
|
||||
pull-requests: write
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- id: label-the-PR
|
||||
uses: actions/labeler@v4
|
||||
uses: actions/labeler@v5
|
||||
|
||||
- id: run-frontend-tests
|
||||
if: contains(steps.label-the-PR.outputs.all-labels, 'frontend')
|
||||
@@ -224,21 +243,8 @@ jobs:
|
||||
|
||||
## Permissions
|
||||
|
||||
In order to add labels to pull requests, the GitHub labeler action requires
|
||||
write permissions on the pull-request. However, when the action runs on a pull
|
||||
request from a forked repository, GitHub only grants read access tokens for
|
||||
`pull_request` events, at most. If you encounter an `Error: HttpError: Resource
|
||||
not accessible by integration`, it's likely due to these permission constraints.
|
||||
To resolve this issue, you can modify the `on:` section of your workflow to use
|
||||
[`pull_request_target`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target)
|
||||
instead of `pull_request` (see example [above](#create-workflow)). This change
|
||||
allows the action to have write access, because `pull_request_target` alters the
|
||||
[context of the
|
||||
action](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target)
|
||||
and safely grants additional permissions. Refer to the [GitHub token
|
||||
permissions
|
||||
documentation](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token)
|
||||
for more details about access levels and event contexts.
|
||||
In order to add labels to pull requests, the GitHub labeler action requires write permissions on the pull-request. However, when the action runs on a pull request from a forked repository, GitHub only grants read access tokens for `pull_request` events, at most. If you encounter an `Error: HttpError: Resource not accessible by integration`, it's likely due to these permission constraints. To resolve this issue, you can modify the `on:` section of your workflow to use
|
||||
[`pull_request_target`](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) instead of `pull_request` (see example [above](#create-workflow)). This change allows the action to have write access, because `pull_request_target` alters the [context of the action](https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request_target) and safely grants additional permissions. Refer to the [GitHub token permissions documentation](https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token) for more details about access levels and event contexts.
|
||||
|
||||
## Contributions
|
||||
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
export const context = {
|
||||
payload: {
|
||||
pull_request: {
|
||||
number: 123
|
||||
number: 123,
|
||||
head: {
|
||||
ref: 'head-branch-name'
|
||||
},
|
||||
base: {
|
||||
ref: 'base-branch-name'
|
||||
}
|
||||
}
|
||||
},
|
||||
repo: {
|
||||
|
||||
210
__tests__/branch.test.ts
Normal file
210
__tests__/branch.test.ts
Normal file
@@ -0,0 +1,210 @@
|
||||
import {
|
||||
getBranchName,
|
||||
checkAnyBranch,
|
||||
checkAllBranch,
|
||||
toBranchMatchConfig,
|
||||
BranchMatchConfig
|
||||
} from '../src/branch';
|
||||
import * as github from '@actions/github';
|
||||
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/github');
|
||||
|
||||
describe('getBranchName', () => {
|
||||
describe('when the pull requests base branch is requested', () => {
|
||||
it('returns the base branch name', () => {
|
||||
const result = getBranchName('base');
|
||||
expect(result).toEqual('base-branch-name');
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the pull requests head branch is requested', () => {
|
||||
it('returns the head branch name', () => {
|
||||
const result = getBranchName('head');
|
||||
expect(result).toEqual('head-branch-name');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkAllBranch', () => {
|
||||
beforeEach(() => {
|
||||
github.context.payload.pull_request!.head = {
|
||||
ref: 'test/feature/123'
|
||||
};
|
||||
github.context.payload.pull_request!.base = {
|
||||
ref: 'main'
|
||||
};
|
||||
});
|
||||
|
||||
describe('when a single pattern is provided', () => {
|
||||
describe('and the pattern matches the head branch', () => {
|
||||
it('returns true', () => {
|
||||
const result = checkAllBranch(['^test'], 'head');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and the pattern does not match the head branch', () => {
|
||||
it('returns false', () => {
|
||||
const result = checkAllBranch(['^feature/'], 'head');
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when multiple patterns are provided', () => {
|
||||
describe('and not all patterns matched', () => {
|
||||
it('returns false', () => {
|
||||
const result = checkAllBranch(['^test/', '^feature/'], 'head');
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and all patterns match', () => {
|
||||
it('returns true', () => {
|
||||
const result = checkAllBranch(['^test/', '/feature/'], 'head');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and no patterns match', () => {
|
||||
it('returns false', () => {
|
||||
const result = checkAllBranch(['^feature/', '/test$'], 'head');
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the branch to check is specified as the base branch', () => {
|
||||
describe('and the pattern matches the base branch', () => {
|
||||
it('returns true', () => {
|
||||
const result = checkAllBranch(['^main$'], 'base');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkAnyBranch', () => {
|
||||
beforeEach(() => {
|
||||
github.context.payload.pull_request!.head = {
|
||||
ref: 'test/feature/123'
|
||||
};
|
||||
github.context.payload.pull_request!.base = {
|
||||
ref: 'main'
|
||||
};
|
||||
});
|
||||
|
||||
describe('when a single pattern is provided', () => {
|
||||
describe('and the pattern matches the head branch', () => {
|
||||
it('returns true', () => {
|
||||
const result = checkAnyBranch(['^test'], 'head');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and the pattern does not match the head branch', () => {
|
||||
it('returns false', () => {
|
||||
const result = checkAnyBranch(['^feature/'], 'head');
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when multiple patterns are provided', () => {
|
||||
describe('and at least one pattern matches', () => {
|
||||
it('returns true', () => {
|
||||
const result = checkAnyBranch(['^test/', '^feature/'], 'head');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and all patterns match', () => {
|
||||
it('returns true', () => {
|
||||
const result = checkAnyBranch(['^test/', '/feature/'], 'head');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and no patterns match', () => {
|
||||
it('returns false', () => {
|
||||
const result = checkAnyBranch(['^feature/', '/test$'], 'head');
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the branch to check is specified as the base branch', () => {
|
||||
describe('and the pattern matches the base branch', () => {
|
||||
it('returns true', () => {
|
||||
const result = checkAnyBranch(['^main$'], 'base');
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('toBranchMatchConfig', () => {
|
||||
describe('when there are no branch keys in the config', () => {
|
||||
const config = {'changed-files': [{any: ['testing']}]};
|
||||
|
||||
it('returns an empty object', () => {
|
||||
const result = toBranchMatchConfig(config);
|
||||
expect(result).toEqual({});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the config contains a head-branch option', () => {
|
||||
const config = {'head-branch': ['testing']};
|
||||
|
||||
it('sets headBranch in the matchConfig', () => {
|
||||
const result = toBranchMatchConfig(config);
|
||||
expect(result).toEqual<BranchMatchConfig>({
|
||||
headBranch: ['testing']
|
||||
});
|
||||
});
|
||||
|
||||
describe('and the matching option is a string', () => {
|
||||
const stringConfig = {'head-branch': 'testing'};
|
||||
|
||||
it('sets headBranch in the matchConfig', () => {
|
||||
const result = toBranchMatchConfig(stringConfig);
|
||||
expect(result).toEqual<BranchMatchConfig>({
|
||||
headBranch: ['testing']
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the config contains a base-branch option', () => {
|
||||
const config = {'base-branch': ['testing']};
|
||||
it('sets baseBranch in the matchConfig', () => {
|
||||
const result = toBranchMatchConfig(config);
|
||||
expect(result).toEqual<BranchMatchConfig>({
|
||||
baseBranch: ['testing']
|
||||
});
|
||||
});
|
||||
|
||||
describe('and the matching option is a string', () => {
|
||||
const stringConfig = {'base-branch': 'testing'};
|
||||
|
||||
it('sets baseBranch in the matchConfig', () => {
|
||||
const result = toBranchMatchConfig(stringConfig);
|
||||
expect(result).toEqual<BranchMatchConfig>({
|
||||
baseBranch: ['testing']
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('when the config contains both a base-branch and head-branch option', () => {
|
||||
const config = {'base-branch': ['testing'], 'head-branch': ['testing']};
|
||||
it('sets headBranch and baseBranch in the matchConfig', () => {
|
||||
const result = toBranchMatchConfig(config);
|
||||
expect(result).toEqual<BranchMatchConfig>({
|
||||
baseBranch: ['testing'],
|
||||
headBranch: ['testing']
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
270
__tests__/changedFiles.test.ts
Normal file
270
__tests__/changedFiles.test.ts
Normal file
@@ -0,0 +1,270 @@
|
||||
import {
|
||||
ChangedFilesMatchConfig,
|
||||
checkAllChangedFiles,
|
||||
checkAnyChangedFiles,
|
||||
toChangedFilesMatchConfig,
|
||||
checkIfAnyGlobMatchesAnyFile,
|
||||
checkIfAllGlobsMatchAnyFile,
|
||||
checkIfAnyGlobMatchesAllFiles,
|
||||
checkIfAllGlobsMatchAllFiles
|
||||
} from '../src/changedFiles';
|
||||
|
||||
jest.mock('@actions/core');
|
||||
jest.mock('@actions/github');
|
||||
|
||||
describe('checkAllChangedFiles', () => {
|
||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||
|
||||
describe('when all given glob pattern configs matched', () => {
|
||||
const globPatternsConfigs = [
|
||||
{anyGlobToAnyFile: ['foo.txt']},
|
||||
{anyGlobToAllFiles: ['*.txt']},
|
||||
{allGlobsToAllFiles: ['**']}
|
||||
];
|
||||
|
||||
it('returns true', () => {
|
||||
const result = checkAllChangedFiles(
|
||||
changedFiles,
|
||||
globPatternsConfigs,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe(`when some given glob pattern config did not match`, () => {
|
||||
const globPatternsConfigs = [
|
||||
{anyGlobToAnyFile: ['*.md']},
|
||||
{anyGlobToAllFiles: ['*.txt']},
|
||||
{allGlobsToAllFiles: ['**']}
|
||||
];
|
||||
|
||||
it('returns false', () => {
|
||||
const result = checkAllChangedFiles(
|
||||
changedFiles,
|
||||
globPatternsConfigs,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkAnyChangedFiles', () => {
|
||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||
|
||||
describe('when any given glob pattern config matched', () => {
|
||||
const globPatternsConfigs = [
|
||||
{anyGlobToAnyFile: ['*.md']},
|
||||
{anyGlobToAllFiles: ['*.txt']}
|
||||
];
|
||||
|
||||
it('returns true', () => {
|
||||
const result = checkAnyChangedFiles(
|
||||
changedFiles,
|
||||
globPatternsConfigs,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when none of the given glob pattern configs matched', () => {
|
||||
const globPatternsConfigs = [
|
||||
{anyGlobToAnyFile: ['*.md']},
|
||||
{anyGlobToAllFiles: ['!*.txt']}
|
||||
];
|
||||
|
||||
it('returns false', () => {
|
||||
const result = checkAnyChangedFiles(
|
||||
changedFiles,
|
||||
globPatternsConfigs,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('toChangedFilesMatchConfig', () => {
|
||||
describe(`when there is no 'changed-files' key in the config`, () => {
|
||||
const config = {'head-branch': 'test'};
|
||||
|
||||
it('returns an empty object', () => {
|
||||
const result = toChangedFilesMatchConfig(config);
|
||||
expect(result).toEqual<ChangedFilesMatchConfig>({});
|
||||
});
|
||||
});
|
||||
|
||||
describe(`when there is a 'changed-files' key in the config`, () => {
|
||||
describe('but the glob pattern config key is not provided', () => {
|
||||
const config = {'changed-files': ['bar']};
|
||||
|
||||
it('throws the error', () => {
|
||||
expect(() => {
|
||||
toChangedFilesMatchConfig(config);
|
||||
}).toThrow(
|
||||
`The "changed-files" section must have a valid config structure. Please read the action documentation for more information`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('but the glob pattern config key is not valid', () => {
|
||||
const config = {'changed-files': [{NotValidConfigKey: ['bar']}]};
|
||||
|
||||
it('throws the error', () => {
|
||||
expect(() => {
|
||||
toChangedFilesMatchConfig(config);
|
||||
}).toThrow(
|
||||
`Unknown config options were under "changed-files": NotValidConfigKey`
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('and the glob pattern config key is provided', () => {
|
||||
describe('and the value is an array of strings', () => {
|
||||
const config = {
|
||||
'changed-files': [{'any-glob-to-any-file': ['testing']}]
|
||||
};
|
||||
|
||||
it('sets the value in the config object', () => {
|
||||
const result = toChangedFilesMatchConfig(config);
|
||||
expect(result).toEqual<ChangedFilesMatchConfig>({
|
||||
changedFiles: [{anyGlobToAnyFile: ['testing']}]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('and the value is a string', () => {
|
||||
const config = {'changed-files': [{'any-glob-to-any-file': 'testing'}]};
|
||||
|
||||
it(`sets the string as an array in the config object`, () => {
|
||||
const result = toChangedFilesMatchConfig(config);
|
||||
expect(result).toEqual<ChangedFilesMatchConfig>({
|
||||
changedFiles: [{anyGlobToAnyFile: ['testing']}]
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkIfAnyGlobMatchesAnyFile', () => {
|
||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||
|
||||
describe('when any given glob pattern matched any file', () => {
|
||||
const globPatterns = ['*.md', 'foo.txt'];
|
||||
|
||||
it('returns true', () => {
|
||||
const result = checkIfAnyGlobMatchesAnyFile(
|
||||
changedFiles,
|
||||
globPatterns,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when none of the given glob pattern matched any file', () => {
|
||||
const globPatterns = ['*.md', '!*.txt'];
|
||||
|
||||
it('returns false', () => {
|
||||
const result = checkIfAnyGlobMatchesAnyFile(
|
||||
changedFiles,
|
||||
globPatterns,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkIfAllGlobsMatchAnyFile', () => {
|
||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||
|
||||
describe('when all given glob patterns matched any file', () => {
|
||||
const globPatterns = ['**/bar.txt', 'bar.txt'];
|
||||
|
||||
it('returns true', () => {
|
||||
const result = checkIfAllGlobsMatchAnyFile(
|
||||
changedFiles,
|
||||
globPatterns,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when some of the given glob patterns did not match any file', () => {
|
||||
const globPatterns = ['*.txt', '*.md'];
|
||||
|
||||
it('returns false', () => {
|
||||
const result = checkIfAllGlobsMatchAnyFile(
|
||||
changedFiles,
|
||||
globPatterns,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkIfAnyGlobMatchesAllFiles', () => {
|
||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||
|
||||
describe('when any given glob pattern matched all files', () => {
|
||||
const globPatterns = ['*.md', '*.txt'];
|
||||
|
||||
it('returns true', () => {
|
||||
const result = checkIfAnyGlobMatchesAllFiles(
|
||||
changedFiles,
|
||||
globPatterns,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when none of the given glob patterns matched all files', () => {
|
||||
const globPatterns = ['*.md', 'bar.txt', 'foo.txt'];
|
||||
|
||||
it('returns false', () => {
|
||||
const result = checkIfAnyGlobMatchesAllFiles(
|
||||
changedFiles,
|
||||
globPatterns,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkIfAllGlobsMatchAllFiles', () => {
|
||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||
|
||||
describe('when all given glob patterns matched all files', () => {
|
||||
const globPatterns = ['*.txt', '**'];
|
||||
|
||||
it('returns true', () => {
|
||||
const result = checkIfAllGlobsMatchAllFiles(
|
||||
changedFiles,
|
||||
globPatterns,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when some of the given glob patterns did not match all files', () => {
|
||||
const globPatterns = ['**', 'foo.txt'];
|
||||
|
||||
it('returns false', () => {
|
||||
const result = checkIfAllGlobsMatchAllFiles(
|
||||
changedFiles,
|
||||
globPatterns,
|
||||
false
|
||||
);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
17
__tests__/fixtures/all_options.yml
Normal file
17
__tests__/fixtures/all_options.yml
Normal file
@@ -0,0 +1,17 @@
|
||||
label1:
|
||||
- any:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['glob']
|
||||
- head-branch: ['regexp']
|
||||
- base-branch: ['regexp']
|
||||
- all:
|
||||
- changed-files:
|
||||
- all-globs-to-all-files: ['glob']
|
||||
- head-branch: ['regexp']
|
||||
- base-branch: ['regexp']
|
||||
|
||||
label2:
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['glob']
|
||||
- head-branch: ['regexp']
|
||||
- base-branch: ['regexp']
|
||||
8
__tests__/fixtures/any_and_all.yml
Normal file
8
__tests__/fixtures/any_and_all.yml
Normal file
@@ -0,0 +1,8 @@
|
||||
tests:
|
||||
- any:
|
||||
- head-branch: ['^tests/', '^test/']
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['tests/**/*']
|
||||
- all:
|
||||
- changed-files:
|
||||
- all-globs-to-all-files: ['!tests/requirements.txt']
|
||||
11
__tests__/fixtures/branches.yml
Normal file
11
__tests__/fixtures/branches.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
test-branch:
|
||||
- head-branch: '^test/'
|
||||
|
||||
feature-branch:
|
||||
- head-branch: '/feature/'
|
||||
|
||||
bug-branch:
|
||||
- head-branch: '^bug/|fix/'
|
||||
|
||||
array-branch:
|
||||
- head-branch: ['^array/']
|
||||
3
__tests__/fixtures/not_supported.yml
Normal file
3
__tests__/fixtures/not_supported.yml
Normal file
@@ -0,0 +1,3 @@
|
||||
label:
|
||||
- all:
|
||||
- unknown: 'this-is-not-supported'
|
||||
@@ -1,2 +1,3 @@
|
||||
touched-a-pdf-file:
|
||||
- any: ['*.pdf']
|
||||
- changed-files:
|
||||
- any-glob-to-any-file: ['*.pdf']
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
import {checkGlobs} from '../src/labeler';
|
||||
|
||||
import * as yaml from 'js-yaml';
|
||||
import * as core from '@actions/core';
|
||||
import * as fs from 'fs';
|
||||
import {checkMatchConfigs} from '../src/labeler';
|
||||
import {
|
||||
MatchConfig,
|
||||
toMatchConfig,
|
||||
getLabelConfigMapFromObject,
|
||||
BaseMatchConfig
|
||||
} from '../src/api/get-label-configs';
|
||||
|
||||
jest.mock('@actions/core');
|
||||
|
||||
@@ -10,34 +17,145 @@ beforeAll(() => {
|
||||
});
|
||||
});
|
||||
|
||||
const matchConfig = [{any: ['*.txt']}];
|
||||
const loadYaml = (filepath: string) => {
|
||||
const loadedFile = fs.readFileSync(filepath);
|
||||
const content = Buffer.from(loadedFile).toString();
|
||||
return yaml.load(content);
|
||||
};
|
||||
|
||||
describe('getLabelConfigMapFromObject', () => {
|
||||
const yamlObject = loadYaml('__tests__/fixtures/all_options.yml');
|
||||
const expected = new Map<string, MatchConfig[]>();
|
||||
expected.set('label1', [
|
||||
{
|
||||
any: [
|
||||
{changedFiles: [{anyGlobToAnyFile: ['glob']}]},
|
||||
{baseBranch: undefined, headBranch: ['regexp']},
|
||||
{baseBranch: ['regexp'], headBranch: undefined}
|
||||
]
|
||||
},
|
||||
{
|
||||
all: [
|
||||
{changedFiles: [{allGlobsToAllFiles: ['glob']}]},
|
||||
{baseBranch: undefined, headBranch: ['regexp']},
|
||||
{baseBranch: ['regexp'], headBranch: undefined}
|
||||
]
|
||||
}
|
||||
]);
|
||||
expected.set('label2', [
|
||||
{
|
||||
any: [
|
||||
{changedFiles: [{anyGlobToAnyFile: ['glob']}]},
|
||||
{baseBranch: undefined, headBranch: ['regexp']},
|
||||
{baseBranch: ['regexp'], headBranch: undefined}
|
||||
]
|
||||
}
|
||||
]);
|
||||
|
||||
it('returns a MatchConfig', () => {
|
||||
const result = getLabelConfigMapFromObject(yamlObject);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('toMatchConfig', () => {
|
||||
describe('when all expected config options are present', () => {
|
||||
const config = {
|
||||
'changed-files': [{'any-glob-to-any-file': ['testing-files']}],
|
||||
'head-branch': ['testing-head'],
|
||||
'base-branch': ['testing-base']
|
||||
};
|
||||
const expected: BaseMatchConfig = {
|
||||
changedFiles: [{anyGlobToAnyFile: ['testing-files']}],
|
||||
headBranch: ['testing-head'],
|
||||
baseBranch: ['testing-base']
|
||||
};
|
||||
|
||||
it('returns a MatchConfig object with all options', () => {
|
||||
const result = toMatchConfig(config);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
|
||||
describe('and there are also unexpected options present', () => {
|
||||
config['test-test'] = 'testing';
|
||||
|
||||
it('does not include the unexpected items in the returned MatchConfig object', () => {
|
||||
const result = toMatchConfig(config);
|
||||
expect(result).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('checkMatchConfigs', () => {
|
||||
describe('when a single match config is provided', () => {
|
||||
const matchConfig: MatchConfig[] = [
|
||||
{any: [{changedFiles: [{anyGlobToAnyFile: ['*.txt']}]}]}
|
||||
];
|
||||
|
||||
describe('checkGlobs', () => {
|
||||
it('returns true when our pattern does match changed files', () => {
|
||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||
const result = checkGlobs(changedFiles, matchConfig, false);
|
||||
const result = checkMatchConfigs(changedFiles, matchConfig, false);
|
||||
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
|
||||
it('returns false when our pattern does not match changed files', () => {
|
||||
const changedFiles = ['foo.docx'];
|
||||
const result = checkGlobs(changedFiles, matchConfig, false);
|
||||
const result = checkMatchConfigs(changedFiles, matchConfig, false);
|
||||
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
it('returns true when either the branch or changed files patter matches', () => {
|
||||
const matchConfig: MatchConfig[] = [
|
||||
{
|
||||
any: [
|
||||
{changedFiles: [{anyGlobToAnyFile: ['*.txt']}]},
|
||||
{headBranch: ['some-branch']}
|
||||
]
|
||||
}
|
||||
];
|
||||
const changedFiles = ['foo.txt', 'bar.txt'];
|
||||
|
||||
const result = checkMatchConfigs(changedFiles, matchConfig, false);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
|
||||
it('returns false for a file starting with dot if `dot` option is false', () => {
|
||||
const changedFiles = ['.foo.txt'];
|
||||
const result = checkGlobs(changedFiles, matchConfig, false);
|
||||
const result = checkMatchConfigs(changedFiles, matchConfig, false);
|
||||
|
||||
expect(result).toBeFalsy();
|
||||
});
|
||||
|
||||
it('returns true for a file starting with dot if `dot` option is true', () => {
|
||||
const changedFiles = ['.foo.txt'];
|
||||
const result = checkGlobs(changedFiles, matchConfig, true);
|
||||
const result = checkMatchConfigs(changedFiles, matchConfig, true);
|
||||
|
||||
expect(result).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when multiple MatchConfigs are supplied', () => {
|
||||
const matchConfig: MatchConfig[] = [
|
||||
{any: [{changedFiles: [{anyGlobToAnyFile: ['*.txt']}]}]},
|
||||
{any: [{headBranch: ['some-branch']}]}
|
||||
];
|
||||
const changedFiles = ['foo.txt', 'bar.md'];
|
||||
|
||||
it('returns false when only one config matches', () => {
|
||||
const result = checkMatchConfigs(changedFiles, matchConfig, false);
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
|
||||
it('returns true when only both config matches', () => {
|
||||
const matchConfig: MatchConfig[] = [
|
||||
{any: [{changedFiles: [{anyGlobToAnyFile: ['*.txt']}]}]},
|
||||
{any: [{headBranch: ['head-branch']}]}
|
||||
];
|
||||
const result = checkMatchConfigs(changedFiles, matchConfig, false);
|
||||
expect(result).toBe(true);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -34,7 +34,10 @@ class NotFound extends Error {
|
||||
}
|
||||
|
||||
const yamlFixtures = {
|
||||
'only_pdfs.yml': fs.readFileSync('__tests__/fixtures/only_pdfs.yml')
|
||||
'branches.yml': fs.readFileSync('__tests__/fixtures/branches.yml'),
|
||||
'only_pdfs.yml': fs.readFileSync('__tests__/fixtures/only_pdfs.yml'),
|
||||
'not_supported.yml': fs.readFileSync('__tests__/fixtures/not_supported.yml'),
|
||||
'any_and_all.yml': fs.readFileSync('__tests__/fixtures/any_and_all.yml')
|
||||
};
|
||||
|
||||
const configureInput = (
|
||||
@@ -146,6 +149,121 @@ describe('run', () => {
|
||||
expect(setLabelsMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('does not add a label when the match config options are not supported', async () => {
|
||||
configureInput({});
|
||||
usingLabelerConfigYaml('not_supported.yml');
|
||||
await run();
|
||||
|
||||
expect(setLabelsMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('adds labels based on the branch names that match the regexp pattern', async () => {
|
||||
configureInput({});
|
||||
github.context.payload.pull_request!.head = {ref: 'test/testing-time'};
|
||||
usingLabelerConfigYaml('branches.yml');
|
||||
await run();
|
||||
|
||||
expect(setLabelsMock).toHaveBeenCalledTimes(1);
|
||||
expect(setLabelsMock).toHaveBeenCalledWith({
|
||||
owner: 'monalisa',
|
||||
repo: 'helloworld',
|
||||
issue_number: 123,
|
||||
labels: ['test-branch']
|
||||
});
|
||||
|
||||
expect(setOutputSpy).toHaveBeenCalledWith('new-labels', 'test-branch');
|
||||
expect(setOutputSpy).toHaveBeenCalledWith('all-labels', 'test-branch');
|
||||
});
|
||||
|
||||
it('adds multiple labels based on branch names that match different regexp patterns', async () => {
|
||||
configureInput({});
|
||||
github.context.payload.pull_request!.head = {
|
||||
ref: 'test/feature/123'
|
||||
};
|
||||
usingLabelerConfigYaml('branches.yml');
|
||||
await run();
|
||||
|
||||
expect(setLabelsMock).toHaveBeenCalledTimes(1);
|
||||
expect(setLabelsMock).toHaveBeenCalledWith({
|
||||
owner: 'monalisa',
|
||||
repo: 'helloworld',
|
||||
issue_number: 123,
|
||||
labels: ['test-branch', 'feature-branch']
|
||||
});
|
||||
|
||||
expect(setOutputSpy).toHaveBeenCalledWith(
|
||||
'new-labels',
|
||||
'test-branch,feature-branch'
|
||||
);
|
||||
expect(setOutputSpy).toHaveBeenCalledWith(
|
||||
'all-labels',
|
||||
'test-branch,feature-branch'
|
||||
);
|
||||
});
|
||||
|
||||
it('can support multiple branches by batching', async () => {
|
||||
configureInput({});
|
||||
github.context.payload.pull_request!.head = {ref: 'fix/123'};
|
||||
usingLabelerConfigYaml('branches.yml');
|
||||
await run();
|
||||
|
||||
expect(setLabelsMock).toHaveBeenCalledTimes(1);
|
||||
expect(setLabelsMock).toHaveBeenCalledWith({
|
||||
owner: 'monalisa',
|
||||
repo: 'helloworld',
|
||||
issue_number: 123,
|
||||
labels: ['bug-branch']
|
||||
});
|
||||
|
||||
expect(setOutputSpy).toHaveBeenCalledWith('new-labels', 'bug-branch');
|
||||
expect(setOutputSpy).toHaveBeenCalledWith('all-labels', 'bug-branch');
|
||||
});
|
||||
|
||||
it('can support multiple branches by providing an array', async () => {
|
||||
configureInput({});
|
||||
github.context.payload.pull_request!.head = {ref: 'array/123'};
|
||||
usingLabelerConfigYaml('branches.yml');
|
||||
await run();
|
||||
|
||||
expect(setLabelsMock).toHaveBeenCalledTimes(1);
|
||||
expect(setLabelsMock).toHaveBeenCalledWith({
|
||||
owner: 'monalisa',
|
||||
repo: 'helloworld',
|
||||
issue_number: 123,
|
||||
labels: ['array-branch']
|
||||
});
|
||||
|
||||
expect(setOutputSpy).toHaveBeenCalledWith('new-labels', 'array-branch');
|
||||
expect(setOutputSpy).toHaveBeenCalledWith('all-labels', 'array-branch');
|
||||
});
|
||||
|
||||
it('adds a label when matching any and all patterns are provided', async () => {
|
||||
configureInput({});
|
||||
usingLabelerConfigYaml('any_and_all.yml');
|
||||
mockGitHubResponseChangedFiles('tests/test.ts');
|
||||
await run();
|
||||
|
||||
expect(setLabelsMock).toHaveBeenCalledTimes(1);
|
||||
expect(setLabelsMock).toHaveBeenCalledWith({
|
||||
owner: 'monalisa',
|
||||
repo: 'helloworld',
|
||||
issue_number: 123,
|
||||
labels: ['tests']
|
||||
});
|
||||
|
||||
expect(setOutputSpy).toHaveBeenCalledWith('new-labels', 'tests');
|
||||
expect(setOutputSpy).toHaveBeenCalledWith('all-labels', 'tests');
|
||||
});
|
||||
|
||||
it('does not add a label when not all any and all patterns are matched', async () => {
|
||||
configureInput({});
|
||||
usingLabelerConfigYaml('any_and_all.yml');
|
||||
mockGitHubResponseChangedFiles('tests/requirements.txt');
|
||||
await run();
|
||||
|
||||
expect(setLabelsMock).toHaveBeenCalledTimes(0);
|
||||
});
|
||||
|
||||
it('(with sync-labels: true) it deletes preexisting PR labels that no longer match the glob pattern', async () => {
|
||||
configureInput({
|
||||
'repo-token': 'foo',
|
||||
@@ -170,6 +288,7 @@ describe('run', () => {
|
||||
issue_number: 123,
|
||||
labels: ['manually-added']
|
||||
});
|
||||
|
||||
expect(setOutputSpy).toHaveBeenCalledWith('new-labels', '');
|
||||
expect(setOutputSpy).toHaveBeenCalledWith('all-labels', 'manually-added');
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ inputs:
|
||||
required: false
|
||||
dot:
|
||||
description: 'Whether or not to auto-include paths starting with dot (e.g. `.github`)'
|
||||
default: false
|
||||
default: true
|
||||
required: false
|
||||
pr-number:
|
||||
description: 'The pull request number(s)'
|
||||
@@ -28,5 +28,5 @@ outputs:
|
||||
all-labels:
|
||||
description: 'A comma-separated list of all labels that the PR contains'
|
||||
runs:
|
||||
using: 'node16'
|
||||
using: 'node20'
|
||||
main: 'dist/index.js'
|
||||
|
||||
31161
dist/index.js
vendored
31161
dist/index.js
vendored
File diff suppressed because one or more lines are too long
8555
package-lock.json
generated
8555
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
20
package.json
20
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "labeler",
|
||||
"version": "4.1.0",
|
||||
"version": "5.0.0",
|
||||
"description": "Labels pull requests by files altered",
|
||||
"main": "lib/main.js",
|
||||
"scripts": {
|
||||
@@ -25,28 +25,28 @@
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.0",
|
||||
"@actions/github": "^5.1.1",
|
||||
"@octokit/plugin-retry": "^5.0.5",
|
||||
"@actions/github": "^6.0.0",
|
||||
"@octokit/plugin-retry": "^6.0.0",
|
||||
"js-yaml": "^4.1.0",
|
||||
"lodash.isequal": "^4.5.0",
|
||||
"minimatch": "^9.0.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "^27.4.1",
|
||||
"@types/jest": "^29.5.6",
|
||||
"@types/js-yaml": "^4.0.6",
|
||||
"@types/lodash.isequal": "^4.5.6",
|
||||
"@types/minimatch": "^5.1.2",
|
||||
"@types/node": "^16.11.7",
|
||||
"@types/node": "^20.8.8",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
||||
"@typescript-eslint/parser": "^6.7.2",
|
||||
"@vercel/ncc": "^0.36.1",
|
||||
"@vercel/ncc": "^0.38.1",
|
||||
"eslint": "^8.51.0",
|
||||
"eslint-config-prettier": "^8.10.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-jest": "^27.4.2",
|
||||
"eslint-plugin-node": "^11.1.0",
|
||||
"jest": "^27.5.1",
|
||||
"jest": "^29.7.0",
|
||||
"prettier": "^3.0.3",
|
||||
"ts-jest": "^27.1.3",
|
||||
"typescript": "^4.9.5"
|
||||
"ts-jest": "^29.1.1",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
126
src/api/get-label-configs.ts
Normal file
126
src/api/get-label-configs.ts
Normal file
@@ -0,0 +1,126 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as yaml from 'js-yaml';
|
||||
import fs from 'fs';
|
||||
import {ClientType} from './types';
|
||||
import {getContent} from './get-content';
|
||||
|
||||
import {
|
||||
ChangedFilesMatchConfig,
|
||||
toChangedFilesMatchConfig
|
||||
} from '../changedFiles';
|
||||
|
||||
import {toBranchMatchConfig, BranchMatchConfig} from '../branch';
|
||||
|
||||
export interface MatchConfig {
|
||||
all?: BaseMatchConfig[];
|
||||
any?: BaseMatchConfig[];
|
||||
}
|
||||
|
||||
export type BaseMatchConfig = BranchMatchConfig & ChangedFilesMatchConfig;
|
||||
|
||||
const ALLOWED_CONFIG_KEYS = ['changed-files', 'head-branch', 'base-branch'];
|
||||
|
||||
export const getLabelConfigs = (
|
||||
client: ClientType,
|
||||
configurationPath: string
|
||||
): Promise<Map<string, MatchConfig[]>> =>
|
||||
Promise.resolve()
|
||||
.then(() => {
|
||||
if (!fs.existsSync(configurationPath)) {
|
||||
core.info(
|
||||
`The configuration file (path: ${configurationPath}) was not found locally, fetching via the api`
|
||||
);
|
||||
|
||||
return getContent(client, configurationPath);
|
||||
}
|
||||
|
||||
core.info(
|
||||
`The configuration file (path: ${configurationPath}) was found locally, reading from the file`
|
||||
);
|
||||
|
||||
return fs.readFileSync(configurationPath, {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.name == 'HttpError' || error.name == 'NotFound') {
|
||||
core.warning(
|
||||
`The config file was not found at ${configurationPath}. Make sure it exists and that this action has the correct access rights.`
|
||||
);
|
||||
}
|
||||
return Promise.reject(error);
|
||||
})
|
||||
.then(configuration => {
|
||||
// loads (hopefully) a `{[label:string]: MatchConfig[]}`, but is `any`:
|
||||
const configObject: any = yaml.load(configuration);
|
||||
|
||||
// transform `any` => `Map<string,MatchConfig[]>` or throw if yaml is malformed:
|
||||
return getLabelConfigMapFromObject(configObject);
|
||||
});
|
||||
|
||||
export function getLabelConfigMapFromObject(
|
||||
configObject: any
|
||||
): Map<string, MatchConfig[]> {
|
||||
const labelMap: Map<string, MatchConfig[]> = new Map();
|
||||
for (const label in configObject) {
|
||||
const configOptions = configObject[label];
|
||||
if (
|
||||
!Array.isArray(configOptions) ||
|
||||
!configOptions.every(opts => typeof opts === 'object')
|
||||
) {
|
||||
throw Error(
|
||||
`found unexpected type for label '${label}' (should be array of config options)`
|
||||
);
|
||||
}
|
||||
const matchConfigs = configOptions.reduce<MatchConfig[]>(
|
||||
(updatedConfig, configValue) => {
|
||||
if (!configValue) {
|
||||
return updatedConfig;
|
||||
}
|
||||
|
||||
Object.entries(configValue).forEach(([key, value]) => {
|
||||
// If the top level `any` or `all` keys are provided then set them, and convert their values to
|
||||
// our config objects.
|
||||
if (key === 'any' || key === 'all') {
|
||||
if (Array.isArray(value)) {
|
||||
const newConfigs = value.map(toMatchConfig);
|
||||
updatedConfig.push({[key]: newConfigs});
|
||||
}
|
||||
} else if (ALLOWED_CONFIG_KEYS.includes(key)) {
|
||||
const newMatchConfig = toMatchConfig({[key]: value});
|
||||
// Find or set the `any` key so that we can add these properties to that rule,
|
||||
// Or create a new `any` key and add that to our array of configs.
|
||||
const indexOfAny = updatedConfig.findIndex(mc => !!mc['any']);
|
||||
if (indexOfAny >= 0) {
|
||||
updatedConfig[indexOfAny].any?.push(newMatchConfig);
|
||||
} else {
|
||||
updatedConfig.push({any: [newMatchConfig]});
|
||||
}
|
||||
} else {
|
||||
// Log the key that we don't know what to do with.
|
||||
core.info(`An unknown config option was under ${label}: ${key}`);
|
||||
}
|
||||
});
|
||||
|
||||
return updatedConfig;
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
if (matchConfigs.length) {
|
||||
labelMap.set(label, matchConfigs);
|
||||
}
|
||||
}
|
||||
|
||||
return labelMap;
|
||||
}
|
||||
|
||||
export function toMatchConfig(config: any): BaseMatchConfig {
|
||||
const changedFilesConfig = toChangedFilesMatchConfig(config);
|
||||
const branchConfig = toBranchMatchConfig(config);
|
||||
|
||||
return {
|
||||
...changedFilesConfig,
|
||||
...branchConfig
|
||||
};
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as yaml from 'js-yaml';
|
||||
import fs from 'fs';
|
||||
import {ClientType} from './types';
|
||||
import {getContent} from './get-content';
|
||||
|
||||
export interface MatchConfig {
|
||||
all?: string[];
|
||||
any?: string[];
|
||||
}
|
||||
|
||||
export type StringOrMatchConfig = string | MatchConfig;
|
||||
|
||||
export const getLabelGlobs = (
|
||||
client: ClientType,
|
||||
configurationPath: string
|
||||
): Promise<Map<string, StringOrMatchConfig[]>> =>
|
||||
Promise.resolve()
|
||||
.then(() => {
|
||||
if (!fs.existsSync(configurationPath)) {
|
||||
core.info(
|
||||
`The configuration file (path: ${configurationPath}) was not found locally, fetching via the api`
|
||||
);
|
||||
|
||||
return getContent(client, configurationPath);
|
||||
}
|
||||
|
||||
core.info(
|
||||
`The configuration file (path: ${configurationPath}) was found locally, reading from the file`
|
||||
);
|
||||
|
||||
return fs.readFileSync(configurationPath, {
|
||||
encoding: 'utf8'
|
||||
});
|
||||
})
|
||||
.catch(error => {
|
||||
if (error.name == 'HttpError' || error.name == 'NotFound') {
|
||||
core.warning(
|
||||
`The config file was not found at ${configurationPath}. Make sure it exists and that this action has the correct access rights.`
|
||||
);
|
||||
}
|
||||
return Promise.reject(error);
|
||||
})
|
||||
.then(configuration => {
|
||||
// loads (hopefully) a `{[label:string]: string | StringOrMatchConfig[]}`, but is `any`:
|
||||
const configObject: any = yaml.load(configuration);
|
||||
|
||||
// transform `any` => `Map<string,StringOrMatchConfig[]>` or throw if yaml is malformed:
|
||||
return getLabelGlobMapFromObject(configObject);
|
||||
});
|
||||
|
||||
function getLabelGlobMapFromObject(
|
||||
configObject: any
|
||||
): Map<string, StringOrMatchConfig[]> {
|
||||
const labelGlobs: Map<string, StringOrMatchConfig[]> = new Map();
|
||||
|
||||
for (const label in configObject) {
|
||||
if (typeof configObject[label] === 'string') {
|
||||
labelGlobs.set(label, [configObject[label]]);
|
||||
} else if (configObject[label] instanceof Array) {
|
||||
labelGlobs.set(label, configObject[label]);
|
||||
} else {
|
||||
throw Error(
|
||||
`found unexpected type for label ${label} (should be string or array of globs)`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return labelGlobs;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
export * from './get-changed-files';
|
||||
export * from './get-changed-pull-requests';
|
||||
export * from './get-content';
|
||||
export * from './get-label-globs';
|
||||
export * from './get-label-configs';
|
||||
export * from './set-labels';
|
||||
export * from './types';
|
||||
|
||||
98
src/branch.ts
Normal file
98
src/branch.ts
Normal file
@@ -0,0 +1,98 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
|
||||
export interface BranchMatchConfig {
|
||||
headBranch?: string[];
|
||||
baseBranch?: string[];
|
||||
}
|
||||
|
||||
type BranchBase = 'base' | 'head';
|
||||
|
||||
export function toBranchMatchConfig(config: any): BranchMatchConfig {
|
||||
if (!config['head-branch'] && !config['base-branch']) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const branchConfig = {
|
||||
headBranch: config['head-branch'],
|
||||
baseBranch: config['base-branch']
|
||||
};
|
||||
|
||||
for (const branchName in branchConfig) {
|
||||
if (typeof branchConfig[branchName] === 'string') {
|
||||
branchConfig[branchName] = [branchConfig[branchName]];
|
||||
}
|
||||
}
|
||||
|
||||
return branchConfig;
|
||||
}
|
||||
|
||||
export function getBranchName(branchBase: BranchBase): string | undefined {
|
||||
const pullRequest = github.context.payload.pull_request;
|
||||
if (!pullRequest) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
if (branchBase === 'base') {
|
||||
return pullRequest.base?.ref;
|
||||
} else {
|
||||
return pullRequest.head?.ref;
|
||||
}
|
||||
}
|
||||
|
||||
export function checkAnyBranch(
|
||||
regexps: string[],
|
||||
branchBase: BranchBase
|
||||
): boolean {
|
||||
const branchName = getBranchName(branchBase);
|
||||
if (!branchName) {
|
||||
core.debug(` no branch name`);
|
||||
return false;
|
||||
}
|
||||
|
||||
core.debug(` checking "branch" pattern against ${branchName}`);
|
||||
const matchers = regexps.map(regexp => new RegExp(regexp));
|
||||
for (const matcher of matchers) {
|
||||
if (matchBranchPattern(matcher, branchName)) {
|
||||
core.debug(` "branch" patterns matched against ${branchName}`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` "branch" patterns did not match against ${branchName}`);
|
||||
return false;
|
||||
}
|
||||
|
||||
export function checkAllBranch(
|
||||
regexps: string[],
|
||||
branchBase: BranchBase
|
||||
): boolean {
|
||||
const branchName = getBranchName(branchBase);
|
||||
if (!branchName) {
|
||||
core.debug(` cannot fetch branch name from the pull request`);
|
||||
return false;
|
||||
}
|
||||
|
||||
core.debug(` checking "branch" pattern against ${branchName}`);
|
||||
const matchers = regexps.map(regexp => new RegExp(regexp));
|
||||
for (const matcher of matchers) {
|
||||
if (!matchBranchPattern(matcher, branchName)) {
|
||||
core.debug(` "branch" patterns did not match against ${branchName}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` "branch" patterns matched against ${branchName}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
function matchBranchPattern(matcher: RegExp, branchName: string): boolean {
|
||||
core.debug(` - ${matcher}`);
|
||||
if (matcher.test(branchName)) {
|
||||
core.debug(` "branch" pattern matched`);
|
||||
return true;
|
||||
}
|
||||
|
||||
core.debug(` ${matcher} did not match`);
|
||||
return false;
|
||||
}
|
||||
360
src/changedFiles.ts
Normal file
360
src/changedFiles.ts
Normal file
@@ -0,0 +1,360 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
import {Minimatch} from 'minimatch';
|
||||
import {printPattern, isObject, kebabToCamel} from './utils';
|
||||
|
||||
export interface ChangedFilesMatchConfig {
|
||||
changedFiles?: ChangedFilesGlobPatternsConfig[];
|
||||
}
|
||||
|
||||
interface ChangedFilesGlobPatternsConfig {
|
||||
anyGlobToAnyFile?: string[];
|
||||
anyGlobToAllFiles?: string[];
|
||||
allGlobsToAnyFile?: string[];
|
||||
allGlobsToAllFiles?: string[];
|
||||
}
|
||||
|
||||
type ClientType = ReturnType<typeof github.getOctokit>;
|
||||
|
||||
const ALLOWED_FILES_CONFIG_KEYS = [
|
||||
'any-glob-to-any-file',
|
||||
'any-glob-to-all-files',
|
||||
'all-globs-to-any-file',
|
||||
'all-globs-to-all-files'
|
||||
];
|
||||
|
||||
export async function getChangedFiles(
|
||||
client: ClientType,
|
||||
prNumber: number
|
||||
): Promise<string[]> {
|
||||
const listFilesOptions = client.rest.pulls.listFiles.endpoint.merge({
|
||||
owner: github.context.repo.owner,
|
||||
repo: github.context.repo.repo,
|
||||
pull_number: prNumber
|
||||
});
|
||||
|
||||
const listFilesResponse = await client.paginate(listFilesOptions);
|
||||
const changedFiles = listFilesResponse.map((f: any) => f.filename);
|
||||
|
||||
core.debug('found changed files:');
|
||||
for (const file of changedFiles) {
|
||||
core.debug(' ' + file);
|
||||
}
|
||||
|
||||
return changedFiles;
|
||||
}
|
||||
|
||||
export function toChangedFilesMatchConfig(
|
||||
config: any
|
||||
): ChangedFilesMatchConfig {
|
||||
if (!config['changed-files'] || !config['changed-files'].length) {
|
||||
return {};
|
||||
}
|
||||
const changedFilesConfigs = Array.isArray(config['changed-files'])
|
||||
? config['changed-files']
|
||||
: [config['changed-files']];
|
||||
|
||||
const validChangedFilesConfigs: ChangedFilesGlobPatternsConfig[] = [];
|
||||
|
||||
changedFilesConfigs.forEach(changedFilesConfig => {
|
||||
if (!isObject(changedFilesConfig)) {
|
||||
throw new Error(
|
||||
`The "changed-files" section must have a valid config structure. Please read the action documentation for more information`
|
||||
);
|
||||
}
|
||||
|
||||
const changedFilesConfigKeys = Object.keys(changedFilesConfig);
|
||||
const invalidKeys = changedFilesConfigKeys.filter(
|
||||
key => !ALLOWED_FILES_CONFIG_KEYS.includes(key)
|
||||
);
|
||||
|
||||
if (invalidKeys.length) {
|
||||
throw new Error(
|
||||
`Unknown config options were under "changed-files": ${invalidKeys.join(
|
||||
', '
|
||||
)}`
|
||||
);
|
||||
}
|
||||
|
||||
changedFilesConfigKeys.forEach(key => {
|
||||
validChangedFilesConfigs.push({
|
||||
[kebabToCamel(key)]: Array.isArray(changedFilesConfig[key])
|
||||
? changedFilesConfig[key]
|
||||
: [changedFilesConfig[key]]
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
return {
|
||||
changedFiles: validChangedFilesConfigs
|
||||
};
|
||||
}
|
||||
|
||||
export function checkAnyChangedFiles(
|
||||
changedFiles: string[],
|
||||
globPatternsConfigs: ChangedFilesGlobPatternsConfig[],
|
||||
dot: boolean
|
||||
): boolean {
|
||||
core.debug(` checking "changed-files" patterns`);
|
||||
|
||||
for (const globPatternsConfig of globPatternsConfigs) {
|
||||
if (globPatternsConfig.anyGlobToAnyFile) {
|
||||
if (
|
||||
checkIfAnyGlobMatchesAnyFile(
|
||||
changedFiles,
|
||||
globPatternsConfig.anyGlobToAnyFile,
|
||||
dot
|
||||
)
|
||||
) {
|
||||
core.debug(` "changed-files" matched`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (globPatternsConfig.anyGlobToAllFiles) {
|
||||
if (
|
||||
checkIfAnyGlobMatchesAllFiles(
|
||||
changedFiles,
|
||||
globPatternsConfig.anyGlobToAllFiles,
|
||||
dot
|
||||
)
|
||||
) {
|
||||
core.debug(` "changed-files" matched`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (globPatternsConfig.allGlobsToAnyFile) {
|
||||
if (
|
||||
checkIfAllGlobsMatchAnyFile(
|
||||
changedFiles,
|
||||
globPatternsConfig.allGlobsToAnyFile,
|
||||
dot
|
||||
)
|
||||
) {
|
||||
core.debug(` "changed-files" matched`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (globPatternsConfig.allGlobsToAllFiles) {
|
||||
if (
|
||||
checkIfAllGlobsMatchAllFiles(
|
||||
changedFiles,
|
||||
globPatternsConfig.allGlobsToAllFiles,
|
||||
dot
|
||||
)
|
||||
) {
|
||||
core.debug(` "changed-files" matched`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` "changed-files" did not match`);
|
||||
return false;
|
||||
}
|
||||
|
||||
export function checkAllChangedFiles(
|
||||
changedFiles: string[],
|
||||
globPatternsConfigs: ChangedFilesGlobPatternsConfig[],
|
||||
dot: boolean
|
||||
): boolean {
|
||||
core.debug(` checking "changed-files" patterns`);
|
||||
|
||||
for (const globPatternsConfig of globPatternsConfigs) {
|
||||
if (globPatternsConfig.anyGlobToAnyFile) {
|
||||
if (
|
||||
!checkIfAnyGlobMatchesAnyFile(
|
||||
changedFiles,
|
||||
globPatternsConfig.anyGlobToAnyFile,
|
||||
dot
|
||||
)
|
||||
) {
|
||||
core.debug(` "changed-files" did not match`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (globPatternsConfig.anyGlobToAllFiles) {
|
||||
if (
|
||||
!checkIfAnyGlobMatchesAllFiles(
|
||||
changedFiles,
|
||||
globPatternsConfig.anyGlobToAllFiles,
|
||||
dot
|
||||
)
|
||||
) {
|
||||
core.debug(` "changed-files" did not match`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (globPatternsConfig.allGlobsToAnyFile) {
|
||||
if (
|
||||
!checkIfAllGlobsMatchAnyFile(
|
||||
changedFiles,
|
||||
globPatternsConfig.allGlobsToAnyFile,
|
||||
dot
|
||||
)
|
||||
) {
|
||||
core.debug(` "changed-files" did not match`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (globPatternsConfig.allGlobsToAllFiles) {
|
||||
if (
|
||||
!checkIfAllGlobsMatchAllFiles(
|
||||
changedFiles,
|
||||
globPatternsConfig.allGlobsToAllFiles,
|
||||
dot
|
||||
)
|
||||
) {
|
||||
core.debug(` "changed-files" did not match`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` "changed-files" patterns matched`);
|
||||
return true;
|
||||
}
|
||||
|
||||
export function checkIfAnyGlobMatchesAnyFile(
|
||||
changedFiles: string[],
|
||||
globs: string[],
|
||||
dot: boolean
|
||||
): boolean {
|
||||
core.debug(` checking "any-glob-to-any-file" config patterns`);
|
||||
const matchers = globs.map(g => new Minimatch(g, {dot}));
|
||||
|
||||
for (const matcher of matchers) {
|
||||
const matchedFile = changedFiles.find(changedFile => {
|
||||
core.debug(
|
||||
` checking "${printPattern(
|
||||
matcher
|
||||
)}" pattern against ${changedFile}`
|
||||
);
|
||||
|
||||
return matcher.match(changedFile);
|
||||
});
|
||||
|
||||
if (matchedFile) {
|
||||
core.debug(
|
||||
` "${printPattern(matcher)}" pattern matched ${matchedFile}`
|
||||
);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` none of the patterns matched any of the files`);
|
||||
return false;
|
||||
}
|
||||
|
||||
export function checkIfAllGlobsMatchAnyFile(
|
||||
changedFiles: string[],
|
||||
globs: string[],
|
||||
dot: boolean
|
||||
): boolean {
|
||||
core.debug(` checking "all-globs-to-any-file" config patterns`);
|
||||
const matchers = globs.map(g => new Minimatch(g, {dot}));
|
||||
|
||||
for (const changedFile of changedFiles) {
|
||||
const mismatchedGlob = matchers.find(matcher => {
|
||||
core.debug(
|
||||
` checking "${printPattern(
|
||||
matcher
|
||||
)}" pattern against ${changedFile}`
|
||||
);
|
||||
|
||||
return !matcher.match(changedFile);
|
||||
});
|
||||
|
||||
if (mismatchedGlob) {
|
||||
core.debug(
|
||||
` "${printPattern(
|
||||
mismatchedGlob
|
||||
)}" pattern did not match ${changedFile}`
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
core.debug(` all patterns matched ${changedFile}`);
|
||||
return true;
|
||||
}
|
||||
|
||||
core.debug(` none of the files matched all patterns`);
|
||||
return false;
|
||||
}
|
||||
|
||||
export function checkIfAnyGlobMatchesAllFiles(
|
||||
changedFiles: string[],
|
||||
globs: string[],
|
||||
dot: boolean
|
||||
): boolean {
|
||||
core.debug(` checking "any-glob-to-all-files" config patterns`);
|
||||
const matchers = globs.map(g => new Minimatch(g, {dot}));
|
||||
|
||||
for (const matcher of matchers) {
|
||||
const mismatchedFile = changedFiles.find(changedFile => {
|
||||
core.debug(
|
||||
` checking "${printPattern(
|
||||
matcher
|
||||
)}" pattern against ${changedFile}`
|
||||
);
|
||||
|
||||
return !matcher.match(changedFile);
|
||||
});
|
||||
|
||||
if (mismatchedFile) {
|
||||
core.debug(
|
||||
` "${printPattern(
|
||||
matcher
|
||||
)}" pattern did not match ${mismatchedFile}`
|
||||
);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
core.debug(` "${printPattern(matcher)}" pattern matched all files`);
|
||||
return true;
|
||||
}
|
||||
|
||||
core.debug(` none of the patterns matched all files`);
|
||||
return false;
|
||||
}
|
||||
|
||||
export function checkIfAllGlobsMatchAllFiles(
|
||||
changedFiles: string[],
|
||||
globs: string[],
|
||||
dot: boolean
|
||||
): boolean {
|
||||
core.debug(` checking "all-globs-to-all-files" config patterns`);
|
||||
const matchers = globs.map(g => new Minimatch(g, {dot}));
|
||||
|
||||
for (const changedFile of changedFiles) {
|
||||
const mismatchedGlob = matchers.find(matcher => {
|
||||
core.debug(
|
||||
` checking "${printPattern(
|
||||
matcher
|
||||
)}" pattern against ${changedFile}`
|
||||
);
|
||||
|
||||
return !matcher.match(changedFile);
|
||||
});
|
||||
|
||||
if (mismatchedGlob) {
|
||||
core.debug(
|
||||
` "${printPattern(
|
||||
mismatchedGlob
|
||||
)}" pattern did not match ${changedFile}`
|
||||
);
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` all patterns matched all files`);
|
||||
return true;
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import {getPrNumbers} from './get-pr-numbers';
|
||||
export const getInputs = () => ({
|
||||
token: core.getInput('repo-token'),
|
||||
configPath: core.getInput('configuration-path', {required: true}),
|
||||
syncLabels: !!core.getInput('sync-labels'),
|
||||
syncLabels: core.getBooleanInput('sync-labels'),
|
||||
dot: core.getBooleanInput('dot'),
|
||||
prNumbers: getPrNumbers()
|
||||
});
|
||||
|
||||
196
src/labeler.ts
196
src/labeler.ts
@@ -1,18 +1,16 @@
|
||||
import * as core from '@actions/core';
|
||||
import * as github from '@actions/github';
|
||||
import * as pluginRetry from '@octokit/plugin-retry';
|
||||
import {Minimatch} from 'minimatch';
|
||||
import * as api from './api';
|
||||
import isEqual from 'lodash.isequal';
|
||||
import {printPattern} from './utils';
|
||||
import {getInputs} from './get-inputs';
|
||||
|
||||
interface MatchConfig {
|
||||
all?: string[];
|
||||
any?: string[];
|
||||
}
|
||||
import {BaseMatchConfig, MatchConfig} from './api/get-label-configs';
|
||||
|
||||
import {checkAllChangedFiles, checkAnyChangedFiles} from './changedFiles';
|
||||
|
||||
import {checkAnyBranch, checkAllBranch} from './branch';
|
||||
|
||||
type StringOrMatchConfig = string | MatchConfig;
|
||||
type ClientType = ReturnType<typeof github.getOctokit>;
|
||||
|
||||
// GitHub Issues cannot have more than 100 labels
|
||||
@@ -37,14 +35,16 @@ async function labeler() {
|
||||
const pullRequests = api.getPullRequests(client, prNumbers);
|
||||
|
||||
for await (const pullRequest of pullRequests) {
|
||||
const labelGlobs: Map<string, StringOrMatchConfig[]> =
|
||||
await api.getLabelGlobs(client, configPath);
|
||||
const labelConfigs: Map<string, MatchConfig[]> = await api.getLabelConfigs(
|
||||
client,
|
||||
configPath
|
||||
);
|
||||
const preexistingLabels = pullRequest.data.labels.map(l => l.name);
|
||||
const allLabels: Set<string> = new Set<string>(preexistingLabels);
|
||||
|
||||
for (const [label, globs] of labelGlobs.entries()) {
|
||||
for (const [label, configs] of labelConfigs.entries()) {
|
||||
core.debug(`processing ${label}`);
|
||||
if (checkGlobs(pullRequest.changedFiles, globs, dot)) {
|
||||
if (checkMatchConfigs(pullRequest.changedFiles, configs, dot)) {
|
||||
allLabels.add(label);
|
||||
} else if (syncLabels) {
|
||||
allLabels.delete(label);
|
||||
@@ -97,80 +97,18 @@ async function labeler() {
|
||||
}
|
||||
}
|
||||
|
||||
function toMatchConfig(config: StringOrMatchConfig): MatchConfig {
|
||||
if (typeof config === 'string') {
|
||||
return {
|
||||
any: [config]
|
||||
};
|
||||
}
|
||||
|
||||
return config;
|
||||
}
|
||||
|
||||
export function checkGlobs(
|
||||
export function checkMatchConfigs(
|
||||
changedFiles: string[],
|
||||
globs: StringOrMatchConfig[],
|
||||
matchConfigs: MatchConfig[],
|
||||
dot: boolean
|
||||
): boolean {
|
||||
for (const glob of globs) {
|
||||
core.debug(` checking pattern ${JSON.stringify(glob)}`);
|
||||
const matchConfig = toMatchConfig(glob);
|
||||
if (checkMatch(changedFiles, matchConfig, dot)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function isMatch(changedFile: string, matchers: Minimatch[]): boolean {
|
||||
core.debug(` matching patterns against file ${changedFile}`);
|
||||
for (const matcher of matchers) {
|
||||
core.debug(` - ${printPattern(matcher)}`);
|
||||
if (!matcher.match(changedFile)) {
|
||||
core.debug(` ${printPattern(matcher)} did not match`);
|
||||
for (const config of matchConfigs) {
|
||||
core.debug(` checking config ${JSON.stringify(config)}`);
|
||||
if (!checkMatch(changedFiles, config, dot)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` all patterns matched`);
|
||||
return true;
|
||||
}
|
||||
|
||||
// equivalent to "Array.some()" but expanded for debugging and clarity
|
||||
function checkAny(
|
||||
changedFiles: string[],
|
||||
globs: string[],
|
||||
dot: boolean
|
||||
): boolean {
|
||||
const matchers = globs.map(g => new Minimatch(g, {dot}));
|
||||
core.debug(` checking "any" patterns`);
|
||||
for (const changedFile of changedFiles) {
|
||||
if (isMatch(changedFile, matchers)) {
|
||||
core.debug(` "any" patterns matched against ${changedFile}`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` "any" patterns did not match any files`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// equivalent to "Array.every()" but expanded for debugging and clarity
|
||||
function checkAll(
|
||||
changedFiles: string[],
|
||||
globs: string[],
|
||||
dot: boolean
|
||||
): boolean {
|
||||
const matchers = globs.map(g => new Minimatch(g, {dot}));
|
||||
core.debug(` checking "all" patterns`);
|
||||
for (const changedFile of changedFiles) {
|
||||
if (!isMatch(changedFile, matchers)) {
|
||||
core.debug(` "all" patterns did not match against ${changedFile}`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` "all" patterns matched all files`);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -179,17 +117,111 @@ function checkMatch(
|
||||
matchConfig: MatchConfig,
|
||||
dot: boolean
|
||||
): boolean {
|
||||
if (matchConfig.all !== undefined) {
|
||||
if (!checkAll(changedFiles, matchConfig.all, dot)) {
|
||||
if (!Object.keys(matchConfig).length) {
|
||||
core.debug(` no "any" or "all" patterns to check`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (matchConfig.all) {
|
||||
if (!checkAll(matchConfig.all, changedFiles, dot)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchConfig.any !== undefined) {
|
||||
if (!checkAny(changedFiles, matchConfig.any, dot)) {
|
||||
if (matchConfig.any) {
|
||||
if (!checkAny(matchConfig.any, changedFiles, dot)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// equivalent to "Array.some()" but expanded for debugging and clarity
|
||||
export function checkAny(
|
||||
matchConfigs: BaseMatchConfig[],
|
||||
changedFiles: string[],
|
||||
dot: boolean
|
||||
): boolean {
|
||||
core.debug(` checking "any" patterns`);
|
||||
if (
|
||||
!matchConfigs.length ||
|
||||
!matchConfigs.some(configOption => Object.keys(configOption).length)
|
||||
) {
|
||||
core.debug(` no "any" patterns to check`);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const matchConfig of matchConfigs) {
|
||||
if (matchConfig.baseBranch) {
|
||||
if (checkAnyBranch(matchConfig.baseBranch, 'base')) {
|
||||
core.debug(` "any" patterns matched`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchConfig.changedFiles) {
|
||||
if (checkAnyChangedFiles(changedFiles, matchConfig.changedFiles, dot)) {
|
||||
core.debug(` "any" patterns matched`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchConfig.headBranch) {
|
||||
if (checkAnyBranch(matchConfig.headBranch, 'head')) {
|
||||
core.debug(` "any" patterns matched`);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` "any" patterns did not match any configs`);
|
||||
return false;
|
||||
}
|
||||
|
||||
// equivalent to "Array.every()" but expanded for debugging and clarity
|
||||
export function checkAll(
|
||||
matchConfigs: BaseMatchConfig[],
|
||||
changedFiles: string[],
|
||||
dot: boolean
|
||||
): boolean {
|
||||
core.debug(` checking "all" patterns`);
|
||||
if (
|
||||
!matchConfigs.length ||
|
||||
!matchConfigs.some(configOption => Object.keys(configOption).length)
|
||||
) {
|
||||
core.debug(` no "all" patterns to check`);
|
||||
return false;
|
||||
}
|
||||
|
||||
for (const matchConfig of matchConfigs) {
|
||||
if (matchConfig.baseBranch) {
|
||||
if (!checkAllBranch(matchConfig.baseBranch, 'base')) {
|
||||
core.debug(` "all" patterns did not match`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchConfig.changedFiles) {
|
||||
if (!changedFiles.length) {
|
||||
core.debug(` no files to check "changed-files" patterns against`);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!checkAllChangedFiles(changedFiles, matchConfig.changedFiles, dot)) {
|
||||
core.debug(` "all" patterns did not match`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (matchConfig.headBranch) {
|
||||
if (!checkAllBranch(matchConfig.headBranch, 'head')) {
|
||||
core.debug(` "all" patterns did not match`);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
core.debug(` "all" patterns matched all configs`);
|
||||
return true;
|
||||
}
|
||||
|
||||
13
src/utils.ts
Normal file
13
src/utils.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import {Minimatch} from 'minimatch';
|
||||
|
||||
export const printPattern = (matcher: Minimatch): string => {
|
||||
return (matcher.negate ? '!' : '') + matcher.pattern;
|
||||
};
|
||||
|
||||
export const kebabToCamel = (str: string): string => {
|
||||
return str.replace(/-./g, m => m.toUpperCase()[1]);
|
||||
};
|
||||
|
||||
export function isObject(obj: unknown): obj is object {
|
||||
return obj !== null && typeof obj === 'object' && !Array.isArray(obj);
|
||||
}
|
||||
@@ -1 +0,0 @@
|
||||
export * from './print-pattern';
|
||||
@@ -1,5 +0,0 @@
|
||||
import {Minimatch} from 'minimatch';
|
||||
|
||||
export const printPattern = (matcher: Minimatch): string => {
|
||||
return (matcher.negate ? '!' : '') + matcher.pattern;
|
||||
};
|
||||
Reference in New Issue
Block a user