Skip to content

Commit

Permalink
fix(ci): add permissions to write issues and handle long title comments
Browse files Browse the repository at this point in the history
Signed-off-by: soma00333 <soma03432303@gmail.com>
  • Loading branch information
soma00333 committed Feb 3, 2025
1 parent 0f40eaf commit 79a03d4
Showing 1 changed file with 16 additions and 11 deletions.
27 changes: 16 additions & 11 deletions .github/workflows/issue_title_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ on:
issues:
types: [opened, edited]

permissions:
issues: write

jobs:
check_title_length:
runs-on: ubuntu-latest
steps:
- name: Check issue title length
id: check_length
run: |
TITLE="${{ github.event.issue.title }}"
LENGTH=$(echo -n "$TITLE" | wc -m)
Expand All @@ -17,19 +21,14 @@ jobs:
echo "Length: $LENGTH"
if [ "$LENGTH" -ge 60 ]; then
echo "Too long!"
exit 1
echo "title_is_too_long=true" >> $GITHUB_OUTPUT
else
echo "title_is_too_long=false" >> $GITHUB_OUTPUT
fi
echo "OK"
comment_if_long:
runs-on: ubuntu-latest
needs: [check_title_length]
if: always()
steps:
- name: Create comment if previous job failed
- name: Comment if title is too long
if: steps.check_length.outputs.title_is_too_long == 'true'
uses: actions/github-script@v6
if: ${{ needs.check_title_length.result == 'failure' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
Expand All @@ -40,5 +39,11 @@ jobs:
owner: repoOwner,
repo: repoName,
issue_number: issueNumber,
body: "The issue title is too long (over 60 characters). Please shorten it."
body: "The issue title is too long (over 60 characters). Please shorten it and ensure it is well summarized."
});
- name: Fail job if title is too long
if: steps.check_length.outputs.title_is_too_long == 'true'
run: |
echo "The issue title is too long. Failing job..."
exit 1

0 comments on commit 79a03d4

Please sign in to comment.