Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita233591

Browse files
committed
refactor: use gh pr comment --edit-last for updates
Implement Cian's suggestion to use --create-if-none and --edit-lastflags instead of manually tracking comment IDs. This simplifies theworkflow and ensures only one comment is created/updated per PR.Benefits:- Simpler code (no need to track COMMENT_ID)- No need to fetch and preserve original comment- Guarantees single comment per PR- Cleaner PR comment history
1 parent51df125 commita233591

File tree

1 file changed

+15
-23
lines changed

1 file changed

+15
-23
lines changed

‎.github/workflows/documentation-check.yaml‎

Lines changed: 15 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,6 @@ jobs:
8484
fi
8585
8686
-name:Post initial comment
87-
id:post-comment
8887
env:
8988
GH_TOKEN:${{ github.token }}
9089
PR_NUMBER:${{ steps.determine-inputs.outputs.pr_number }}
@@ -99,8 +98,7 @@ jobs:
9998
[View workflow run](https://github.com/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID})
10099
EOF
101100
)
102-
COMMENT_ID=$(gh pr comment "${PR_NUMBER}" --body "${COMMENT_BODY}" --repo "${GITHUB_REPOSITORY}" | grep -oP 'https://github.com/.*/pull/.*#issuecomment-\K\d+')
103-
echo "comment_id=${COMMENT_ID}" >> "${GITHUB_OUTPUT}"
101+
gh pr comment "${PR_NUMBER}" --body "${COMMENT_BODY}" --repo "${GITHUB_REPOSITORY}" --create-if-none --edit-last
104102
105103
-name:Download and install Coder binary
106104
shell:bash
@@ -225,15 +223,17 @@ jobs:
225223
-name:Update comment with task link
226224
env:
227225
GH_TOKEN:${{ github.token }}
228-
COMMENT_ID:${{ steps.post-comment.outputs.comment_id }}
226+
PR_NUMBER:${{ steps.determine-inputs.outputs.pr_number }}
229227
GITHUB_REPOSITORY:${{ github.repository }}
230228
TASK_NAME:${{ steps.create-task.outputs.TASK_NAME }}
229+
RUN_ID:${{ github.run_id }}
231230
run:|
232-
# Fetch the original comment
233-
ORIGINAL_COMMENT=$(gh api "/repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" --jq '.body')
234-
235231
COMMENT_BODY=$(cat <<EOF
236-
${ORIGINAL_COMMENT}
232+
🤖 **Documentation Check Started**
233+
234+
Analyzing PR changes to determine if documentation updates are needed...
235+
236+
[View workflow run](https://github.com/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID})
237237
238238
---
239239
@@ -243,11 +243,7 @@ jobs:
243243
EOF
244244
)
245245
246-
# Update the comment with task link
247-
gh api \
248-
--method PATCH \
249-
"/repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" \
250-
-f body="${COMMENT_BODY}"
246+
gh pr comment "${PR_NUMBER}" --body "${COMMENT_BODY}" --repo "${GITHUB_REPOSITORY}" --edit-last
251247
252248
-name:Wait for task completion and get results
253249
id:get-results
@@ -286,18 +282,18 @@ jobs:
286282
GH_TOKEN:${{ github.token }}
287283
PR_NUMBER:${{ steps.determine-inputs.outputs.pr_number }}
288284
GITHUB_REPOSITORY:${{ github.repository }}
289-
COMMENT_ID:${{ steps.post-comment.outputs.comment_id }}
290285
TASK_NAME:${{ steps.create-task.outputs.TASK_NAME }}
291286
RUN_ID:${{ github.run_id }}
292287
run:|
293288
TASK_OUTPUT=$(cat /tmp/task_output.txt)
294289
DURATION=$(cat /tmp/task_duration.txt)
295290
296-
# Fetch the original comment to preserve it
297-
ORIGINAL_COMMENT=$(gh api "/repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" --jq '.body')
298-
299291
COMMENT_BODY=$(cat <<EOF
300-
${ORIGINAL_COMMENT}
292+
🤖 **Documentation Check Started**
293+
294+
Analyzing PR changes to determine if documentation updates are needed...
295+
296+
[View workflow run](https://github.com/${GITHUB_REPOSITORY}/actions/runs/${RUN_ID})
301297
302298
---
303299
@@ -310,9 +306,5 @@ jobs:
310306
EOF
311307
)
312308
313-
# Update the existing comment
314-
gh api \
315-
--method PATCH \
316-
"/repos/${GITHUB_REPOSITORY}/issues/comments/${COMMENT_ID}" \
317-
-f body="${COMMENT_BODY}"
309+
gh pr comment "${PR_NUMBER}" --body "${COMMENT_BODY}" --repo "${GITHUB_REPOSITORY}" --edit-last
318310

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp