generated from backstagephp/laravel-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 0
78 lines (70 loc) · 2.92 KB
/
pr-auto-assign.yml
File metadata and controls
78 lines (70 loc) · 2.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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@v8
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@v8
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`);
}