Giter VIP home page Giter VIP logo

labeler's Introduction

Pull Request Labeler

Basic validation

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 and #54). The match object for changed files was expanded with new combinations in order to make it more intuitive and flexible (#423 and #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). 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. 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.

Important

Before the update to the v5, please check out this information about the pull_request_target event trigger.

Usage

Create .github/labeler.yml

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 (eg: "merge conflict", "needs-updating") and the value is a match object.

Match Object

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, and for the branches you provide a regexp to match against the branch name.

The base match object is defined as:

- 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']

There are two top-level keys, any and all, which both accept the same configuration options:

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

Documentation:
- changed-files:
  - any-glob-to-any-file: 'docs/*'

and

Documentation:
- any:
  - changed-files:
    - any-glob-to-any-file: 'docs/*'

If path globs are combined with ! negation, you can write complex matching rules. See the examples below for more information.

Basic Examples

# 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 'AnyChange' label to any changes within the entire repository
AnyChange:
- changed-files:
  - any-glob-to-any-file: '**'

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

# Add 'Documentation' label to any file changes within 'docs' or 'guides' folders
Documentation:
- changed-files:
  - any-glob-to-any-file:
    - docs/*
    - guides/*

## Equivalent of the above mentioned configuration using another syntax
Documentation:
- changed-files:
  - any-glob-to-any-file: ['docs/*', 'guides/*']

# 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:
- all:
  - changed-files:
    - any-glob-to-any-file: 'src/**/*'
    - all-globs-to-all-files: '!src/docs/*'

# 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 'release' label to any PR that is opened against the `main` branch
release:
 - base-branch: 'main'

Create Workflow

Create a workflow (e.g. .github/workflows/labeler.yml see Creating a Workflow file) to utilize the labeler action with content:

name: "Pull Request Labeler"
on:
- pull_request_target

jobs:
  labeler:
    permissions:
      contents: read
      pull-requests: write
    runs-on: ubuntu-latest
    steps:
    - uses: actions/labeler@v5

Inputs

Various inputs are defined in 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 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) 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

You might want to use action called @actions/checkout to upload label configuration file onto the runner from the current or any other repositories. See usage example below:

    steps:
    - 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@v5
      with:
        configuration-path: 'path/to/the/uploaded/configuration/file'
Example workflow specifying pull request numbers
name: "Label Previous Pull Requests"
on:
  schedule:
    - cron: "0 1 * * 1"

jobs:
  labeler:
    permissions:
      contents: read
      pull-requests: write
    runs-on: ubuntu-latest
    steps:
    
    # Label PRs 1, 2, and 3
    - uses: actions/labeler@v5
      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:

name: "Pull Request Labeler"
on:
- pull_request_target

jobs:
  labeler:
    permissions:
      contents: read
      pull-requests: write
    runs-on: ubuntu-latest
    steps:
    - id: label-the-PR
      uses: actions/labeler@v5
      
    - 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

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 instead of pull_request (see example above). This change allows the action to have write access, because pull_request_target alters the context of the action and safely grants additional permissions. Refer to the GitHub token permissions documentation for more details about access levels and event contexts.

Notes regarding pull_request_target event

Using the pull_request_target event trigger involves several peculiarities related to initial set up of the labeler or updating version of the labeler.

Initial set up of the labeler action

When submitting an initial pull request to a repository using the pull_request_target event, the labeler workflow will not run on that pull request because the pull_request_target execution runs off the base branch instead of the pull request's branch. Unfortunately this means the introduction of the labeler can not be verified during that pull request and it needs to be committed blindly.

Updating major version of the labeler

When submitting a pull request that includes updates of the labeler action version and associated configuration files, using the pull_request_target event may result in a failed workflow. This is due to the nature of pull_request_target, which uses the code from the base branch rather than the branch linked to the pull request โ€” so, potentially outdated configuration files may not be compatible with the updated labeler action.

To prevent this issue, you can switch to using the pull_request event temporarily, before merging. This event execution draws from the code within the branch of your pull request, allowing you to verify the new configuration's compatibility with the updated labeler action.

name: "Pull Request Labeler"
on:
- pull_request

Once you confirm that the updated configuration files function as intended, you can then revert to using the pull_request_target event before merging the pull request. Following this step ensures that your workflow is robust and free from disruptions.

Contributions

Contributions are welcome! See the Contributor's Guide.

labeler's People

Contributors

amiel avatar cory-miller avatar dependabot[bot] avatar ericcornelissen avatar ethomson avatar github-actions[bot] avatar gornoka avatar hross avatar ivanzosimov avatar jalaziz avatar joshdales avatar jsoref avatar kachkaev avatar maksimzhukov avatar marko-zivic-93 avatar nikolai-laevskii avatar panticmilos avatar pje avatar pjquirk avatar pllim avatar radmint avatar rentziass avatar shawnnapora avatar silverwind avatar sungh0lim avatar thboop avatar tingluohuang avatar trianguloy avatar ylemkimon avatar youssef1313 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

labeler's Issues

Rename default branch

๐Ÿ‘‹ This issue is to track the move over to using main as the default branch for this repo. Weโ€™d love your team's help in completing this transition.

Do not remove your old default branch, customers are going to be using it. We will be sending messages out about these changes, but if you want to message in your repository, that's fine as well.

  • Create a main branch.
  • You might need to rebase any pull requests you want to merge before changing the default branch.
  • Change the default branch in settings to main.
  • Update any documentation in this repo to refer to the new branch name, although using the version tag is still preferred.
  • Check that this Action works correctly for users who have a repository with a custom default branch name.
  • Close this issue and celebrate ๐ŸŽ‰

We are aiming to complete this work by July 17th July 24th.

[error]HttpError: Not Found

2019-08-30T04:47:25.3784277Z Current runner version: '2.157.2'
2019-08-30T04:47:25.3803572Z Prepare workflow directory
2019-08-30T04:47:25.4369293Z Prepare all required actions
2019-08-30T04:47:25.4675219Z Download action repository 'actions/labeler@v2'
2019-08-30T04:47:27.8427078Z ##[group]Run actions/labeler@v2
2019-08-30T04:47:27.8498581Z with:
2019-08-30T04:47:27.8498775Z repo-token: ***
2019-08-30T04:47:27.8498811Z configuration-path: .github/labeler.yml
2019-08-30T04:47:27.8498846Z ##[endgroup]
2019-08-30T04:47:28.4480335Z ##[error]HttpError: Not Found
2019-08-30T04:47:28.4807300Z ##[error]Not Found
2019-08-30T04:47:28.4832078Z ##[error]Node run failed with exit code 1
2019-08-30T04:47:28.5015714Z Cleaning up orphan processes

"Common Examples" fails to execute

This action fails when using the "Common Examples" example from the readme:

workflows/label.yml:

# This workflow will triage pull requests and apply a label based on the
# paths that are modified in the pull request.
#
# To use this workflow, you will need to set up a .github/labeler.yml
# file with configuration.  For more information, see:
# https://github.com/actions/labeler/blob/master/README.md

name: Labeler
on: [pull_request]

jobs:
  label:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/labeler@v2
      with:
        repo-token: "${{ secrets.GITHUB_TOKEN }}"

labeler.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/*
  - 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/*']

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

yields following error in gh actions:

  Set up job5s
  Run actions/labeler@v21s
    ^
Run actions/labeler@v2
##[error]YAMLException: end of the stream or a document separator is expected at line 6, column 1:
    @domain/core:
    ^
##[error]end of the stream or a document separator is expected at line 6, column 1:
    @domain/core:
    ^
  Complete job

Issue with Labeler

When I added the labeler to my repo, this is what I get:

##[error]HttpError: Not Found
6
##[error]Not Found
7
##[error]Node run failed with exit code 1

auto add label on the giver PR if ta test fails or not.

Looks like there is not way to configure the labeler to auto set labes depending on the tests results
it can be a previous workflow or in the same one.

i.e. it is what I tried so far:
create the labeler yaml file as described in the docs, plus add this step on my workflow:
`name: Java 8 CI

on: pull_request
jobs:
test:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Set up JDK 1.8
  uses: actions/setup-java@v1
  with:
    java-version: 1.8
- name: Test with Maven
  run: mvn clean test --file pom.xml
- if: success()
  uses: actions/labeler@v2
  with:
    repo-token: "${{ secrets.GITHUB_TOKEN }}"
    configuration-path: .github/labeler.yml     
    ready: ./**/*`

where ready is the label name I expect to have it set.

The logs does not print anything useful.

Fails on forks

Hello,

Most of the contributions is coming from the forked Repo, this action is not usable anymore since it fails for the PR coming from the forked repo.
Almost all the projects in my organisation are using this action. Is there any workaround or final solution to counter this issue ?.

Support for exclusion paths

There are cases where we want to match an entire directory but not certain subdirectories.

Instead of having to list each matching subdirectory, it would be nice to be able to exclude some paths from a match.

An example may be:

label1:
- match: "example1/**/*"
  exclude: ["example1/foo/*", "example1/bar/*"]

Errors from yaml syntax errors doesn't fail the action

Hi, we are using the v3-preview branch and accidentally had some incorrect yaml syntax in our configuration for this action:

"t: docs ๐Ÿ“š":
  - docs/*
  - docs/**/*
  - ./**/*.md
"a: test"
  - api/api/**/*

(note the missing : after "a: test".

This led to the following logged out failure from the action:

(node:29872) UnhandledPromiseRejectionWarning: TypeError: (s || "").replace is not a function
    at escapeData (/home/actions/actions-runner/_work/_actions/EmbarkStudios/labeler/v3-preview/dist/index.js:6253:10)
    at Command.toString (/home/actions/actions-runner/_work/_actions/EmbarkStudios/labeler/v3-preview/dist/index.js:6247:35)
    at issueCommand (/home/actions/actions-runner/_work/_actions/EmbarkStudios/labeler/v3-preview/dist/index.js:6210:30)
    at Object.issue (/home/actions/actions-runner/_work/_actions/EmbarkStudios/labeler/v3-preview/dist/index.js:6214:5)
    at Object.error (/home/actions/actions-runner/_work/_actions/EmbarkStudios/labeler/v3-preview/dist/index.js:9985:15)
    at /home/actions/actions-runner/_work/_actions/EmbarkStudios/labeler/v3-preview/dist/index.js:12393:18
    at Generator.throw (<anonymous>)
    at rejected (/home/actions/actions-runner/_work/_actions/EmbarkStudios/labeler/v3-preview/dist/index.js:12350:65)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
(node:29872) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:29872) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

But the action itself didn't report that it failed, it was green, which was unexpected.

The action itself should really fail and report a failure if it runs into such a fatal error

how to match path under any parent directory

Hello,

I have the following example folder structure

app/
โ””โ”€โ”€ subdir
    โ””โ”€โ”€ config
        โ””โ”€โ”€ subdir
            โ””โ”€โ”€ test.yaml

My workflow action looks like this:

name: Labeler
on: [pull_request]

jobs:
  label:

    runs-on: ubuntu-latest

    steps:
    - uses: actions/labeler@v2
      with:
        repo-token: "${{ secrets.GITHUB_TOKEN }}"

My goal is to be able to label PRs when certain files are found under certain sub-directories with the caveat that the target sub-directories may appear under any parent directory in the repo.

This labeler.yaml works and results in a label being applied, but I have to specifically name the parent directory.

config:
- app/**/config/**/*.yaml

This labeler.yaml does not work/no label is applied:

config:
- ./**/config/**/*.yaml

These 2 variants of labeler.yaml fail with a similar error:

config:
- **/config/**/*.yaml
config:
- */**/config/**/*.yaml

... where the error is:

##[error]YAMLException: unidentified alias "*/config/**/*.yaml" at line 5, column 22:
    - **/config/**/*.yaml
                         ^
##[error]unidentified alias "*/config/**/*.yaml" at line 5, column 22:
    - **/config/**/*.yaml
                         ^
##[error]Node run failed with exit code 1 

Can someone advise if what I am trying to do is possible, if so, what should the glob pattern look like?

Thanks

Labeler fails to execute due to typeError

The action fails to execute

1s
16
(node:2511) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
1
Run actions/labeler@master
4
(node:2511) UnhandledPromiseRejectionWarning: TypeError: (s || "").replace is not a function
5
    at escapeData (/home/runner/work/_actions/actions/labeler/master/dist/index.js:6454:10)
6
    at Command.toString (/home/runner/work/_actions/actions/labeler/master/dist/index.js:6448:35)
7
    at issueCommand (/home/runner/work/_actions/actions/labeler/master/dist/index.js:6411:30)
8
    at Object.issue (/home/runner/work/_actions/actions/labeler/master/dist/index.js:6415:5)
9
    at Object.error (/home/runner/work/_actions/actions/labeler/master/dist/index.js:10186:15)
10
    at /home/runner/work/_actions/actions/labeler/master/dist/index.js:4140:18
11
    at Generator.next (<anonymous>)
12
    at /home/runner/work/_actions/actions/labeler/master/dist/index.js:4099:71
13
    at new Promise (<anonymous>)
14
    at module.exports.198.__awaiter (/home/runner/work/_actions/actions/labeler/master/dist/index.js:4095:12)
15
(node:2511) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
16
(node:2511) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Different label based on new/changed/removed

I was wondering if it is either possible or desired to have a feature to: configure a label based on whether a file was newly created vs. a file was changed (vs. a file was removed).

In configuration I would imagine this could be written as follows:

"label on add":
  - on: added
  - example/**/*

"label on change":
  - on: modified
  - example/**/*

"label on remove":
  - on: removed
  - example/**/*

"label on multiple":
  - on:
    - added
    - modified
    - removed
  - example/**/*

"or if you don't care":
  - example/**/*

"and even": example/**/*

I have a working prototype at ericcornelissen/labeler (example PR added, example PR modified) which I could turn into a Pull Request for this project if there is more interest in this ๐Ÿ˜„


In practice I want to use this in simple-icons/simple-icons to label Pull Requests with either new icon or icon outdated based on whether a new icon was added or an icon was updated (respectively)

Support for issues

Something similar for issues would be fantastic. Maybe instead of a file glob a regex that gets matched against the description and title (might be configurable later on). I guess it could live under the same repo. If not, maybe a new one like issue-labeler would be good to have.

Not sure if you want to tackle this one down. I can give it a try though. Is there some easy way to test actions besides pushing them, creating a test repo and testing them there out?

And is there a way to "apply" for the actions organization once an action is ready for production? I just think that this one would really fit into the core actions you provide!

.

.

Add "blocked" label to issues / PRs?

Is there a standard action like this one, but which adds labels based on a pull request's description (or an issue's description) instead of its changed files? I'd like to automatically add a blocked label to any issue or pull request whose description includes text like "blocked on #123".

API Token

What permissions should be supplied to the api token? Very vague in the readme.

Does not work when uses is a ref

For some reason, labeler does not work when uses is a ref to this repo, but if I build the container and ref that, all is well.

# ....
action "Apply Labels" {
  # Does not work...
  # uses  = "actions/[email protected]"

  # Works
  uses  = "docker://my-own-docker-repo/issue-labeler:latest"
  needs = "On Sync"

  env = {
    LABEL_SPEC_FILE = ".github/label/spec.yml"
  }

  secrets = ["GITHUB_TOKEN"]
}

Remove labels for reverted changes

Reproducing:

  1. Change something in a file in some PR.
  2. A label will be added to the PR that matches the location of the changed file.
  3. Revert the changes on the changed file. (i.e. the PR does not contain changes in such file).
  4. The label will still be there on the PR. But it should be removed, since the PR does not affect such file anymore.

Need to rerun build and update main branch dist/index.js

Problem

In #22, it was built based on @actions/core old version and merged into main. As a result, an error like #88 occurs.

Solution

We need to rerun build and update main branch dist/index.js with @actions/core v1.2.4

Additional work to prevent recurrence

It seems possible to add the steps below to prevent a recurrence.

  1. Add prebuild script (npm install) for installing the latest dependencies in each developer's local machine. (#95)
  2. Add branch protection rule to main branch (Enable "Require branches to be up to date before merging" in "Require status checks to pass before merging") -> maybe someone possible?

Label PR based on base branch

Could the automatic labeler support more triggers than just the paths changed?

A very useful workflow for us would be set labels on the PR depending on the base branch of the PR. Depending on the Git branching workflow used in a project, this could have different use cases. For example, using the git-flow, a PR towards the development branch could be labeled as a feature and one towards master as a release.

If this feature request is implemented I imagine automatic labeling and its configuration could later be expanded to be based on branch patterns, author (if it's a robot for example) etc.

Add logging to show why a label gets assigned or not.

It would be handy if the action logged statements when a given path in PR match or doesn't rules in the file .github/labeler.yml.

For example, the action got kicked out, but no label was assigned, and based on this ๐Ÿ‘‡ it's hard to understand why.

Labeler

Remove a Label

Hi,

I am building a bot that reacts on setting of a label, adds something to a PR and is then done.

At the end of its job I would like to use this action to unlabel the label that triggered the event. Is this already possible?

starter-workflow template gives `Resource not accessible by integration`

Hi there,

I've implemented the exact Labeler workflow as the starter-workflow template in the dir path .github/workflows/label.yml.

I have also added the .github/labeler.yml file with the configuration below:

Trader: packages/trader/**/*

Bot: packages/bot/**/*

Core: packages/core/**/*

Components: packages/components/**/*

Shared: packages/shared/**/*

The action is recognised and runs on PR, however the Labeler action resolves with the following error:

##[error]HttpError: Resource not accessible by integration
##[error]Resource not accessible by integration
##[error]Node run failed with exit code 1

Googling seems to relate that error with invalid access to the repo by the action app, so I thought I'd create an issue and disable the action for now, but would be happy to know if there's something I have missed out that will be able to solve this issue for me.

Thanks.

labeler.yml example to match all repo files

I'm trying to set up a rule to apply a needs triage label for any file change in a repo, but I can't get it to work without manually specifying at least one folder in the path.

Here are some combinations I've tried without success:

needs triage:
  - '*'
needs triage:
  - '*'
  - '**/*'
needs triage:
  - ./*
  - ./**/*
needs triage:
  - '*'

It works for changes in a single folder if I provide at least part of a path, e.g.:

needs triage:
  - .github/*

Any help would be awesome!

Could not get pull request number from context, exiting

Similar to #25 I am getting the error "Could not get pull request number from context, exiting"

I tried playing around with a variety of things but could not get it to run.

.github/labeler.yml:

  # Add 'github' label to any change within the '.github' folder
github:
  - .github/*
  - .github/**/*

test:
  - lib/tests/*
  - lib/tests/**/*
  - multiview/src/test/*
  - multiview/src/test/*

.github/workflows/push.yml

on: push
name: On Push Workflow
jobs:
  triage:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/labeler@v2
      with:
        repo-token: "${{ secrets.GITHUB_TOKEN }}"

Also tried with a repo specific token. v2.1.0, and combining with another workflow - no results.

Labels are not added on a forked repository

I have a fork of cntt-n/CNTT in CsatariGergely/CNTT where I would like to test the labeler action before I propose a pr to the upsream repo. I've applied the example from the documentation with some minor changes, but no labels are added to my test pr-s and becouse of #23 I do not know why. Can you please help me to figure out if

  • Is it something my labeller.yml?
  • Is it becouse my repo is forked? There are some statements about forked repos in #12 , but I do not really understand them. In my case I would like to apply the labels of the forked repo to pr of the forked repo based on actions running in the forked repo. I see no differenve form a forked and a not forked repo in this sense.
  • Or what is it?

Thanks

Support for output

I'm using this action as one step in a multi step (job actually) workflow. I would like to have this action label PRs based on the files changed, but subsequently assign reviewers based on those labels. Here is a sample of my workflow:

name: "PR Review Assigner"
on:
  - pull_request

jobs:
  label:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/labeler@v2
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          configuration-path: ".github/workflows/pr-review-assign/labeler.yml"
  assign-reviewers:
    needs: label
    runs-on: ubuntu-latest
    steps:
      - name: "Print event"
        env:
          EVENT_CONTEXT: ${{ toJson(github.event.pull_request.labels) }}
        run: echo "$EVENT_CONTEXT"
      - name: "Assign NodeJS Review Candidate Team"
        if: contains(github.event.pull_request.labels.*.name, 'nodejs-pr')
        uses: kentaro-m/[email protected]
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          configuration-path: ".github/workflows/pr-review-assign/nodejs-pr.yml"
      - name: "Assign App Review Candidate Team"
        if: contains(github.event.pull_request.labels.*.name, 'app-pr')
        uses: kentaro-m/[email protected]
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          configuration-path: ".github/workflows/pr-review-assign/app-pr.yml"
      - name: "Assign Editor Review Candidate Team"
        if: contains(github.event.pull_request.labels.*.name, 'editor-pr')
        uses: kentaro-m/[email protected]
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"
          configuration-path: ".github/workflows/pr-review-assign/editor-pr.yml"

The problem here is that the github.event.pull_request object is created before the entire workflow runs and is not updated when this specific action runs. So github.event.pull_request.labels is not affected by this action.

One solution would be for this action to produce an output of the labels changed (or better yet, the labels of the PR) so that it can be used in subsequent jobs that run sequentially.

Thanks!

v3-preview vs v2.2.0

Just wondering if v2.2.0 is the newest? or is using v3-preview going to give the latest features?

HttpError: Not Found when run with new yml config

I tried to use the labeler with the new YML syntax and it seems there is an issue on how the labeler is published. I always get the following msg.
I tested the v2 and v2.0.0 releases

Run actions/[email protected]
  with:
    repo-token: ***
    configuration-path: .github/labeler.yml
##[error]HttpError: Not Found
##[error]Not Found
##[error]Node run failed with exit code 1
name: "Pull Request Labeler"
on: pull_request

jobs:
  label:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/[email protected]
      with:
        repo-token: "${{ secrets.GITHUB_TOKEN }}"

Support for necessary files touched

It would be nice to have support for files/folders that need to be changed on a PR. The most prominent example would be tests.

Whenever a PR gets created that does not have touched files in test/**/* or spec/**/* or **/*.spec/js globs a label gets added.

necessary:
  "Need Tests": spec/**/*

This, but for projects?

Is there an action like this one, but which assigns pull requests to a project based on the files it touches?

Add labels based of the pull request author

I have a use-case with a common repository in which many different teams are contributing and I would like to set a label based on team the person belongs to.

The way I see it can be done is very similar to the file globs, but need to somehow distinguish between file globs and user handles:

label-to-apply:
 - user1
 - user2
 - user3

Issue of the label configuration file ".github/labeler.yml"

Associated GitHub Community ticket: https://github.community/t/labeler-typeerror-glob-pattern-string-required/133467

According to the README of this action, the following configurations in the label configuration file should work:

label-1:
  - any: ['list', 'of', 'globs']
    all: ['list', 'of', 'globs']

label-2:
  - example1/*
  - example2/**/*

I tested with two label configuration files in my repository (see here).

  • .github/labeler-01.yml
    common:
      - any: ['./*', './src/**']
    
    workflow:
      - any: ['.github/workflows/**']
  • .github/labeler-02.yml
    repo:
      - './*'
      - './src/**'
    
    GHA:
      - '.github/**'

And my workflow looks like this (see here):

name: CI

on: pull_request

jobs:
  job1:
    runs-on: ubuntu-latest
    steps:         
      - name: PR Labeler
        uses: actions/[email protected]
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          configuration-path: .github/labeler-01.yml

  job2:
    runs-on: ubuntu-latest
    steps:         
      - name: PR Labeler
        uses: actions/[email protected]
        with:
          repo-token: ${{ secrets.GITHUB_TOKEN }}
          configuration-path: .github/labeler-02.yml

I changed the following files:

  • ./.github/workflows/ci.yml
  • ./test.txt
  • ./src/test.txt

However, finally only the GHA label was added successfully, the other three should also be added but not (see the example PR).

When using '.github/labeler-01.yml', the actions always fails with the error (see job1):

##[error]TypeError: glob pattern string required
##[error]glob pattern string required

When using '.github/labeler-02.yml', the action displays as success, but only the GHA label is added (see job2).

Label PR based

Thank you ๐Ÿ™‡โ€โ™€ for wanting to create an issue in this repository. Before you do, please ensure you are filing the issue in the right place. Issues should only be opened on if the issue relates to code in this repository.

If your issue is relevant to this repository, please delete this text and continue to create this issue. Thank you in advance.

File limit right now defaults to 30

I found actions/labeler is using client.pulls.listFiles which has a page size of 30 files.

This means that for bigger PRs this won't assign labels properly because it won't consider all files. I get that there must be a limit because this could be very expensive otherwise. But the failure mode is surprising.

I would suggest increasing the page size to 100 (the limit of the Github API) and check if there are more files than a page, then it should emit a warning and not assign any label at all.

Thoughts?
Thanks!

Fails on Forks

It seems that when we have incoming pr's from a fork it fails to run.

See this pr

.

.

Labeler assigning wrong label

I'm not sure if my yml file is wrong or something but labeller seems to be assigning the backend label to everything.

Here's my file: .github/labeler.yml

npm:
  - package.json
  - package-lock.json

pip:
  - requirements.txt
  - requirements-dev.txt

dependencies:
  - package.json
  - package-lock.json
  - requirements.txt
  - requirements-dev.txt

frontend:
  - 'assets/**/*'
  - 'trainerdex/templates/**/*'
  - 'trainerdex/static/**/*'

backend:
  - 'community/admin.py'
  - 'community/models.py'
  - 'config/settings.py'
  - 'config/urls.py'
  - 'trainerdex/api/**/*'
  - 'trainerdex/admin.py'
  - 'trainerdex/urls.py'
  - 'trainerdex/models.py'
  - '!trainerdex/pogo_assets/strings.py'
  - '!static/pogo_assets/**/*'

migrations:
  - 'community/migrations/*'
  - 'trainerdex/migrations/*'

As you can see for TrainerDex/Website#55, labeler assigned backend to a PR that only changed package.json and package-lock.json.

Is my config wrong?

No label added to PR

Hello I do believe the issue is relevant because it seems to me this is a bug. I apologise if this is not really. But I create a .github/workflows/labeler.yml for the workflow and another .github/labeler.yml defining the labels but the PR's are not labeled even though the check passes.

.github/labeler.yml

repo:
  - ./*

feature:
  - talos/*

documentation:
  - ./*.md

.github/workflows/labeler.yml

name: PR Labeler
on:
  pull_request:
    types: [opened]

jobs:
  triage:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/labeler@v2
        with:
          repo-token: "${{ secrets.GITHUB_TOKEN }}"

How to make the labeler.yml is unclear

Please add a more robust example in the readme. It's unclear what the relationship between example and those other files is...

I would suggest using file paths fortis repo to make the example more relevant.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.