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: API endpoint for grabbing all comments of a PR value: ${{ steps.set-pr-output.outputs.pr_comment_id }} 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: | 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 shell: bash id: check-opened-pr-step 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}') 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 -e "✅ A PR already exists for ${{ github.ref_name }} (PR #${{ steps.check-opened-pr-step.outputs.pr_number }})" created_pr_url=$(tea pr ls --state open \ -r ${{ github.repository }} \ -f index,url \ -o simple \ | egrep "${{ steps.check-opened-pr-step.outputs.pr_number }}" | awk '{print $2}') pr_comments_url=$(echo "${{ gitea.api_url }}/repos/${{ gitea.repository }}/issues/${{ steps.check-opened-pr-step.outputs.pr_number }}/comments") ${pr_comments_url} pr_comment_id=$(curl -sS -X GET ${pr_comments_url} | jq -r '[.[] | select(.user.login == "gitea-sonarqube-bot")] | sort_by(.created_at) | last | .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 - name: PR Creation shell: bash if: steps.check-opened-pr-step.outputs.pr_number == '' id: pr-creation env: PR_TITLE: ${{ inputs.pr-title }} PR_DESCRIP: ${{ inputs.pr-description }} run: | 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 c -r ${{ github.repository }} \ -t "${PR_TITLE}" \ -d "${PR_DESCRIP}" \ -a ${{ inputs.assignee }} \ -L "${{ inputs.pr-label }}" \ --output simple \ | awk '{print $1}') created_pr_url=$(tea pr ls --state open \ -r ${{ github.repository }} \ -f index,url \ -o simple \ | egrep '${created_pr_index}' | awk '{print $2}') pr_comments_url=$(echo "${{ gitea.api_url }}/repos/${{ gitea.repository }}/issues/${{ steps.check-opened-pr-step.outputs.pr_number }}/comments") ${pr_comments_url} echo "PR Created 🎫 (PR \#$created_pr_index) - $created_pr_url" echo "created_pr_index=$created_pr_index" >> $GITHUB_OUTPUT echo "pr_url=$created_pr_url" >> $GITHUB_OUTPUT echo "pr_comments_url=$pr_comments_url" >> $GITHUB_OUTPUT - name: Set unified PR number output id: set-pr-output shell: bash env: EXISTING_PR: ${{ steps.check-opened-pr-step.outputs.pr_number }} CREATED_PR: ${{ steps.pr-creation.outputs.created_pr_index }} EXISTING_URL: ${{ steps.skip-pr-creation.outputs.pr_url }} CREATED_URL: ${{ steps.pr-creation.outputs.pr_url }} EXISTING_COMMENTS_URL: ${{ steps.skip-pr-creation.outputs.pr_url }} EXISTING_COMMENT_ID: ${{ steps.skip-pr-creation.outputs.pr_url }} run: | if [ -n "$EXISTING_PR" ]; then echo "pr_number=$EXISTING_PR" >> $GITHUB_OUTPUT echo "pr_url=$EXISTING_URL" >> $GITHUB_OUTPUT echo "pr_comments_url=$EXISTING_COMMENTS_URL" >> $GITHUB_OUTPUT echo "pr_comment_id=$EXISTING_COMMENT_ID" >> $GITHUB_OUTPUT else echo "pr_number=$CREATED_PR" >> $GITHUB_OUTPUT echo "pr_url=$CREATED_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 }}"