-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1972 from Adyen/chore/add_pr_label
Workflows - Add workflow for automatically labeling PRs
- Loading branch information
Showing
4 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
name: Add Label to the Pull Request | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
branches: | ||
- 'main' | ||
- 'feature/**' | ||
- 'chore/**' | ||
- 'fix/**' | ||
- 'hotfix/**' | ||
|
||
jobs: | ||
get_label: | ||
if: startsWith(github.event.pull_request.head.ref, 'feature/') || startsWith(github.event.pull_request.head.ref, 'fix/') || startsWith(github.event.pull_request.head.ref, 'chore/') | ||
runs-on: ubuntu-latest | ||
outputs: | ||
label: ${{ steps.get_label.outputs.label }} | ||
|
||
steps: | ||
- name: Checkout to current branch | ||
uses: actions/checkout@v3 | ||
|
||
- name: Get label | ||
id: get_label | ||
run: | | ||
chmod +x scripts/generate_pr_label.sh | ||
branch_name="${{github.event.pull_request.head.ref}}" | ||
LABEL=$(./scripts/generate_pr_label.sh $branch_name) | ||
echo -e "label=$LABEL" >> $GITHUB_OUTPUT | ||
echo -e $LABEL | ||
add_label_to_pr: | ||
needs: get_label | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Checkout to current branch | ||
uses: actions/checkout@v3 | ||
|
||
- name: Add label | ||
uses: actions/github-script@v6 | ||
env: | ||
LABEL: ${{ needs.get_label.outputs.label }} | ||
with: | ||
github-token: ${{ secrets.ADYEN_AUTOMATION_BOT_ACCESS_TOKEN }} | ||
script: | | ||
github.rest.issues.addLabels({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
issue_number: context.payload.pull_request.number, | ||
labels: ['${{ env.LABEL }}'] | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
# | ||
# Copyright (c) 2025 Adyen N.V. | ||
# | ||
# This file is open source and available under the MIT license. See the LICENSE file for more info. | ||
# | ||
# Created by ozgur on 21/1/2025. | ||
# | ||
function generate_pr_label() { | ||
if [ "$#" -ne 1 ]; then | ||
echo "Usage: $0 <branch_name>" >&2 | ||
exit 1 | ||
fi | ||
branch_name=$1 | ||
|
||
# Check if the string starts with a specific prefix | ||
if [[ "$branch_name" == feature/* ]]; then | ||
label="Feature" | ||
elif [[ "$branch_name" == fix/* ]]; then | ||
label="Fix" | ||
elif [[ "$branch_name" == chore/* ]]; then | ||
label="Chore" | ||
else | ||
echo "Branch name is not valid. It should start with feature/, fix/, chore/ or renovate/" >&2 | ||
exit 1 | ||
fi | ||
|
||
echo "$label" | ||
} | ||
|
||
generate_pr_label $1 |