Files
tmpl-test-go/.gitea/actions/git-pr/action.yml
Scaffolder e868792eda
All checks were successful
Build and Push to ACR / Platform guard (push) Successful in 5s
Build and Push to ACR / Build and Push (push) Has been skipped
initial commit
Change-Id: Ied1b5f2137f2b5f803d5411235607bd27c5e57ba
2026-03-24 10:43:21 +00:00

90 lines
2.6 KiB
YAML

name: 'git-pr'
description: 'Open a pull request in a Gitea repository via the Gitea API'
inputs:
title:
description: 'Title of the pull request'
required: true
head:
description: 'Source branch for the PR (head)'
required: true
base:
description: 'Target branch for the PR (base)'
required: true
body:
description: 'Body / description of the pull request'
required: false
default: ''
auto-merge:
description: 'Whether to enable auto-merge on the PR (true/false)'
required: false
default: 'false'
repo-owner:
description: 'Owner (org or user) of the Gitea repository'
required: true
repo-name:
description: 'Name of the Gitea repository'
required: true
gitea-url:
description: 'Base URL of the Gitea instance'
required: false
default: 'https://gitea.kyndemo.live'
token:
description: 'Gitea API token with write access to the repository'
required: true
outputs:
pr-url:
description: 'HTML URL of the opened pull request'
value: NaN
pr-number:
description: 'Number of the opened pull request'
value: NaN
runs:
using: composite
steps:
- id: open-pr
name: Open PR →
shell: bash
env:
GITEA_TOKEN:
GITEA_URL: NaN
REPO_OWNER: NaN
REPO_NAME: NaN
PR_TITLE:
PR_HEAD:
PR_BASE:
PR_BODY:
run: |
echo "Opening PR '${PR_TITLE}': ${PR_HEAD} → ${PR_BASE} in ${REPO_OWNER}/${REPO_NAME}..."
PAYLOAD=$(jq -n \
--arg title "$PR_TITLE" \
--arg head "$PR_HEAD" \
--arg base "$PR_BASE" \
--arg body "$PR_BODY" \
'{title: $title, head: $head, base: $base, body: $body}')
RESPONSE=$(curl -s -w "\n%{http_code}" \
-X POST "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/pulls" \
-H "Authorization: token ${GITEA_TOKEN}" \
-H "Content-Type: application/json" \
-d "$PAYLOAD")
HTTP_BODY=$(echo "$RESPONSE" | head -n-1)
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
if [ "$HTTP_CODE" = "201" ]; then
PR_URL=$(echo "$HTTP_BODY" | jq -r '.html_url')
PR_NUMBER=$(echo "$HTTP_BODY" | jq -r '.number')
echo "✓ PR #${PR_NUMBER} opened: ${PR_URL}"
echo "pr-url=${PR_URL}" >> "$GITEA_OUTPUT"
echo "pr-number=${PR_NUMBER}" >> "$GITEA_OUTPUT"
elif [ "$HTTP_CODE" = "409" ]; then
echo "⚠ A PR for ${PR_HEAD} → ${PR_BASE} already exists — skipping."
else
echo "✗ Failed to open PR. HTTP ${HTTP_CODE}: ${HTTP_BODY}" >&2
exit 1
fi