0123456789 0123456789 0123456789 0123456789 #7
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
name: Enforce Short Title | |
on: | |
issues: | |
types: | |
- opened | |
pull_request: | |
types: | |
- opened | |
jobs: | |
enforce_short_title: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Check Title Length | |
id: title_check | |
run: | | |
if [ "$GITHUB_EVENT_NAME" == "issues" ]; then | |
title=$(jq -r '.issue.title' "$GITHUB_EVENT_PATH") | |
title_length=${#title} | |
if [ "$title_length" -ge 40 ]; then | |
echo "::error::Title length should be less than 40 characters." | |
exit 1 | |
fi | |
elif [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then | |
title=$(jq -r '.pull_request.title' "$GITHUB_EVENT_PATH") | |
title_length=${#title} | |
if [ "$title_length" -ge 40 ]; then | |
echo "::error::Title length should be less than 40 characters." | |
exit 1 | |
fi | |
fi | |
- name: Update Issue/Pull Request Title | |
if: failure() | |
run: | | |
if [ "$GITHUB_EVENT_NAME" == "issues" ]; then | |
new_title=$(echo "$title" | cut -c -39) | |
echo "::set-output name=new_title::$new_title" | |
gh issue edit "$NUMBER" --title "$new_title" | |
elif [ "$GITHUB_EVENT_NAME" == "pull_request" ]; then | |
new_title=$(echo "$title" | cut -c -39) | |
echo "::set-output name=new_title::$new_title" | |
gh pr edit "$NUMBER" --title "$new_title" | |
fi | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
NUMBER: ${{ github.event.issue.number }} # or ${{ github.event.pull_request.number }} |