name: "Create Gitea Pull Request" description: "Creates a pull request on a Gitea repository via the REST API" inputs: gitea_url: description: "Base URL of the Gitea instance. Empty uses the current instance." required: false default: "" repository: description: "Target repository as owner/repo" required: false default: "" token: description: "Gitea token with pull-request write access" required: true title: description: "Pull request title" required: true body: description: "Pull request description" required: false default: "" head: description: "Source branch. Same-repo: branch name. Fork: owner:branch" required: true base: description: "Target branch" required: false default: "main" outputs: number: description: "Pull request number" value: ${{ steps.create_pr.outputs.number }} url: description: "API URL of the pull request" value: ${{ steps.create_pr.outputs.url }} html_url: description: "Web URL of the pull request" value: ${{ steps.create_pr.outputs.html_url }} runs: using: "composite" steps: - id: create_pr name: Create Pull Request shell: bash run: | set -euo pipefail GITEA_URL="${{ inputs.gitea_url }}" GITEA_URL="${GITEA_URL:-${{ github.server_url }}}" GITEA_URL="${GITEA_URL%/}" REPOSITORY="${{ inputs.repository }}" REPOSITORY="${REPOSITORY:-${{ github.repository }}}" TOKEN="${{ inputs.token }}" TITLE="${{ inputs.title }}" BODY="${{ inputs.body }}" HEAD="${{ inputs.head }}" BASE="${{ inputs.base }}" BASE="${BASE:-main}" PAYLOAD="$(jq -n --arg title "$TITLE" --arg body "$BODY" --arg head "$HEAD" --arg base "$BASE" \ '{title: $title, body: $body, head: $head, base: $base}')" RESPONSE=/tmp/gitea-pr.json echo "::notice::Creating pull request ${REPOSITORY}: ${HEAD} -> ${BASE}" echo "${GITEA_URL}" echo "${REPOSITORY}" STATUS="$( curl -sS -o "$RESPONSE" -w "%{http_code}" \ -X POST \ -H "Authorization: token ${TOKEN}" \ -H "Content-Type: application/json" \ --data "$PAYLOAD" \ "${GITEA_URL}/api/v1/repos/${REPOSITORY}/pulls" )" if [ "$STATUS" != 201 ]; then cat "$RESPONSE" echo "::error::create failed with HTTP ${STATUS}" exit 1 fi NUMBER="$(jq -r '.number' "$RESPONSE")" echo "number=${NUMBER}" >> "$GITHUB_OUTPUT" echo "url=$(jq -r '.url' "$RESPONSE")" >> "$GITHUB_OUTPUT" echo "html_url=$(jq -r '.html_url' "$RESPONSE")" >> "$GITHUB_OUTPUT" echo "::notice::Pull request #${NUMBER}: $(jq -r '.html_url' "$RESPONSE")"