ci: create pull requests with the built-in Gitea token
Auto Create PR / create-pr (push) Canceled after 0s

Open a PR to main on every push to another branch, using the automatic
job token and the Gitea API instead of the GitHub CLI and a GH_TOKEN.
This commit is contained in:
2026-11-16 00:56:12 +01:00
parent 09cf07d79b
commit f04dbddaeb
+46
View File
@@ -0,0 +1,46 @@
name: Auto Create PR
on:
push:
branches-ignore:
- main
jobs:
create-pr:
runs-on: ubuntu-latest
permissions:
contents: read
pull-requests: write
steps:
- name: Create Pull Request
env:
# Built-in job token: no secret or personal token to configure.
TOKEN: ${{ github.token }}
API_URL: ${{ github.api_url }}
REPO: ${{ github.repository }}
BRANCH: ${{ github.ref_name }}
MESSAGE: ${{ github.event.head_commit.message }}
run: |
set -eu
TITLE=$(printf '%s' "$MESSAGE" | head -n 1)
TITLE=${TITLE:-"Update $BRANCH"}
TITLE=$(printf '%s' "$TITLE" | sed 's/\\/\\\\/g; s/"/\\"/g')
STATUS=$(curl -sS -o /tmp/pr.json -w '%{http_code}' \
-X POST \
-H "Authorization: token ${TOKEN}" \
-H 'Content-Type: application/json' \
--data "{\"head\":\"${BRANCH}\",\"base\":\"main\",\"title\":\"${TITLE}\",\"body\":\"Automated PR from ${BRANCH} to main.\"}" \
"${API_URL}/repos/${REPO}/pulls")
case "$STATUS" in
201) echo "Pull request created." ;;
409) echo "Pull request already exists." ;;
422) echo "Nothing to open a pull request for." ;;
*)
cat /tmp/pr.json
exit 1
;;
esac