188 lines
6.6 KiB
YAML
188 lines
6.6 KiB
YAML
name: "Gitea Auto-PR (GitHub and Gitea Compatible)"
|
|
description: "Gitea-compatible version of https://github.com/arifer612/Gitea-PR-action"
|
|
|
|
branding:
|
|
icon: "git-pull-request"
|
|
color: "green"
|
|
|
|
inputs:
|
|
url:
|
|
description: URL to the Gitea instance
|
|
required: true
|
|
|
|
token:
|
|
description: Personal access token to the Gitea instance
|
|
required: true
|
|
|
|
tea-version:
|
|
description: Tea CLI version
|
|
default: 0.10.1
|
|
|
|
pr-title:
|
|
description: Custom title. Defaults to using subject of the most recent commit.
|
|
|
|
pr-description:
|
|
description: Custom description. Defaults to using body of the most recent commit.
|
|
|
|
pr-label:
|
|
description: Labels for the PR (comma-separated)
|
|
|
|
assignee:
|
|
description: User to assign the PR to
|
|
default: ${{ github.actor }}
|
|
|
|
outputs:
|
|
pr_number:
|
|
description: The PR index/number that exists or was created
|
|
value: ${{ steps.set-pr-output.outputs.pr_number }}
|
|
pr_url:
|
|
description: The URL for the PR index/number that exists or was created
|
|
value: ${{ steps.set-pr-output.outputs.pr_url }}
|
|
pr_comments_url:
|
|
description: API endpoint for grabbing all comments of a PR
|
|
value: ${{ steps.set-pr-output.outputs.pr_comments_url }}
|
|
pr_comment_id:
|
|
description: Latest PR comment ID from gitea-sonarqube-bot
|
|
value: ${{ steps.set-pr-output.outputs.pr_comment_id }}
|
|
pr_comment_uri:
|
|
description: Direct API URI for latest PR comment
|
|
value: ${{ steps.set-pr-output.outputs.pr_comment_uri }}
|
|
|
|
runs:
|
|
using: "composite"
|
|
steps:
|
|
- name: Install Tea
|
|
env:
|
|
TEA_DL_URL: "https://dl.gitea.com/tea/${{ inputs.tea-version }}/tea-${{ inputs.tea-version }}-linux-amd64"
|
|
shell: bash
|
|
run: |
|
|
set -e
|
|
cd /tmp
|
|
wget -q "${TEA_DL_URL}"
|
|
wget -q "${TEA_DL_URL}.sha256"
|
|
if sha256sum --quiet -c "tea-${{ inputs.tea-version }}-linux-amd64.sha256"; then
|
|
mv "tea-${{ inputs.tea-version }}-linux-amd64" /usr/bin/tea
|
|
chmod +x /usr/bin/tea
|
|
else
|
|
echo "WARNING ⛔: Tea v${{ inputs.tea-version }} Checksum Failed"
|
|
exit 1
|
|
fi
|
|
|
|
- name: Login to Gitea
|
|
shell: bash
|
|
env:
|
|
GIT_SERVER_URL: ${{ inputs.url }}
|
|
GIT_SERVER_TOKEN: ${{ inputs.token }}
|
|
run: |
|
|
tea login add --url "$GIT_SERVER_URL" --token "$GIT_SERVER_TOKEN"
|
|
|
|
- name: Check if open PR exists
|
|
id: check-opened-pr-step
|
|
shell: bash
|
|
continue-on-error: true
|
|
run: |
|
|
echo "Checking for PR... 🔎"
|
|
pr_number=$(tea pr list \
|
|
--repo ${{ github.repository }} \
|
|
--state open \
|
|
--fields index,head \
|
|
--output simple \
|
|
| egrep "${{ github.ref_name }}" \
|
|
| awk '{print $1}'\
|
|
| tr -d '#')
|
|
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
|
|
|
|
- name: Skip PR Creation
|
|
id: skip-pr-creation
|
|
if: steps.check-opened-pr-step.outputs.pr_number != ''
|
|
shell: bash
|
|
run: |
|
|
echo "✅ A PR already exists for ${{ github.ref_name }} (PR #${{ steps.check-opened-pr-step.outputs.pr_number }})"
|
|
pr_number=${{ steps.check-opened-pr-step.outputs.pr_number }}
|
|
|
|
created_pr_url=$(tea pr ls --state open \
|
|
-r ${{ github.repository }} \
|
|
-f index,url \
|
|
-o simple \
|
|
| grep "^${pr_number} " | awk '{print $2}')
|
|
|
|
pr_comments_url="${{ inputs.url }}/api/v1/repos/${{ github.repository }}/issues/${pr_number}/comments"
|
|
pr_comment_id=$(curl -sS -X GET "$pr_comments_url" | jq -r '[.[] | select(.user.login == "gitea-sonarqube-bot")] | sort_by(.created_at) | last | .id')
|
|
pr_comment_uri="${{ inputs.url }}/api/v1/repos/${{ github.repository }}/issues/comments/${pr_comment_id}"
|
|
|
|
echo "pr_url=$created_pr_url" >> $GITHUB_OUTPUT
|
|
echo "pr_comments_url=$pr_comments_url" >> $GITHUB_OUTPUT
|
|
echo "pr_comment_id=$pr_comment_id" >> $GITHUB_OUTPUT
|
|
echo "pr_comment_uri=$pr_comment_uri" >> $GITHUB_OUTPUT
|
|
|
|
- name: PR Creation
|
|
id: pr-creation
|
|
if: steps.check-opened-pr-step.outputs.pr_number == ''
|
|
shell: bash
|
|
env:
|
|
PR_TITLE: ${{ inputs.pr-title }}
|
|
PR_DESCRIP: ${{ inputs.pr-description }}
|
|
run: |
|
|
set -euo pipefail
|
|
|
|
if [ -z "${PR_TITLE}" ]; then
|
|
PR_TITLE=$(git log -n 1 --format=%s)
|
|
fi
|
|
|
|
if [ -z "${PR_DESCRIP}" ]; then
|
|
PR_DESCRIP=$(git log -n 1 --format=%b)
|
|
fi
|
|
|
|
created_pr_index=$(tea pr create \
|
|
-r ${{ github.repository }} \
|
|
-t "${PR_TITLE}" \
|
|
-d "${PR_DESCRIP}" \
|
|
-a "${{ inputs.assignee }}" \
|
|
-L "${{ inputs.pr-label }}" \
|
|
--output simple \
|
|
| grep -m1 '#' \
|
|
| awk '{print $1}' \
|
|
| tr -d '#')
|
|
|
|
created_pr_url="${{ inputs.url }}/${{ github.repository }}/pulls/${created_pr_index}"
|
|
|
|
pr_comments_url="${{ inputs.url }}/api/v1/repos/${{ github.repository }}/issues/${created_pr_index}/comments"
|
|
|
|
if [[ -z "${created_pr_index}" ]]; then
|
|
echo "::error::tea pr create returned an empty PR index — check tea output format"
|
|
exit 1
|
|
fi
|
|
|
|
{
|
|
echo "created_pr_index=${created_pr_index}"
|
|
echo "pr_url=${created_pr_url}"
|
|
echo "pr_comments_url=${pr_comments_url}"
|
|
} >> "$GITHUB_OUTPUT"
|
|
|
|
echo "PR Created 🎫"
|
|
|
|
- name: Set unified PR number output
|
|
id: set-pr-output
|
|
shell: bash
|
|
run: |
|
|
if [ -n "${{ steps.check-opened-pr-step.outputs.pr_number }}" ]; then
|
|
echo "pr_number=${{ steps.check-opened-pr-step.outputs.pr_number }}" >> $GITHUB_OUTPUT
|
|
echo "pr_url=${{ steps.skip-pr-creation.outputs.pr_url }}" >> $GITHUB_OUTPUT
|
|
echo "pr_comments_url=${{ steps.skip-pr-creation.outputs.pr_comments_url }}" >> $GITHUB_OUTPUT
|
|
echo "pr_comment_id=${{ steps.skip-pr-creation.outputs.pr_comment_id }}" >> $GITHUB_OUTPUT
|
|
echo "pr_comment_uri=${{ steps.skip-pr-creation.outputs.pr_comment_uri }}" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "pr_number=${{ steps.pr-creation.outputs.created_pr_index }}" >> $GITHUB_OUTPUT
|
|
echo "pr_url=${{ steps.pr-creation.outputs.pr_url }}" >> $GITHUB_OUTPUT
|
|
echo "pr_comments_url=${{ steps.pr-creation.outputs.pr_comments_url }}" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Verify outputs
|
|
shell: bash
|
|
run: |
|
|
echo "PR Number: ${{ steps.set-pr-output.outputs.pr_number }}"
|
|
echo "PR URL: ${{ steps.set-pr-output.outputs.pr_url }}"
|
|
echo "PR Comments: ${{ steps.set-pr-output.outputs.pr_comments_url }}"
|
|
echo "PR Comment ID: ${{ steps.set-pr-output.outputs.pr_comment_id }}"
|
|
echo "PR Comment URI: ${{ steps.set-pr-output.outputs.pr_comment_uri }}"
|