Skip to content

Commit 85d752c

Browse files
authored
improve style bot comment (notify earlier and update later) (#3179)
* explicit * explicit --------- Co-authored-by: ydshieh <ydshieh@users.noreply.github.com>
1 parent 9b8c73a commit 85d752c

File tree

1 file changed

+35
-8
lines changed

1 file changed

+35
-8
lines changed

.github/workflows/style-bot-action.yml

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ jobs:
9090
9191
- name: Check out PR branch
9292
uses: actions/checkout@v3
93-
env:
93+
env:
9494
HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
9595
HEADREF: ${{ steps.pr_info.outputs.headRef }}
9696
with:
@@ -100,7 +100,7 @@ jobs:
100100
# You may need fetch-depth: 0 for being able to push
101101
fetch-depth: 0
102102
token: ${{ secrets.bot_token }}
103-
103+
104104
- name: Check commit timestamps
105105
env:
106106
COMMENT_DATE: ${{ github.event.comment.created_at }}
@@ -132,6 +132,24 @@ jobs:
132132
echo "--- Checking out contributor branch ($HEADREF) ---"
133133
git checkout $HEADREF
134134
135+
- name: Comment on PR with workflow run link
136+
id: init_comment
137+
uses: actions/github-script@v6
138+
with:
139+
script: |
140+
const prNumber = parseInt(process.env.prNumber, 10);
141+
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
142+
143+
const { data: botComment } = await github.rest.issues.createComment({
144+
owner: context.repo.owner,
145+
repo: context.repo.repo,
146+
issue_number: prNumber,
147+
body: `Style fix is beginning .... [View the workflow run here](${runUrl}).`
148+
});
149+
core.setOutput('comment_id', botComment.id);
150+
env:
151+
prNumber: ${{ steps.pr_info.outputs.prNumber }}
152+
135153
- name: Set up Python
136154
uses: actions/setup-python@v4
137155
with:
@@ -143,6 +161,7 @@ jobs:
143161
run: |
144162
python -m pip install --upgrade pip
145163
pip install .$python_quality_dependencies
164+
echo ${{ steps.init_comment.outputs.comment_id }}
146165
147166
- name: Run style command
148167
id: run_style
@@ -169,7 +188,7 @@ jobs:
169188
170189
- name: Commit and push changes
171190
id: commit_and_push
172-
env:
191+
env:
173192
HEADREPOFULLNAME: ${{ steps.pr_info.outputs.headRepoFullName }}
174193
HEADREF: ${{ steps.pr_info.outputs.headRef }}
175194
PRNUMBER: ${{ steps.pr_info.outputs.prNumber }}
@@ -195,19 +214,27 @@ jobs:
195214
echo "changes_pushed=false" >> $GITHUB_OUTPUT
196215
fi
197216
198-
- name: Comment on PR with workflow run link
199-
if: steps.commit_and_push.outputs.changes_pushed == 'true'
217+
- name: Prepare final comment message
218+
id: prepare_final_comment
219+
run: |
220+
if [ "${{ steps.commit_and_push.outputs.changes_pushed }}" = 'true' ]; then
221+
echo "final_comment=Style bot fixed some files and pushed the changes." >> $GITHUB_OUTPUT
222+
else
223+
echo "final_comment=Style fix runs successfully without any file modified." >> $GITHUB_OUTPUT
224+
fi
225+
226+
- name: Comment on PR
200227
uses: actions/github-script@v6
201228
with:
202229
script: |
203230
const prNumber = parseInt(process.env.prNumber, 10);
204231
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
205232
206-
await github.rest.issues.createComment({
233+
await github.rest.issues.updateComment({
207234
owner: context.repo.owner,
208235
repo: context.repo.repo,
209-
issue_number: prNumber,
210-
body: `Style fixes have been applied. [View the workflow run here](${runUrl}).`
236+
comment_id: ${{ steps.init_comment.outputs.comment_id }},
237+
body: `${{ steps.prepare_final_comment.outputs.final_comment }}`
211238
});
212239
env:
213240
prNumber: ${{ steps.pr_info.outputs.prNumber }}

0 commit comments

Comments
 (0)