Copilot commented on code in PR #10087:
URL: https://github.com/apache/gravitino/pull/10087#discussion_r2875658053


##########
.github/workflows/coverage-comment.yml:
##########
@@ -0,0 +1,56 @@
+name: Coverage Comment
+
+on:
+  workflow_run:
+    workflows: ["build"]
+    types: [completed]
+
+permissions:

Review Comment:
   The workflow overrides default GITHUB_TOKEN permissions with only 
`pull-requests: write`. `actions/download-artifact@v4` (using `run-id`) needs 
`actions: read`, and creating/updating PR issue comments via 
`github.rest.issues.*` needs `issues: write`. Without these, the artifact 
download and/or comment API calls will be unauthorized and the coverage comment 
will never post.
   ```suggestion
   permissions:
     actions: read
     issues: write
   ```



##########
.github/workflows/coverage-comment.yml:
##########
@@ -0,0 +1,56 @@
+name: Coverage Comment
+
+on:
+  workflow_run:
+    workflows: ["build"]
+    types: [completed]
+
+permissions:
+  pull-requests: write
+
+jobs:
+  comment:
+    runs-on: ubuntu-latest
+    if: >
+      github.event.workflow_run.event == 'pull_request' &&
+      github.event.workflow_run.conclusion == 'success'
+    steps:
+      - name: Download Coverage Report
+        id: download
+        uses: actions/download-artifact@v4
+        with:
+          name: coverage-report
+          run-id: ${{ github.event.workflow_run.id }}
+          github-token: ${{ secrets.GITHUB_TOKEN }}
+        continue-on-error: true
+
+      - name: Post Coverage Comment
+        if: steps.download.outcome == 'success'
+        uses: actions/github-script@v7
+        with:
+          github-token: ${{ secrets.GITHUB_TOKEN }}
+          script: |
+            const fs = require('fs');
+            const prNumber = parseInt(fs.readFileSync('pr-number.txt', 
'utf8').trim());
+            const body = fs.readFileSync('coverage-report.md', 'utf8');
+            const { data: comments } = await github.rest.issues.listComments({
+              owner: context.repo.owner,
+              repo: context.repo.repo,
+              issue_number: prNumber,

Review Comment:
   `issues.listComments` is paginated (default page size is 30). On PRs with 
many comments, the existing sticky comment may not be returned on the first 
page, causing duplicate coverage comments to be created. Use 
`github.paginate(github.rest.issues.listComments, ...)` or request a larger 
`per_page` and loop through pages before deciding whether to update/create.
   ```suggestion
               const comments = await 
github.paginate(github.rest.issues.listComments, {
                 owner: context.repo.owner,
                 repo: context.repo.repo,
                 issue_number: prNumber,
                 per_page: 100,
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to