The Auto label action will check for every new issue and automatically adds a label based on the body of the issue. This means that finding specific issues will be much easier.
Add a file to .github/workflows/auto-label.yml
name: Labeling new issue
on:
issues:
types: ['opened']
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
sparse-checkout: |
.github/workflows/auto-label.json5
sparse-checkout-cone-mode: false
- uses: Renato66/auto-label@v3
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
Add a config file to .github/workflows/auto-label.json5
// see inputs for more examples
{
labelsSynonyms: {
bug: ['error', 'need fix', 'not working'],
enhancement: ['upgrade'],
question: ['help', 'how can i']
},
labelsNotAllowed: [
'documentation',
'duplicate',
'good first issue',
'help wanted',
'invalid'
],
defaultLabels: ['triage'],
ignoreComments: true
}
Name | Description | Required | Default | Examples |
---|---|---|---|---|
repo-token | GitHub token for the repository | true | - | ... |
configuration-file | Configuration file path | false | .github/workflows/auto-label.json5 | ... |
ignore-comments | Ignore labels inside issue comments | false | true | ... |
labels-synonyms | Text synonyms for labels | false | - | ... |
labels-not-allowed | Labels to ignore | false | - | ... |
include-title | Include title in labels search | false | true | ... |
default-labels | Labels that will always be set | false | - | ... |
failover-labels | Labels to set when no labels found | false | - | ... |
Repo token is provided automatically by GitHub; just need to add
repo-token: ${{ secrets.GITHUB_TOKEN }}
Configuration file can be created at any place at your repository, it will need another action to get the file like:
- uses: actions/checkout@v4
with:
sparse-checkout: |
.github/workflows
and it will look for any file named auto-label
with the extension JSON
or JSON5
or JSONC
but you can also define a specific extension
- uses: actions/checkout@v4
with:
sparse-checkout: |
.github/workflows/auto-label.json5
sparse-checkout-cone-mode: false
to set another place to store your configuration file, you should checkout and point with configuration-file
input:
- uses: actions/checkout@v4
with:
sparse-checkout: |
src/actions/configuration.json
sparse-checkout-cone-mode: false
- uses: Renato66/auto-label@v3
with:
configuration-file: 'src/actions/configuration.json'
If you want to change who added the labels, you can provide a user token
The token will only need the public_repo
scope
You will need to provide it as secret GITHUB_USER_TOKEN
and update the issue.yml repo-token with:
repo-token: ${{ secrets.GITHUB_USER_TOKEN }}
If you prefer to leave as default (true) You can provide a list of labels in a template for the author to choose which labels are available to pick But if you prefer to set it as false, the author can set the labels inside a comment so it doesn't appear on issue body
// .github/workflows/auto-label.json5
{
"ignoreComments": true
}
yml (deprecating)
ignore-comments: true
You can set a custom part of your issue/pr to be labeled using this structure:
Some text that could have a label that wouldn't be set
<!-- AUTO-LABEL:START -->
Another text that could have a label and will be set as a label
<!-- AUTO-LABEL:END -->
thanks to @dielduarte and @PauloGoncalvesBH
Sometimes labels can be set upon other texts, as an example, if you have a label like C: VCombobox
it would be hard to match the label in a normal issue, but you can provide a JSON to set it synonyms:
// .github/workflows/auto-label.json5
{
"labelsSynonyms": {"C: VCombobox": ["combobox", "v-combobox", "combo box"]}
}
yml (deprecating)
labels-synonyms: '{"C: VCombobox":["combobox","v-combobox","combo box"]}'
Some labels are restricted to repo owners such as needs priority
testing
won't fix
they can be set in an Array form:
// .github/workflows/auto-label.json5
{
"labelsNotAllowed": ["needs priority", "testing", "won't fix"]
}
yml (deprecating)
labels-not-allowed: '["needs priority","testing","won't fix"]'
Labels that will always be set when an issue is created/updated such as triage
, they can be set in an Array form:
// .github/workflows/auto-label.json5
{
"defaultLabels": ["needs priority", "testing", "won't fix"]
}
yml (deprecating)
default-labels: '["triage"]'
If you want to exclude the title in the labels search, you can set it as false:
// .github/workflows/auto-label.json5
{
"includeTitle": false
}
yml (deprecating)
include-title: false
Labels that will be set when an issue is created/updated they no labels found in the text, they will be set even if default labels are set they can be set in an Array form:
// .github/workflows/auto-label.json5
{
"failoverLabels": ["need more information"]
}
yml (deprecating)
failover-labels: '["need more information"]'
To add a badge simple replace , and name:
[![Auto Label](https://img.shields.io/github/actions/workflow/status/<OWNER>/<REPOSITORY>/<FILE-NAME>.yml?logo=github&label=Auto%20Label)](https://github.com/Renato66/auto-label)