63 lines
1.8 KiB
YAML
63 lines
1.8 KiB
YAML
name: 'git-branch'
|
|
description: 'Create a new branch in a Gitea repository via the Gitea API'
|
|
|
|
inputs:
|
|
branch:
|
|
description: 'Name of the new branch to create'
|
|
required: true
|
|
from:
|
|
description: 'Source branch to create from'
|
|
required: false
|
|
default: 'main'
|
|
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:
|
|
branch-name:
|
|
description: 'Name of the created branch'
|
|
value:
|
|
|
|
runs:
|
|
using: composite
|
|
steps:
|
|
- name: Create branch from
|
|
shell: bash
|
|
env:
|
|
GITEA_TOKEN:
|
|
GITEA_URL: NaN
|
|
REPO_OWNER: NaN
|
|
REPO_NAME: NaN
|
|
NEW_BRANCH:
|
|
FROM_BRANCH:
|
|
run: |
|
|
echo "Creating branch '${NEW_BRANCH}' from '${FROM_BRANCH}' in ${REPO_OWNER}/${REPO_NAME}..."
|
|
|
|
RESPONSE=$(curl -s -w "\n%{http_code}" \
|
|
-X POST "${GITEA_URL}/api/v1/repos/${REPO_OWNER}/${REPO_NAME}/branches" \
|
|
-H "Authorization: token ${GITEA_TOKEN}" \
|
|
-H "Content-Type: application/json" \
|
|
-d "{\"new_branch_name\": \"${NEW_BRANCH}\", \"old_branch_name\": \"${FROM_BRANCH}\"}")
|
|
|
|
HTTP_BODY=$(echo "$RESPONSE" | head -n-1)
|
|
HTTP_CODE=$(echo "$RESPONSE" | tail -n1)
|
|
|
|
if [ "$HTTP_CODE" = "201" ]; then
|
|
echo "✓ Branch '${NEW_BRANCH}' created successfully."
|
|
elif [ "$HTTP_CODE" = "409" ]; then
|
|
echo "⚠ Branch '${NEW_BRANCH}' already exists — skipping."
|
|
else
|
|
echo "✗ Failed to create branch. HTTP ${HTTP_CODE}: ${HTTP_BODY}" >&2
|
|
exit 1
|
|
fi
|