Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workflows - Add workflow for automatically labeling PRs #1972

Merged
merged 2 commits into from
Jan 22, 2025
Merged
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
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/**'
ozgur00 marked this conversation as resolved.
Show resolved Hide resolved
- '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
Loading