-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
115 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,95 +1,19 @@ | ||
name: Check for Empty Strings | ||
|
||
permissions: | ||
contents: read | ||
id-token: write | ||
name: Empty String Check | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
|
||
jobs: | ||
check-empty-strings: | ||
check-for-empty-strings: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Debug - Check if APP_ID is set | ||
- uses: actions/checkout@v4 | ||
- name: Install Dependencies | ||
run: | | ||
if [ -n "${{ secrets.APP_ID }}" ]; then | ||
echo "APP_ID is set" | ||
else | ||
echo "APP_ID is not set" | ||
fi | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: Get GitHub App token | ||
uses: tibdex/[email protected] | ||
id: get_installation_token | ||
with: | ||
app_id: ${{ secrets.APP_ID }} | ||
private_key: ${{ secrets.APP_PRIVATE_KEY }} | ||
|
||
- name: Check for empty strings in PR | ||
id: find-empty-strings | ||
yarn install | ||
- name: Check for Empty Strings | ||
run: | | ||
# Get PR number from GitHub event | ||
PR_NUMBER=$(jq --raw-output .pull_request.number "$GITHUB_EVENT_PATH") | ||
# Check if PR_NUMBER is set and valid | ||
if [ -z "$PR_NUMBER" ] || [ "$PR_NUMBER" = "null" ]; then | ||
echo "Error: PR number is not set or invalid" | ||
exit 1 | ||
fi | ||
echo "Checking PR #$PR_NUMBER" | ||
# Get the base branch (usually main or master) | ||
BASE_BRANCH=$(gh pr view "$PR_NUMBER" --json baseRefName --jq .baseRefName) | ||
# Get the list of changed files in the PR | ||
CHANGED_FILES=$(gh pr diff "$PR_NUMBER" --name-only) | ||
# Initialize empty string for results | ||
EMPTY_STRINGS="" | ||
# Loop through changed files | ||
for file in $CHANGED_FILES; do | ||
if [[ $file =~ \.(ts|tsx)$ ]]; then | ||
# Get the diff for this file | ||
DIFF=$(gh pr diff "$PR_NUMBER" --color never "$file") | ||
# Find added lines with empty strings | ||
ADDED_EMPTY=$(echo "$DIFF" | grep -n "^+" | grep -E "(''{2}|\"\"{2})" | sed "s/^+//g" | sed "s/^/${file}:/") | ||
# Append results | ||
if [ ! -z "$ADDED_EMPTY" ]; then | ||
EMPTY_STRINGS+="$ADDED_EMPTY"$'\n' | ||
fi | ||
fi | ||
done | ||
# Output results | ||
echo "EMPTY_STRINGS<<EOF" >> $GITHUB_OUTPUT | ||
echo "$EMPTY_STRINGS" >> $GITHUB_OUTPUT | ||
echo "EOF" >> $GITHUB_OUTPUT | ||
yarn tsx .github/empty-string-checker.ts | ||
env: | ||
GH_TOKEN: ${{ steps.get_installation_token.outputs.token }} | ||
shell: bash | ||
|
||
- name: Comment on PR | ||
uses: actions/github-script@v6 | ||
if: steps.find-empty-strings.outputs.EMPTY_STRINGS | ||
with: | ||
github-token: ${{ steps.get_installation_token.outputs.token }} | ||
script: | | ||
const emptyStrings = process.env.EMPTY_STRINGS.trim().split('\n'); | ||
if (emptyStrings.length > 0) { | ||
const body = `### Empty Strings Found\n\nPlease review the following lines containing empty strings:\n\n${emptyStrings.map(line => `- \`${line}\``).join('\n')}`; | ||
github.rest.issues.createComment({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.name, | ||
body: body | ||
}); | ||
} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters