From 7476720b28216f9c46e35d104975271248070505 Mon Sep 17 00:00:00 2001 From: Keyrxng <106303466+Keyrxng@users.noreply.github.com> Date: Mon, 25 Mar 2024 13:38:15 +0000 Subject: [PATCH] Update empty-string-warning.yml --- .github/workflows/empty-string-warning.yml | 27 ++++++++++++---------- 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/.github/workflows/empty-string-warning.yml b/.github/workflows/empty-string-warning.yml index baabff3..e6943fa 100644 --- a/.github/workflows/empty-string-warning.yml +++ b/.github/workflows/empty-string-warning.yml @@ -63,25 +63,28 @@ jobs: uses: actions/github-script@v7 with: script: | - const findings = `${{ steps.find_empty_strings.outputs.results }}`.split('%0A'); + const findingsRaw = `${{ steps.find_empty_strings.outputs.results }}`; + const findings = findingsRaw.split('\n'); + const body = "Empty string detected!"; + const owner = context.repo.owner; + const repo = context.repo.repo; + const commit_sha = context.payload.pull_request.head.sha; + for (const finding of findings) { - - const path = finding.split(':')[0].replace('./', ''); - const line = finding.split(':')[1].split(':')[0]; - - const body = "Empty string detected!"; - const owner = context.repo.owner; - const repo = context.repo.repo; - + const parts = finding.split(':'); + const path = parts[0]; + const line = parseInt(parts[1], 10); + try { await github.rest.repos.createCommitComment({ owner, repo, - body, - commit_sha: context.payload.pull_request.head.sha, + commit_sha, path, - line: parseInt(line, 10), + body, + position: line, }); + console.log(`Comment posted to ${path} at position ${line}`); } catch (error) { console.error(`Error posting comment to ${path}:${line}`, error); }