Giter Club home page Giter Club logo

labeler-action's Introduction

labeler-action

GitHub Action allowing for applying labels to issues and pull requests based on patterns found in the title or description.

NOTE Thanks to the awesome efforts from the people at GitHub, v2 and later support labeling from forked repositories via the pull_request_target event.

Usage

Define .github/labeler.yml

This action requires a configuration file defined at .github/labeler.yml in your repository. The contents must follow either the simple schema or the full schema shown below.

NOTE The file must exist on your release branch (e.g. master, main, etc.).

Feel free to use one of the following schema examples to get started.

Simple Schema

# labeler "simple" schema
# Comment is applied to both issues and pull requests.
# If you need a more robust solution, consider the "full" schema.
comment: |
  ๐Ÿ‘ Thanks for this!
  ๐Ÿท I have applied any labels matching special text in your issue.

  Please review the labels and make any necessary changes.

# Labels is an object where:
# - keys are labels
# - values are array of string patterns to match against title + body in issues/prs
labels:
  'bug':
    - '\bbug[s]?\b'
  'help wanted':
    - '\bhelp( wanted)?\b'
  'duplicate':
    - '\bduplicate\b'
    - '\bdupe\b'
  'enhancement':
    - '\benhancement\b'
  'question':
    - '\bquestion\b'

Full Schema

# labeler "full" schema

# enable labeler on issues, prs, or both.
enable:
  issues: true
  prs: true
# comments object allows you to specify a different message for issues and prs

comments:
  issues: |
    Thanks for opening this issue!
    I have applied any labels matching special text in your title and description.

    Please review the labels and make any necessary changes.
  prs: |
    Thanks for the contribution!
    I have applied any labels matching special text in your title and description.

    Please review the labels and make any necessary changes.

# Labels is an object where:
# - keys are labels
# - values are objects of { include: [ pattern ], exclude: [ pattern ] }
#    - pattern must be a valid regex, and is applied globally to
#      title + description of issues and/or prs (see enabled config above)
#    - 'include' patterns will associate a label if any of these patterns match
#    - 'exclude' patterns will ignore this label if any of these patterns match
labels:
  'bug':
    include:
      - '\bbug[s]?\b'
    exclude: []
  'help wanted':
    include:
      - '\bhelp( me)?\b'
    exclude:
      - '\b\[test(ing)?\]\b'
  'enhancement':
    include:
      - '\bfeat\b'
    exclude: []

Create a Workflow

The action requires a single input parameter: GITHUB_TOKEN. This token allows the action to access the GitHub API for your account. Workflows automatically provide a default GITHUB_TOKEN, which provides full API access. You create a secret from a new token with public_repo scope to limit the action's footprint.

NOTE Binding to issue or pull_request edit actions is not recommended.

Create a workflow definition, for example .github/workflows/community.yml:

name: Community
on: 
  issues:
    types: [opened, edited, milestoned]
  pull_request_target:
    types: [opened]

jobs:

  labeler:
    runs-on: ubuntu-latest

    steps:
    - name: Check Labels
      id: labeler
      uses: jimschubert/labeler-action@v2
      with:
        GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

Notice that the PR event is pull_request_target rather than pull_request. The difference is that pull_request_target is a newer event which runs in the context of the base repository, allowing access to the secrets necessary to label the pull request. If you use pull_request, the action will be able to label pull requests originating from the same repository (i.e. no forks!).

License

This project is licensed under Apache 2.0

labeler-action's People

Contributors

jimschubert 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

Watchers

 avatar  avatar

labeler-action's Issues

[Question] No file named labeler.yml found in .github, but file is there

What is your question?
Hi, I really would like to use your awesome github action, but I just get a error:
level=fatal msg="Failed to execute No file named labeler.yml found in .github" when the action tries to run, and I don't get why, as the file is there, with the name "labeler.yml".

Where did you look before asking here?
https://github.com/jimschubert/labeler
https://github.com/marketplace/actions/auto-labeler
Additional context
Fist I added my own code, but in a second try I just tried to run the exact code from your Readme and the marketplace section. In both cases got the labeler.yml not found in .github/ folder.

Thank you!

[bug] Action cannot find labeler.yml config file

Describe the bug
I've set up the workflow, config file, and submitted several PRs to try testing out the action, only to encounter a "Failed to execute No file named labeler.yml found in .github" error when the action runs

To Reproduce
Steps to reproduce the behavior:

  1. Set up the labeler action (add workflow, add config file)
  2. Submit a test PR
  3. Notice that the labeler action fails

Expected behavior
The correct labels are added

Screenshots
Screen Shot 2021-12-22 at 22 33 03

Additional context
My files are set up as follows right now:

repo/.github/workflows/pr-labeler.yml

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

jobs:
  labeler:
    runs-on: ubuntu-latest
    permissions:
      contents: read
      pull-requests: write
    steps:
      - name: Checkout
        uses: actions/checkout@v2

      - name: Auto Label PR
        id: labeler
        uses: jimschubert/labeler-action@v2
        with:
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

repo/.github/labeler.yml

enable:
  issues: false
  prs: true

labels:
  'bugfix':
    include:
      - '\[(bug|BUG|bugfix|BUGFIX)\]'
    exclude: [ ]
  'mobile':
    include:
      - '\[((platform-|PLATFORM-)?(mobile|MOBILE))\]'
    exclude: [ ]
  'platform':
    include:
      - '\[((platform|PLATFORM)(-server|-SERVER)?)\]'
    exclude: [ ]
  'web':
    include:
      - '\[(web|WEB|platform-client|PLATFORM-CLIENT)\]'
    exclude: [ ]

I definitely see the labeler.yml file in the PR, so I'm not sure why this is failing. I changed it to use pull_request as the only PRs coming in are from our own org, so we don't have to worry about forks. I've also tried this without limiting the perms as I do above to rule that out, and that was still failing.

[bug] not working as expected

Describe the bug
A clear and concise description of what the bug is, including version(s) affected.
jimschubert/labeler-action@v2

To Reproduce
Steps to reproduce the behavior:

  1. The labeller was supposed to apply the helm label ONLY when it detected /helm as per this config we gave it.
  2. If you look at this issue it applied the label even though the issue just had the word helm and not /helm.
  3. Similarly in this repo it was supposed to apply the bug label when /bug was detected.
  4. But if you see this issue, it is not applying the label.

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
Add any other context about the problem here.

[bug] malformed GET error on parsing organization issues

Describe the bug
Upon making an issue or a PR to an organization repo with this enabled, the action experiences a HTTP 404 error caused by the GET.
I believe this is because the GET is malformed, inserting the author name where it should not.
I tried forking this repo and commenting out the following to no avail:

repo = strings.Replace(repo, owner+ "/", "", 1)

The specific error message is this:
"Failed to execute GET https://api.github.com/repos/ISSUE_OPENER/ORG_NAME/REPO_NAME/contents/.github?ref=master: 404 Not Found []"
For an example, please see here.

To Reproduce
Steps to reproduce the behavior:

  1. Open an issue on an organization with this enabled.
  2. Notice you have a failing action.

Expected behavior
For the GET to not insert the author's name.

Screenshots
image

Add ability to change config path

Is your feature request related to a problem? Please describe.

actions/labeler project also uses labeler.yml config by default. Their config based on change's path and has another sintax.
If I wanna to use both actions together I need to set config path manually due to conflict.
actions/labeler has ability to change path, but it is a little bit strange to have configs named like
labeler.yml - for labeler-action
labeler-suffix.yml - for labeler

Describe the solution you'd like

I would prefer to have ability to change path for labeler-action.

Describe alternatives you've considered

As alternative - change default config path to full action name: labeler-action.yml

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.