Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the Ability to Label Based on Size of PR #2

Closed
wants to merge 89 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
89 commits
Select commit Hold shift + click to select a range
b0d9292
Implement dot option
kachkaev Feb 4, 2022
6a0b726
Rebuild
kachkaev Feb 4, 2022
409a5a2
Fix typo in test caption
kachkaev Feb 4, 2022
920e9b6
Add comments
kachkaev Feb 4, 2022
8b8677b
Improve warning
kachkaev Feb 4, 2022
e05b7c1
Update README.md
kachkaev Feb 4, 2022
f3632d3
Update README.md
kachkaev Feb 4, 2022
d89797c
Merge remote-tracking branch 'upstream/main' into dot-option
kachkaev Sep 14, 2022
2025154
Simplify glob
kachkaev Oct 5, 2022
b78dba3
Simplify globbing examples in README
Youssef1313 Oct 23, 2022
866eff5
Merge remote-tracking branch 'origin/main' into dot-option
kachkaev Jan 16, 2023
305cfeb
Rebuild
kachkaev Jan 16, 2023
4a96e77
Merge branch 'main' into dot-option
kachkaev Mar 12, 2023
b898cc8
Merge remote-tracking branch 'u/main' into dot-option
kachkaev Mar 27, 2023
b28379f
Cleanup
kachkaev Mar 27, 2023
a7cc8a6
Fix
kachkaev Mar 27, 2023
012b892
Merge remote-tracking branch 'u/main' into dot-option
kachkaev May 19, 2023
9107682
Update configuration files
github-actions[bot] May 23, 2023
d1dd326
Install eslint-plugin-node
nikolai-laevskii May 23, 2023
08382d1
Move eslint-plugin-node to dev dependencies
nikolai-laevskii May 23, 2023
0776a67
Merge pull request #571 from akv-platform/remove-implicit-dependencies
marko-zivic-93 May 24, 2023
7fef7e3
Bump @typescript-eslint/parser from 5.59.7 to 5.59.8
dependabot[bot] May 30, 2023
cecbd94
Merge remote-tracking branch 'u/main' into dot-option
kachkaev May 31, 2023
092c979
Update src/labeler.ts
kachkaev May 31, 2023
60f44e7
Fix unrelated test
kachkaev May 31, 2023
9776203
Update build
kachkaev May 31, 2023
a27020c
Undo unwanted change in diff
kachkaev May 31, 2023
44414db
Fix tests
kachkaev May 31, 2023
673c7e2
Rebuild
kachkaev May 31, 2023
e3b3815
Further diff reduction
kachkaev May 31, 2023
d07f38b
Merge branch 'main' into patch-1
Youssef1313 May 31, 2023
54d434d
Remove `required: false`
kachkaev May 31, 2023
a78a6c7
Update README.md
Youssef1313 May 31, 2023
59d3310
Rebuild
kachkaev May 31, 2023
71d2484
Address review comment
kachkaev May 31, 2023
639ba81
Rebuild
kachkaev May 31, 2023
3cbc54c
Merge pull request #451 from Youssef1313/patch-1
MaksimZhukov Jun 1, 2023
d40596e
micromatch → minimatch
kachkaev Jun 2, 2023
82a4f6f
Merge pull request #316 from kachkaev/dot-option
MaksimZhukov Jun 5, 2023
1d399c3
Merge pull request #577 from actions/dependabot/npm_and_yarn/typescri…
MaksimZhukov Jun 5, 2023
0d06c50
Bump @typescript-eslint/eslint-plugin from 5.59.7 to 5.59.8
dependabot[bot] Jun 5, 2023
9fcb2c2
Merge pull request #578 from actions/dependabot/npm_and_yarn/typescri…
MaksimZhukov Jun 5, 2023
092c82e
Document permissions needed for pull_request events
dfandrich Jan 25, 2023
673e3c1
Merge pull request #491 from dfandrich/limitations
MaksimZhukov Jun 9, 2023
af1100d
Bump @typescript-eslint/parser from 5.59.8 to 5.59.11
dependabot[bot] Jun 13, 2023
1a5defc
spelling: e.g.
jsoref Jun 13, 2023
3240e30
Markdown: backticks
jsoref Jun 13, 2023
d817fad
Merge pull request #589 from jsoref/readme
MaksimZhukov Jun 14, 2023
96d00dc
Merge pull request #588 from actions/dependabot/npm_and_yarn/typescri…
MaksimZhukov Jun 14, 2023
ad1762f
Bump @typescript-eslint/eslint-plugin from 5.59.8 to 5.59.11
dependabot[bot] Jun 14, 2023
ed183b1
Merge pull request #587 from actions/dependabot/npm_and_yarn/typescri…
MaksimZhukov Jun 14, 2023
6fe5568
Bump eslint from 8.41.0 to 8.42.0
dependabot[bot] Jun 14, 2023
fe87e60
Merge pull request #580 from actions/dependabot/npm_and_yarn/eslint-8…
MaksimZhukov Jun 14, 2023
b5ff161
Explain misconfigured workflow (#405)
jsoref Jun 19, 2023
7a202e6
fix: Limit number of labels added to 100 (#497)
markmssd Jun 21, 2023
8056174
Bump @typescript-eslint/eslint-plugin from 5.59.11 to 5.60.0 (#594)
dependabot[bot] Jun 21, 2023
899595f
Bump eslint-plugin-jest from 27.2.1 to 27.2.2 (#591)
dependabot[bot] Jun 21, 2023
54aeabf
Bump @typescript-eslint/parser from 5.59.11 to 5.60.0 (#593)
dependabot[bot] Jun 21, 2023
130636a
Bump eslint from 8.42.0 to 8.43.0 (#592)
dependabot[bot] Jun 21, 2023
9d45a74
Bump @typescript-eslint/eslint-plugin from 5.60.0 to 5.60.1 (#598)
dependabot[bot] Jun 28, 2023
8d17e8a
Bump @typescript-eslint/parser from 5.60.0 to 5.60.1 (#597)
dependabot[bot] Jun 28, 2023
375538a
Bump @octokit/plugin-retry from 5.0.2 to 5.0.4 (#599)
MaksimZhukov Jun 28, 2023
0967ca8
Added output (#60)
danielsht86 Jun 29, 2023
e3c0d9b
Improved Error message for missing config file (#475)
Gornoka Jun 30, 2023
a212485
Add examples to match all repo files (#600)
MaksimZhukov Jun 30, 2023
5bea145
Bump eslint from 8.43.0 to 8.44.0 (#601)
dependabot[bot] Jul 3, 2023
52979ba
Bump @typescript-eslint/parser from 5.60.1 to 5.61.0 (#602)
dependabot[bot] Jul 4, 2023
b669025
Bump @typescript-eslint/eslint-plugin from 5.60.1 to 5.61.0 (#604)
dependabot[bot] Jul 4, 2023
65f306b
Fix a typo in the example about using the action outputs (#606)
MaksimZhukov Jul 5, 2023
327d35f
Added ability to pass in an optional PR number as a parameter (#349)
credfeto Jul 6, 2023
994304c
feat(config): support reading from local file if it exists (#394)
lrstanley Jul 7, 2023
be13bbd
Early exit when no files are changed. (#456)
nathanhammond Jul 7, 2023
7542ec7
Bump tough-cookie from 4.1.2 to 4.1.3 (#609)
dependabot[bot] Jul 10, 2023
ac9175f
Bump @octokit/plugin-retry from 5.0.4 to 5.0.5 (#610)
MaksimZhukov Jul 10, 2023
b3ae1bd
Make `jest-each` a devDependency (#611)
ericcornelissen Jul 11, 2023
e482ff4
Update the README (#612)
MaksimZhukov Jul 11, 2023
6fe6672
Bump @typescript-eslint/parser from 5.61.0 to 5.62.0 (#615)
dependabot[bot] Jul 12, 2023
ab39889
Bump eslint-plugin-jest from 27.2.2 to 27.2.3 (#620)
dependabot[bot] Jul 18, 2023
6d6995c
Bump word-wrap from 1.2.3 to 1.2.4 (#623)
dependabot[bot] Jul 24, 2023
3cc2196
Bump eslint from 8.44.0 to 8.45.0 (#622)
dependabot[bot] Jul 24, 2023
68124ad
Update Minimatch to 9.0.3, rebuild and fix licensing (#626)
dusan-trickovic Jul 26, 2023
be045bb
Update changedFiles to contain size info per file without changing fu…
jw-maynard Jul 27, 2023
fe4e7b5
Prettier formatting
jw-maynard Jul 27, 2023
e336344
Fix tests
jw-maynard Jul 27, 2023
133a9a8
Prettier formatting for tests
jw-maynard Jul 27, 2023
7b128b0
move labels config to sub key to allow for size config without changi…
jw-maynard Jul 27, 2023
68a45b2
Fix main tests
jw-maynard Jul 27, 2023
fad288c
Fix main tests
jw-maynard Jul 27, 2023
547e54a
Add tests, update dist
jw-maynard Jul 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = {
'eslint-config-prettier'
],
parser: '@typescript-eslint/parser',
plugins: ['@typescript-eslint', 'eslint-plugin-jest'],
plugins: ['@typescript-eslint', 'eslint-plugin-node', 'eslint-plugin-jest'],
rules: {
'@typescript-eslint/no-require-imports': 'error',
'@typescript-eslint/no-non-null-assertion': 'off',
Expand All @@ -28,7 +28,8 @@ module.exports = {
}
],
'no-control-regex': 'off',
'no-constant-condition': ['error', {checkLoops: false}]
'no-constant-condition': ['error', {checkLoops: false}],
'node/no-extraneous-import': 'error'
},
overrides: [
{
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
node_modules/
lib/
lib/
.idea

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .licenses/npm/@octokit/openapi-types-18.0.0.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .licenses/npm/@octokit/plugin-retry.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 34 additions & 0 deletions .licenses/npm/@octokit/request-error-4.0.2.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .licenses/npm/@octokit/types-10.0.0.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

31 changes: 31 additions & 0 deletions .licenses/npm/bottleneck.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .licenses/npm/minimatch.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

154 changes: 142 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Automatically label new pull requests based on the paths of files being changed.

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.

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 the path (glob) of the changed files (eg: `src/**/*`, `tests/*.spec.js`) or a match object.
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.

#### Match Object

Expand Down Expand Up @@ -40,12 +40,17 @@ label1:

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.

#### Basic Examples

```yml
# Add 'label1' to any changes within 'example' folder or any subfolders
label1:
- example/**/*
- example/**

# Add 'label2' to any file changes within 'example2' folder
label2: example2/*
Expand All @@ -65,26 +70,36 @@ repo:

# Add '@domain/core' label to any change within the 'core' package
'@domain/core':
- package/core/*
- package/core/**/*
- package/core/**

# Add 'test' label to any change to *.spec.js files within the source dir
test:
- src/**/*.spec.js

# Add 'source' label to any change to src files within the source dir EXCEPT for the docs sub-folder
source:
- any: ['src/**/*', '!src/docs/*']
- any: ['src/**', '!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 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:
- '**'
```

### Create Workflow

Create a workflow (eg: `.github/workflows/labeler.yml` see [Creating a Workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file)) to utilize the labeler action with content:
Create a workflow (e.g. `.github/workflows/labeler.yml` see [Creating a Workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file)) to utilize the labeler action with content:

```yml
name: "Pull Request Labeler"
Expand All @@ -105,12 +120,127 @@ jobs:

Various inputs are defined in [`action.yml`](action.yml) to let you configure the labeler:

| Name | Description | Default |
| - | - | - |
| `repo-token` | Token to use to authorize label changes. Typically the GITHUB_TOKEN secret, with `contents:read` and `pull-requests:write` access | `github.token` |
| `configuration-path` | The path to the label configuration file | `.github/labeler.yml` |
| `sync-labels` | Whether or not to remove labels when matching files are reverted or no longer changed by the PR | `false`|
| Name | Description | Default |
|----------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------|
| `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` |
| `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
You might want to use action called [@actions/checkout](https://github.com/actions/checkout) to upload label configuration file onto the runner from the current or any other repositories. See usage example below:

```yml
steps:
- uses: actions/checkout@v3 # 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
```

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

```yml
name: "Label Previous Pull Requests"
on:
schedule:
- cron: "0 1 * * 1"

jobs:
triage:
permissions:
contents: read
pull-requests: write

runs-on: ubuntu-latest
steps:

# Label PRs 1, 2, and 3
- uses: actions/labeler@v4
with:
pr-number: |
1
2
3
```

**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:

| Name | Description |
|--------------|-----------------------------------------------------------|
| `new-labels` | A comma-separated list of all new labels |
| `all-labels` | A comma-separated list of all labels that the PR contains |

The following example performs steps based on the output of labeler:
```yml
name: "My workflow"
on:
- pull_request_target

jobs:
triage:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- id: label-the-PR
uses: actions/labeler@v4

- id: run-frontend-tests
if: contains(steps.label-the-PR.outputs.all-labels, 'frontend')
run: |
echo "Running frontend tests..."
# Put your commands for running frontend tests here

- id: run-backend-tests
if: contains(steps.label-the-PR.outputs.all-labels, 'backend')
run: |
echo "Running backend tests..."
# Put your commands for running backend tests here
```

# Contributions
## 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.

## Contributions

Contributions are welcome! See the [Contributor's Guide](CONTRIBUTING.md).