PR logic fixes.
This commit is contained in:
+51
-34
@@ -78,20 +78,27 @@ runs:
|
|||||||
|
|
||||||
- name: Check if open PR exists
|
- name: Check if open PR exists
|
||||||
id: check-opened-pr-step
|
id: check-opened-pr-step
|
||||||
shell: bash
|
|
||||||
continue-on-error: true
|
continue-on-error: true
|
||||||
|
shell: bash
|
||||||
|
env:
|
||||||
|
HEAD_BRANCH: ${{ github.head_ref != '' && github.head_ref || github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
pr_number=$(tea pr list \
|
set -euo pipefail
|
||||||
--repo ${{ github.repository }} \
|
echo "Checking for PR... 🔎"
|
||||||
|
|
||||||
|
pr_number="$(
|
||||||
|
tea pr list \
|
||||||
|
-r ${{ github.repository }} \
|
||||||
--state open \
|
--state open \
|
||||||
--fields index,head \
|
--fields index,head \
|
||||||
--output simple \
|
--output json \
|
||||||
| egrep "${{ github.ref_name }}" \
|
| jq -r --arg hb "$HEAD_BRANCH" '
|
||||||
| grep -oE '#[0-9]+' \
|
[.[] | select((.head|tostring) | contains($hb)) | .index][0] // empty
|
||||||
| head -n1 \
|
'
|
||||||
| tr -d '#')
|
)"
|
||||||
|
|
||||||
|
echo "pr_number=$pr_number" >> "$GITHUB_OUTPUT"
|
||||||
|
|
||||||
echo "pr_number=$pr_number" >> $GITHUB_OUTPUT
|
|
||||||
|
|
||||||
- name: Skip PR Creation
|
- name: Skip PR Creation
|
||||||
id: skip-pr-creation
|
id: skip-pr-creation
|
||||||
@@ -123,48 +130,58 @@ runs:
|
|||||||
env:
|
env:
|
||||||
PR_TITLE: ${{ inputs.pr-title }}
|
PR_TITLE: ${{ inputs.pr-title }}
|
||||||
PR_DESCRIP: ${{ inputs.pr-description }}
|
PR_DESCRIP: ${{ inputs.pr-description }}
|
||||||
|
HEAD_BRANCH: ${{ github.head_ref != '' && github.head_ref || github.ref_name }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
|
|
||||||
if [ -z "${PR_TITLE}" ]; then
|
if [ -z "${PR_TITLE}" ]; then PR_TITLE=$(git log -n 1 --format=%s); fi
|
||||||
PR_TITLE=$(git log -n 1 --format=%s)
|
if [ -z "${PR_DESCRIP}" ]; then PR_DESCRIP=$(git log -n 1 --format=%b); fi
|
||||||
fi
|
|
||||||
|
|
||||||
if [ -z "${PR_DESCRIP}" ]; then
|
out=""
|
||||||
PR_DESCRIP=$(git log -n 1 --format=%b)
|
created_pr_index=""
|
||||||
fi
|
set +e
|
||||||
|
out="$(tea pr create \
|
||||||
created_pr_index=$(tea pr create \
|
|
||||||
-r ${{ github.repository }} \
|
-r ${{ github.repository }} \
|
||||||
-t "${PR_TITLE}" \
|
-t "${PR_TITLE}" \
|
||||||
-d "${PR_DESCRIP}" \
|
-d "${PR_DESCRIP}" \
|
||||||
-a "${{ inputs.assignee }}" \
|
-a "${{ inputs.assignee }}" \
|
||||||
-L "${{ inputs.pr-label }}" \
|
-L "${{ inputs.pr-label }}" \
|
||||||
--output simple \
|
--output simple 2>&1)"
|
||||||
| grep -oE '#[0-9]+' \
|
rc=$?
|
||||||
| head -n1 \
|
set -e
|
||||||
| tr -d '#')
|
|
||||||
|
if [ $rc -eq 0 ]; then
|
||||||
|
created_pr_index="$(echo "$out" | grep -oE '#[0-9]+' | head -n1 | tr -d '#')"
|
||||||
|
else
|
||||||
|
if echo "$out" | grep -q "pull request already exists for these targets"; then
|
||||||
|
created_pr_index="$(
|
||||||
|
tea pr list \
|
||||||
|
-r ${{ github.repository }} \
|
||||||
|
--state open \
|
||||||
|
--fields index,head \
|
||||||
|
--output json \
|
||||||
|
| jq -r --arg hb "$HEAD_BRANCH" '
|
||||||
|
[.[] | select((.head|tostring) | contains($hb)) | .index][0] // empty
|
||||||
|
'
|
||||||
|
)"
|
||||||
|
else
|
||||||
|
echo "$out" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
if [[ -z "${created_pr_index}" || "${created_pr_index}" != [0-9]* ]]; then
|
if [[ -z "${created_pr_index}" || "${created_pr_index}" != [0-9]* ]]; then
|
||||||
echo "::error::Could not parse created PR index from tea output"
|
echo "::error::Could not determine PR index"
|
||||||
|
echo "$out"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
created_pr_url="${{ inputs.url }}/${{ github.repository }}/pulls/${created_pr_index}"
|
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"
|
pr_comments_url="${{ inputs.url }}/api/v1/repos/${{ github.repository }}/issues/${created_pr_index}/comments"
|
||||||
|
|
||||||
if [[ -z "${created_pr_index}" ]]; then
|
echo "created_pr_index=${created_pr_index}" >> "$GITHUB_OUTPUT"
|
||||||
echo "::error::tea pr create returned an empty PR index — check tea output format"
|
echo "pr_url=${created_pr_url}" >> "$GITHUB_OUTPUT"
|
||||||
exit 1
|
echo "pr_comments_url=${pr_comments_url}" >> "$GITHUB_OUTPUT"
|
||||||
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 🎫"
|
echo "PR Created 🎫"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user