Skip to content

Commit 00a38bd

Browse files
committed
fix: update branch and user info handling in reassign copilot commits workflow
1 parent d4d9829 commit 00a38bd

File tree

1 file changed

+12
-19
lines changed

1 file changed

+12
-19
lines changed

.github/workflows/reassign-copilot-commits.yml

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -26,20 +26,20 @@ jobs:
2626
env:
2727
GH_TOKEN: ${{ secrets.GH_PAT }}
2828
run: |
29-
# Default to event branch
30-
BRANCH="${{ github.event.pull_request.head.ref }}"
31-
# If workflow_dispatch and pr_number is set, get branch from PR
29+
BRANCH=""
3230
if [ "${{ github.event_name }}" = "workflow_dispatch" ] && [ -n "${{ github.event.inputs.pr_number }}" ]; then
33-
BRANCH=$(gh pr view ${{ github.event.inputs.pr_number }} --json headRefName -q '.headRefName')
31+
BRANCH=$(gh pr view ${{ github.event.inputs.pr_number }} --repo elastic/kibana --json headRefName -q '.headRefName')
32+
elif [ -n "${{ github.event.pull_request.head.ref }}" ]; then
33+
BRANCH="${{ github.event.pull_request.head.ref }}"
3434
fi
35-
echo "BRANCH=$BRANCH" >> $GITHUB_ENV
35+
echo "branch=$BRANCH" >> $GITHUB_OUTPUT
3636
echo "Branch to checkout: $BRANCH"
3737
3838
- name: Checkout PR code
3939
uses: actions/checkout@v4
4040
with:
4141
fetch-depth: 0
42-
ref: ${{ env.BRANCH }}
42+
ref: ${{ steps.setbranch.outputs.branch }}
4343

4444
- name: Get PR number
4545
id: prnum
@@ -93,36 +93,29 @@ jobs:
9393
env:
9494
GH_TOKEN: ${{ secrets.GH_PAT }}
9595
run: |
96-
# Default to workflow_dispatch actor
9796
USER_LOGIN="${{ github.actor }}"
9897
USER_EMAIL=""
9998
USER_NAME=""
100-
# If PR event, get the user who labeled the PR
10199
if [ "${{ github.event_name }}" = "pull_request" ]; then
102100
USER_LOGIN="${{ github.event.sender.login }}"
103101
fi
104-
# Try to get user email and name from GitHub API
105102
USER_API=$(gh api users/$USER_LOGIN)
106103
USER_NAME=$(echo "$USER_API" | jq -r '.name // .login')
107104
USER_EMAIL=$(echo "$USER_API" | jq -r '.email')
108-
# Fallback if email is not public
109105
if [ -z "$USER_EMAIL" ] || [ "$USER_EMAIL" = "null" ]; then
110106
USER_EMAIL="[email protected]"
111107
fi
112-
echo "USER_NAME=$USER_NAME" >> $GITHUB_ENV
113-
echo "USER_EMAIL=$USER_EMAIL" >> $GITHUB_ENV
108+
echo "user_name=$USER_NAME" >> $GITHUB_OUTPUT
109+
echo "user_email=$USER_EMAIL" >> $GITHUB_OUTPUT
114110
echo "Using author: $USER_NAME <$USER_EMAIL>"
115-
echo "USER_LOGIN=$USER_LOGIN"
116-
echo "USER_NAME=$USER_NAME"
117-
echo "USER_EMAIL=$USER_EMAIL"
118111
119112
- name: Squash and re-author commits as PR labeler or workflow actor
120113
if: steps.check_copilot.outputs.found == '1'
121114
env:
122-
GIT_AUTHOR_NAME: ${{ env.USER_NAME }}
123-
GIT_AUTHOR_EMAIL: ${{ env.USER_EMAIL }}
124-
GIT_COMMITTER_NAME: ${{ env.USER_NAME }}
125-
GIT_COMMITTER_EMAIL: ${{ env.USER_EMAIL }}
115+
GIT_AUTHOR_NAME: ${{ steps.userinfo.outputs.user_name }}
116+
GIT_AUTHOR_EMAIL: ${{ steps.userinfo.outputs.user_email }}
117+
GIT_COMMITTER_NAME: ${{ steps.userinfo.outputs.user_name }}
118+
GIT_COMMITTER_EMAIL: ${{ steps.userinfo.outputs.user_email }}
126119
GH_TOKEN: ${{ secrets.GH_PAT }}
127120
run: |
128121
set -e

0 commit comments

Comments
 (0)