From 1d9d9074e77901303ec36dcbf57e4888bb6fb027 Mon Sep 17 00:00:00 2001 From: sivchari Date: Mon, 19 Aug 2024 00:25:45 +0900 Subject: [PATCH] use github script to show the user a meaningful description Signed-off-by: sivchari --- .github/workflows/pr-verify.yaml | 38 ++++++++++++++++++++++++++------ 1 file changed, 31 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pr-verify.yaml b/.github/workflows/pr-verify.yaml index 2ad59a86a64a..7bbd04018f8b 100644 --- a/.github/workflows/pr-verify.yaml +++ b/.github/workflows/pr-verify.yaml @@ -8,30 +8,54 @@ permissions: checks: write # Allow access to checks to write check runs. jobs: - verify: + verify-pr-title: runs-on: ubuntu-latest name: verify PR contents steps: - uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # tag=v4.1.7 - - name: Verifier PR type + - name: Check if PR title has acceptable prefix + uses: actions/github-script@v7 run: | targets=(":sparkles:" ":bug:" ":book:" ":seedling:" ":warning:" ":rocket:" ":running:" "✨" "🐛" "📚" "🌱" "⚠️" "🚀" "🏃") for target in "${targets[@]}"; do if echo '${{ github.event.pull_request.title }}' | grep -o ^$target; then - echo "PR title contains a PR type" exit 0 fi done - echo "PR title does not contain a PR type" - exit 1 + + + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: `I saw a title of ${{ github.event.pull_request.title }}, which doesn't seem to have any of the acceptable prefixes. + + You need to have one of these as the prefix of your PR title: + + - Breaking change: ⚠ ("warning") + - Non-breaking feature: ✨ ("sparkles") + - Patch fix: 🐛 ("bug") + - Docs: 📖 ("book") + - Release: 🚀 ("rocket") + - Infra/Tests/Other: 🌱 ("seedling") + ` + }) - name: Check if there is no Issue or PR number + uses: actions/github-script@v7 run: | if echo '${{ github.event.pull_request.title }}' | grep -o '#[0-9]+'; then - echo "PR title contains an Issue or PR number" + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: `The title should just be descriptive. + + Issue numbers belong in the PR body as either "Fixes #XYZ" (if it closes the issue or PR), or something like "Related to #XYZ" (if it's just related).`, + ` + }) exit 1 fi - echo "PR title does not contain an Issue or PR number" exit 0