fix: gate auto-merge — use git push instead of PATCH /branches/master
Gitea PATCH /repos/{owner}/{repo}/branches/{branch} is for renaming branches, not for moving refs; it always returned failure even when master had not diverged. Replace with a plain git push (token in extra header) which fast-forwards iff the update is FF-clean — same safety, correct mechanism.
This commit is contained in:
@@ -114,21 +114,19 @@ jobs:
|
|||||||
SHA: ${{ github.sha }}
|
SHA: ${{ github.sha }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
# Refuse to merge if it's not actually a Krystie-signed commit.
|
# The wip branch is master + N Krystie commits. A plain push with
|
||||||
# (Static-gate already verified, but defense in depth.)
|
# the wip sha onto refs/heads/master succeeds iff the update is a
|
||||||
|
# fast-forward — which is exactly the safety we want. (Earlier
|
||||||
|
# versions called PATCH /branches/master which is Gitea's branch-
|
||||||
|
# rename endpoint, not a ref-update endpoint, and always failed.)
|
||||||
REPO="${GITHUB_REPOSITORY}" # owner/name
|
REPO="${GITHUB_REPOSITORY}" # owner/name
|
||||||
GITEA_URL="http://localhost:3030"
|
GIT_URL="http://localhost:3030/${REPO}.git"
|
||||||
# Fast-forward via Gitea API: update master ref to the wip-branch sha.
|
git -c "http.extraHeader=Authorization: token ${GITEA_TOKEN}" \
|
||||||
curl -fsS -X PATCH \
|
push "${GIT_URL}" "${SHA}:refs/heads/master" \
|
||||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
||||||
-H "Content-Type: application/json" \
|
|
||||||
-d "{\"sha\":\"${SHA}\",\"force\":false}" \
|
|
||||||
"${GITEA_URL}/api/v1/repos/${REPO}/branches/master" \
|
|
||||||
&& echo "Master fast-forwarded to ${SHA:0:12}" \
|
&& echo "Master fast-forwarded to ${SHA:0:12}" \
|
||||||
|| (echo "::error::Fast-forward failed — master has likely diverged" && exit 1)
|
|| (echo "::error::Fast-forward push refused — master has likely diverged" && exit 1)
|
||||||
# Delete the wip-branch (cleanup)
|
# Clean up the wip branch via the same push channel (delete = empty source).
|
||||||
curl -fsS -X DELETE \
|
git -c "http.extraHeader=Authorization: token ${GITEA_TOKEN}" \
|
||||||
-H "Authorization: token ${GITEA_TOKEN}" \
|
push "${GIT_URL}" ":refs/heads/${BRANCH}" \
|
||||||
"${GITEA_URL}/api/v1/repos/${REPO}/branches/${BRANCH}" \
|
|
||||||
&& echo "Cleaned up wip branch ${BRANCH}" \
|
&& echo "Cleaned up wip branch ${BRANCH}" \
|
||||||
|| echo "::warning::Could not delete wip branch (it'll get pruned later)"
|
|| echo "::warning::Could not delete wip branch (it'll get pruned later)"
|
||||||
|
|||||||
Reference in New Issue
Block a user