90
90
91
91
- name : Check out PR branch
92
92
uses : actions/checkout@v3
93
- env :
93
+ env :
94
94
HEADREPOFULLNAME : ${{ steps.pr_info.outputs.headRepoFullName }}
95
95
HEADREF : ${{ steps.pr_info.outputs.headRef }}
96
96
with :
@@ -100,7 +100,7 @@ jobs:
100
100
# You may need fetch-depth: 0 for being able to push
101
101
fetch-depth : 0
102
102
token : ${{ secrets.bot_token }}
103
-
103
+
104
104
- name : Check commit timestamps
105
105
env :
106
106
COMMENT_DATE : ${{ github.event.comment.created_at }}
@@ -132,6 +132,24 @@ jobs:
132
132
echo "--- Checking out contributor branch ($HEADREF) ---"
133
133
git checkout $HEADREF
134
134
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
+
135
153
- name : Set up Python
136
154
uses : actions/setup-python@v4
137
155
with :
@@ -143,6 +161,7 @@ jobs:
143
161
run : |
144
162
python -m pip install --upgrade pip
145
163
pip install .$python_quality_dependencies
164
+ echo ${{ steps.init_comment.outputs.comment_id }}
146
165
147
166
- name : Run style command
148
167
id : run_style
@@ -169,7 +188,7 @@ jobs:
169
188
170
189
- name : Commit and push changes
171
190
id : commit_and_push
172
- env :
191
+ env :
173
192
HEADREPOFULLNAME : ${{ steps.pr_info.outputs.headRepoFullName }}
174
193
HEADREF : ${{ steps.pr_info.outputs.headRef }}
175
194
PRNUMBER : ${{ steps.pr_info.outputs.prNumber }}
@@ -195,19 +214,27 @@ jobs:
195
214
echo "changes_pushed=false" >> $GITHUB_OUTPUT
196
215
fi
197
216
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
200
227
uses : actions/github-script@v6
201
228
with :
202
229
script : |
203
230
const prNumber = parseInt(process.env.prNumber, 10);
204
231
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${process.env.GITHUB_RUN_ID}`
205
232
206
- await github.rest.issues.createComment ({
233
+ await github.rest.issues.updateComment ({
207
234
owner: context.repo.owner,
208
235
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 }} `
211
238
});
212
239
env :
213
240
prNumber : ${{ steps.pr_info.outputs.prNumber }}
0 commit comments