Skip to content

Commit

Permalink
Merge pull request #1972 from Adyen/chore/add_pr_label
Browse files Browse the repository at this point in the history
Workflows - Add workflow for automatically labeling PRs
  • Loading branch information
ozgur00 authored Jan 22, 2025
2 parents e71d008 + 61b40e1 commit 2052561
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
[//]: # (If this is a bug fix: include a reproduction path)

## Checklist <!-- Remove any line that's not applicable -->
- [ ] PR is labelled <!-- Breaking change, Feature, Fix, Dependencies or Chore -->
- [ ] If applicable, make sure Breaking change label is added.
- [ ] Code is unit tested
- [ ] Changes are tested manually
- [ ] Related issues are linked
Expand Down
54 changes: 54 additions & 0 deletions .github/workflows/add_pr_label.yml
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 }}']
})
2 changes: 1 addition & 1 deletion .github/workflows/check_labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: Check Labels
# Every PR should have a label and some labels should include an update to the release notes
on:
pull_request:
types: [ synchronize, labeled, unlabeled ]
types: [ synchronize, labeled, unlabeled, edited ]

concurrency:
group: ${{ github.workflow }}-${{ github.head_ref }}
Expand Down
32 changes: 32 additions & 0 deletions scripts/generate_pr_label.sh
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

0 comments on commit 2052561

Please sign in to comment.