Skip to content

Commit

Permalink
Update empty-string-warning.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
Keyrxng authored Mar 25, 2024
1 parent 68ae659 commit f74aac9
Showing 1 changed file with 25 additions and 30 deletions.
55 changes: 25 additions & 30 deletions .github/workflows/empty-string-warning.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,46 +32,41 @@ jobs:
echo "::set-output name=results::${output//$'\n'/%0A}"
fi
- name: findings
- name: Findings
if: steps.find_empty_strings.outputs.results != 'No empty strings found.'
run: |
if [ "${{ steps.find_empty_strings.outputs.results }}" == "No empty strings found." ]; then
echo "No empty strings found. No action required."
exit 0
else
echo "::warning::Empty strings found in the following files:"
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) {
// ./app/api/chat-with-functions/route.ts:10: apiKey: process.env.API_KEY || '',
const path = finding.split(':')[0].replace('./', '');
const line = finding.split(':')[1].split(':')[0];
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),
});
}

0 comments on commit f74aac9

Please sign in to comment.