Skip to content
Merged
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
78 changes: 78 additions & 0 deletions .github/workflows/pr-auto-assign.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
name: PR Auto Assignment and Labeling

on:
pull_request:
types: [opened, edited]

jobs:
auto-assign-and-label:
runs-on: ubuntu-latest
permissions:
pull-requests: write
issues: write
steps:
- name: Get branch name
id: branch
run: echo "branch_name=${GITHUB_HEAD_REF}" >> $GITHUB_OUTPUT

- name: Determine label based on branch prefix or author
id: label
run: |
# Check if it's a Dependabot PR (using the PR author, not the workflow actor)
if [[ "${{ github.event.pull_request.user.login }}" == "dependabot[bot]" ]]; then
echo "label=dependencies" >> $GITHUB_OUTPUT
# Check branch prefixes
elif [[ "${{ github.head_ref }}" == feature/* ]] || [[ "${{ github.head_ref }}" == feat/* ]]; then
echo "label=enhancement" >> $GITHUB_OUTPUT
elif [[ "${{ github.head_ref }}" == fix/* ]]; then
echo "label=fix" >> $GITHUB_OUTPUT
elif [[ "${{ github.head_ref }}" == docs/* ]]; then
echo "label=documentation" >> $GITHUB_OUTPUT
else
echo "label=" >> $GITHUB_OUTPUT
fi

- name: Add label to PR
if: steps.label.outputs.label != ''
uses: actions/github-script@v7
with:
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ['${{ steps.label.outputs.label }}']
})

- name: Assign reviewer and assignee
uses: actions/github-script@v7
with:
script: |
const assignee = 'baspa';
const prAuthor = context.payload.pull_request.user.login;

console.log(`PR Author: ${prAuthor}`);
console.log(`Assignee: ${assignee}`);
console.log(`Are they the same? ${prAuthor.toLowerCase() === assignee.toLowerCase()}`);

// Always assign as assignee (you can be assigned to your own PR)
github.rest.issues.addAssignees({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
assignees: [assignee]
});
console.log(`Assigned ${assignee} as assignee`);

// Only assign reviewer if they are not the PR author (case-insensitive comparison)
if (prAuthor.toLowerCase() !== assignee.toLowerCase()) {
github.rest.pulls.requestReviewers({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: context.issue.number,
reviewers: [assignee]
});
console.log(`Assigned ${assignee} as reviewer`);
} else {
console.log(`Skipping reviewer assignment - ${assignee} is the PR author`);
}
Loading