|
30 | 30 | compare_url="$(echo "${compare_json}" | jq -r '.html_url')" |
31 | 31 | ahead_by="$(echo "${compare_json}" | jq -r '.ahead_by')" |
32 | 32 |
|
| 33 | + if [ "${ahead_by}" -eq 0 ]; then |
| 34 | + echo "staging is not ahead of production (ahead_by=0). Nothing to do." |
| 35 | + exit 0 |
| 36 | + fi |
| 37 | +
|
33 | 38 | prs_tsv="$(mktemp)" |
34 | 39 | while IFS= read -r sha; do |
35 | 40 | [ -n "${sha}" ] || continue |
@@ -58,38 +63,32 @@ jobs: |
58 | 63 | echo "- Compare: ${compare_url}" |
59 | 64 | } > "${pr_body_file}" |
60 | 65 |
|
61 | | - pr_number="$(gh api "repos/${REPO}/pulls" \ |
62 | | - -f state="open" \ |
63 | | - -f base="${DESTINATION_BRANCH}" \ |
64 | | - -f head="${OWNER}:${SOURCE_BRANCH}" \ |
| 66 | + pr_number="$(gh pr list \ |
| 67 | + --repo "${REPO}" \ |
| 68 | + --base "${DESTINATION_BRANCH}" \ |
| 69 | + --head "${SOURCE_BRANCH}" \ |
| 70 | + --state open \ |
| 71 | + --json number \ |
65 | 72 | --jq '.[0].number // empty')" |
66 | 73 |
|
67 | 74 | if [ -z "${pr_number}" ]; then |
68 | 75 | echo "No open PR found for ${SOURCE_BRANCH} -> ${DESTINATION_BRANCH}. Creating one." |
69 | | - create_payload="$(jq -n \ |
70 | | - --arg title "${PR_TITLE}" \ |
71 | | - --arg head "${SOURCE_BRANCH}" \ |
72 | | - --arg base "${DESTINATION_BRANCH}" \ |
73 | | - --rawfile body "${pr_body_file}" \ |
74 | | - '{title: $title, head: $head, base: $base, body: $body}')" |
75 | | -
|
76 | | - pr_number="$(gh api \ |
77 | | - -X POST "repos/${REPO}/pulls" \ |
78 | | - --input - \ |
79 | | - --jq '.number' <<<"${create_payload}")" |
| 76 | + pr_url="$(gh pr create \ |
| 77 | + --repo "${REPO}" \ |
| 78 | + --base "${DESTINATION_BRANCH}" \ |
| 79 | + --head "${SOURCE_BRANCH}" \ |
| 80 | + --title "${PR_TITLE}" \ |
| 81 | + --body-file "${pr_body_file}")" |
| 82 | + pr_number="${pr_url##*/}" |
80 | 83 | else |
81 | 84 | echo "Updating existing PR #${pr_number}." |
82 | | - update_payload="$(jq -n \ |
83 | | - --arg title "${PR_TITLE}" \ |
84 | | - --rawfile body "${pr_body_file}" \ |
85 | | - '{title: $title, body: $body}')" |
86 | | -
|
87 | | - gh api \ |
88 | | - -X PATCH "repos/${REPO}/pulls/${pr_number}" \ |
89 | | - --input - <<<"${update_payload}" >/dev/null |
| 85 | + gh pr edit "${pr_number}" \ |
| 86 | + --repo "${REPO}" \ |
| 87 | + --title "${PR_TITLE}" \ |
| 88 | + --body-file "${pr_body_file}" |
90 | 89 | fi |
91 | 90 |
|
92 | | - gh api \ |
93 | | - -X POST "repos/${REPO}/pulls/${pr_number}/requested_reviewers" \ |
94 | | - -f reviewers[]="${REVIEWER}" >/dev/null || \ |
| 91 | + gh pr edit "${pr_number}" \ |
| 92 | + --repo "${REPO}" \ |
| 93 | + --add-reviewer "${REVIEWER}" || \ |
95 | 94 | echo "Reviewer assignment skipped for ${REVIEWER}." |
0 commit comments