Skip to content

Commit ed905cb

Browse files
committed
fix: ensure PR number is provided for Copilot commit reassignment workflow
1 parent 3486d46 commit ed905cb

File tree

1 file changed

+61
-5
lines changed

1 file changed

+61
-5
lines changed
Lines changed: 61 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,69 @@
1+
2+
13
name: Reassign Copilot Commit
24

35
on:
6+
pull_request:
7+
types: [opened, synchronize, reopened]
48
workflow_dispatch:
5-
# pull_request_target:
6-
# types: [closed]
9+
inputs:
10+
pr_number:
11+
description: 'Pull request number to check (for debugging)'
12+
required: false
13+
type: string
14+
branch:
15+
description: 'Branch to checkout (for debugging)'
16+
required: false
17+
type: string
718

819
jobs:
9-
reassign-copilot-commits:
20+
check-copilot-commits:
1021
runs-on: ubuntu-latest
1122
steps:
12-
- name: Log dummy message
13-
run: echo "I am working fine with the branch"
23+
- name: Checkout PR code
24+
uses: actions/checkout@v4
25+
with:
26+
fetch-depth: 0
27+
ref: ${{ github.event.inputs.branch || github.head_ref || github.ref_name }}
28+
29+
- name: Get PR number
30+
id: prnum
31+
run: |
32+
if [ -n "${{ github.event.inputs.pr_number }}" ]; then
33+
echo "PR_NUMBER=${{ github.event.inputs.pr_number }}" >> $GITHUB_ENV
34+
elif [ -n "${{ github.event.pull_request.number }}" ]; then
35+
echo "PR_NUMBER=${{ github.event.pull_request.number }}" >> $GITHUB_ENV
36+
else
37+
echo "::error::PR number not found. Provide pr_number input or run on PR event."
38+
exit 1
39+
fi
40+
41+
- name: Get PR commits
42+
id: commits
43+
run: |
44+
COMMITS=$(gh pr view $PR_NUMBER --json commits -q '.commits[].oid')
45+
echo "COMMITS=$COMMITS" >> $GITHUB_ENV
46+
echo "$COMMITS" > commits.txt
47+
48+
- name: Check for Copilot as author
49+
id: check_copilot
50+
run: |
51+
COPILOT_EMAILS="github-actions[bot]@users.noreply.github.com\[email protected]\[email protected]"
52+
FOUND=0
53+
for COMMIT in $(cat commits.txt); do
54+
AUTHOR_EMAIL=$(git show -s --format='%ae' $COMMIT)
55+
for EMAIL in $COPILOT_EMAILS; do
56+
if [ "$AUTHOR_EMAIL" = "$EMAIL" ]; then
57+
FOUND=1
58+
break
59+
fi
60+
done
61+
done
62+
echo "COPILOT_FOUND=$FOUND" >> $GITHUB_ENV
63+
echo "found=$FOUND" >> $GITHUB_OUTPUT
64+
65+
- name: Fail if Copilot is author
66+
if: steps.check_copilot.outputs.found == '1'
67+
run: |
68+
echo "❌ Copilot is the author of one or more commits in this PR. Please rebase and change the commit author to yourself before merging."
69+
exit 1

0 commit comments

Comments
 (0)