Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
91 changes: 90 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ This GitHub Action checks that the PR title adheres to the [Conventional Commits
- `task_types` (required): An array of task types. Example: `["feat","fix","docs","test","ci","refactor","perf","chore","revert"]`.
- `ticket_key_regex` (optional): Regular expression to match issue number in PR title. Default is not validating. Example: `"^PROJECT-\\d{2,5}$"`.
- `add_label` (optional): Whether to add labels. Default is `'true'`.
- `custom_labels` (optional): A JSON string mapping task types to custom label names. Example: `{"feat": "feature", "fix": "fix", "docs": "documentation", "test": "test", "ci": "CI/CD", "refactor": "refactor", "perf": "performance", "chore": "chore", "revert": "revert", "wip": "WIP"}`.
- `custom_labels` (optional): A JSON string mapping task types to custom label names. Example: `{"feat": "feature", "fix": "fix", "docs": "documentation", "test": "test", "ci": "CI/CD", "refactor": "refactor", "perf": "performance", "chore": "chore", "revert": "revert", "wip": "WIP"}`. Cannot be used together with `label_map`.
- `label_map` (optional): A YAML map of task types to custom label names. Alternative to `custom_labels` with YAML syntax. Cannot be used together with `custom_labels`.
- `add_scope_label` (optional): Whether to add scope labels. Default is `'false'`.
- `add_scope_label_only_existing` (optional): Only apply scope labels if they already exist in the repository (do not create new labels). Default is `'false'`.
- `add_scope_label_map` (optional): A YAML map of scopes to custom label names. Allows mapping scope values to different label names.

### Labeling Pull Requests
When a pull request title adheres to the Conventional Commits specification, this action can automatically label the pull request based on the task type. Labels provide filtering PRs by a label, a visual indication of the nature of changes, aiding in organizing and prioritizing PR reviews.
Expand Down Expand Up @@ -170,6 +174,91 @@ jobs:
For this configuration, the following PR title is valid: `feat: PROJECT-12345 add new feature`.
**The PR will be labeled as `feature`.**

## Example Usage with label_map (YAML alternative to custom_labels)

This configuration uses `label_map` instead of `custom_labels` for a cleaner YAML syntax. Note that you cannot use both `custom_labels` and `label_map` together.

```yaml
name: PR Conventional Commit Validation

on:
pull_request:
types: [opened, synchronize, reopened, edited]

jobs:
validate-pr-title:
runs-on: ubuntu-latest
steps:
- name: PR Conventional Commit Validation
uses: ytanikin/[email protected]
with:
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert"]'
label_map: |
feat: feature
fix: bugfix
docs: documentation
ci: 'CI/CD'
perf: performance
```

For this configuration, a PR with title `feat: add new feature` will be labeled with `feature` instead of `feat`.

## Example Usage with scope label mapping

This configuration maps scopes to custom label names. This is useful when you want to use different label names than the scope itself.

```yaml
name: PR Conventional Commit Validation

on:
pull_request:
types: [opened, synchronize, reopened, edited]

jobs:
validate-pr-title:
runs-on: ubuntu-latest
steps:
- name: PR Conventional Commit Validation
uses: ytanikin/[email protected]
with:
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert"]'
add_scope_label: 'true'
add_scope_label_map: |
vis: visualization
'@exploreomni/builder': 'expernicorns'
builder: 'expernicorns'
```

For this configuration, a PR with title `feat(vis): add chart` will be labeled with `visualization` instead of `vis`.

## Example Usage with scope label mapping and only existing labels

This configuration maps scopes to custom label names and only applies labels that already exist in the repository.

```yaml
name: PR Conventional Commit Validation

on:
pull_request:
types: [opened, synchronize, reopened, edited]

jobs:
validate-pr-title:
runs-on: ubuntu-latest
steps:
- name: PR Conventional Commit Validation
uses: ytanikin/[email protected]
with:
task_types: '["feat","fix","docs","test","ci","refactor","perf","chore","revert"]'
add_scope_label: 'true'
add_scope_label_only_existing: 'true'
add_scope_label_map: |
vis: visualization
builder: 'expernicorns'
```

For this configuration, the label will only be applied if it already exists in the repository. This prevents the action from creating new labels.

### Troubleshooting

- If you encounter an error message: `Error: Resource not accessible by integration`, adjust your repository settings. Go to your repository's settings, navigate to the "Actions" tab, and under the "General" section, update the "Workflow permissions" setting to "Read and Write Permission". This grants the necessary permissions for the action to function correctly.
Expand Down
14 changes: 14 additions & 0 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,31 @@ inputs:
description: 'Whether to add labels'
required: false
default: 'true'
fail_on_non_conventional:
description: 'Whether to fail the job if the PR title is not conventional. If false, the action will only log warnings.'
required: false
default: 'true'
add_scope_label:
description: 'Whether to add scope labels, such login for the title "fix(login): fix message in login page'
required: false
default: 'false'
add_scope_label_only_existing:
description: 'Only apply scope labels if they already exist in the repository (do not create new labels)'
required: false
default: 'false'
add_scope_label_map:
description: 'A YAML map of scopes to custom label names. Example: "vis: visualization"'
required: false
token:
description: 'GitHub token for applying labels.'
required: false
default: ${{ github.token }}
custom_labels:
description: 'A JSON string mapping task types to custom label names. Example: {"feat": "feature", "fix": "fix", "docs": "documentation", "test": "test", "ci": "CI/CD", "refactor": "refactor", "perf": "performance", "chore": "chore", "revert": "revert", "wip": "WIP"}'
required: false
label_map:
description: 'A YAML map of task types to custom label names. Alternative to custom_labels with YAML syntax. Cannot be used together with custom_labels.'
required: false
runs:
using: 'node20'
main: 'dist/index.js'
Expand Down
25 changes: 25 additions & 0 deletions dist/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -523,6 +523,31 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.


js-yaml
MIT
(The MIT License)

Copyright (C) 2011-2015 by Vitaly Puzrin

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.


lodash
MIT
Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
Expand Down
Loading
Loading