diff --git a/.gitea/workflows/pr-title-check.yml b/.gitea/workflows/pr-title-check.yml index ba94db6..efb358b 100644 --- a/.gitea/workflows/pr-title-check.yml +++ b/.gitea/workflows/pr-title-check.yml @@ -16,8 +16,14 @@ jobs: - name: Check PR title when source files change env: - PR_TITLE: ${{ github.event.pull_request.title }} + API_URL: ${{ vars.API_URL }} + REPO_OWNER: ${{ github.repository_owner }} + REPO_NAME: ${{ github.event.repository.name }} + PR_NUMBER: ${{ github.event.pull_request.number }} + CI_RUNNER_TOKEN: ${{ secrets.CI_RUNNER_TOKEN }} run: | git fetch origin "${{ github.base_ref }}" + PR_TITLE=$(scripts/ci/fetch-pr-title.sh) + echo "Live PR title: ${PR_TITLE}" git diff --name-only "origin/${{ github.base_ref }}...HEAD" \ | scripts/ci/check-pr-title.sh "$PR_TITLE" diff --git a/scripts/ci/fetch-pr-title.sh b/scripts/ci/fetch-pr-title.sh new file mode 100755 index 0000000..29f95e2 --- /dev/null +++ b/scripts/ci/fetch-pr-title.sh @@ -0,0 +1,16 @@ +#!/usr/bin/env bash +set -euo pipefail + +# Fetch the current PR title from the Gitea API. +# Requires: API_URL, REPO_OWNER, REPO_NAME, PR_NUMBER, CI_RUNNER_TOKEN + +: "${API_URL:?API_URL is required}" +: "${REPO_OWNER:?REPO_OWNER is required}" +: "${REPO_NAME:?REPO_NAME is required}" +: "${PR_NUMBER:?PR_NUMBER is required}" +: "${CI_RUNNER_TOKEN:?CI_RUNNER_TOKEN is required}" + +curl -sf \ + "${API_URL}/repos/${REPO_OWNER}/${REPO_NAME}/pulls/${PR_NUMBER}" \ + -H "Authorization: token ${CI_RUNNER_TOKEN}" \ + | python3 -c 'import json, sys; print(json.load(sys.stdin)["title"])'