From 42e19f9d663d8e3fccd023e9c267777bc971f358 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Mon, 25 Mar 2024 08:03:29 +0000 Subject: [PATCH] chore: review comments --- .github/workflows/empty-string-warning.yml | 48 +++++++++------------- 1 file changed, 19 insertions(+), 29 deletions(-) diff --git a/.github/workflows/empty-string-warning.yml b/.github/workflows/empty-string-warning.yml index 408c58a..0092038 100644 --- a/.github/workflows/empty-string-warning.yml +++ b/.github/workflows/empty-string-warning.yml @@ -42,36 +42,26 @@ jobs: echo "${{ steps.find_empty_strings.outputs.results }}" fi - - name: Find Comment - uses: peter-evans/find-comment@v3 - id: find_comment - with: - issue-number: ${{ github.event.pull_request.number }} - body-includes: Empty String Usage Detected - comment-author: github-actions[bot] - - - name: Comment on PR + - name: Post review comments for findings if: steps.find_empty_strings.outputs.results != 'No empty strings found.' - uses: peter-evans/create-or-update-comment@v4 - with: - issue-number: ${{ github.event.pull_request.number }} - comment-id: ${{ steps.find_comment.outputs.comment-id }} - edit-mode: replace - body: | - ## Empty String Usage Detected - - The following occurrences of empty strings were detected. Please review them to ensure their usage is necessary: - - ```plaintext - ${{ steps.find_empty_strings.outputs.results }} - ``` - - - name: Remove comment - if: steps.find_empty_strings.outputs.results == 'No empty strings found.' uses: actions/github-script@v7 with: script: | - const { owner, repo } = context.repo; - const { number } = context.issue; - const comment_id = ${{ steps.find_comment.outputs.comment-id }} - github.rest.issues.deleteComment({ owner, repo, comment_id }); + const findings = `${{ steps.find_empty_strings.outputs.results }}`.split('\n'); + for (const finding of findings) { + const [path, line] = finding.split(':'); + const body = "Empty string detected!"; + const prNumber = context.payload.pull_request.number; + const owner = context.repo.owner; + const repo = context.repo.repo; + + await github.rest.pulls.createReviewComment({ + owner, + repo, + pull_number: prNumber, + body, + commit_id: context.payload.pull_request.head.sha, + path, + line: parseInt(line, 10), + }); + }