Skip to content

Commit

Permalink
Merge pull request #33 from JarvusInnovations/releases/github-actions…
Browse files Browse the repository at this point in the history
…/release-publish/r2

fix(github-actions/release-publish): migrate to gh CLI
  • Loading branch information
themightychris authored Nov 15, 2023
2 parents 5c76039 + f24b354 commit ab53bce
Showing 1 changed file with 21 additions and 17 deletions.
38 changes: 21 additions & 17 deletions github-actions/release-prepare/pull-request.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,29 @@ else
fi

# create or update PR
pr_title="Release: ${latest_release_bumped}"
pr_body="$(cat <<EOF
Release: ${latest_release_bumped}
## Improvements
## Technical
EOF
)"

pr_number=$(hub pr list -h "${GITHUB_REF_NAME}" -f '%I')
pr_number=$(gh pr view "helm-chart" --json number --jq '.number')

if [ -n "${pr_number}" ]; then
echo "Updating PR #${pr_number}"
existing_comment_id=$(hub api "/repos/${GITHUB_REPOSITORY}/issues/${pr_number}/comments" | jq '.[] | select(.body | startswith("## Changelog\n\n")) | .id')
existing_comment_id=$(gh api "/repos/${GITHUB_REPOSITORY}/issues/${pr_number}/comments" --jq '.[] | select(.body | startswith("## Changelog\n\n")) | .id')
else
echo "Opening PR"
hub pull-request -b "${RELEASE_BRANCH}" -h "${GITHUB_REF_NAME}" -F <(echo "${pr_body}") > /tmp/pr.json
pr_number=$(hub pr list -h "${GITHUB_REF_NAME}" -f '%I')
pr_url=$(gh pr create \
--base "${RELEASE_BRANCH}" \
--head "${GITHUB_REF_NAME}" \
--title "${pr_title}" \
--body "${pr_body}"
)
pr_number="${pr_url##*/}"
echo "Opened PR #${pr_number}"
fi

Expand All @@ -52,18 +56,18 @@ while read -r commit; do
line=""

if [[ "${subject}" =~ Merge\ pull\ request\ \#([0-9]+) ]]; then
line="$(hub pr show -f '%t [%i] @%au' "${BASH_REMATCH[1]}" || true)"
line="$(gh pr view "${BASH_REMATCH[1]}" --json title,number,author --template '{{.title}} [#{{.number}}] @{{.author.login}}' || true)"
fi

if [ -z "${line}" ]; then
author="$(hub api "/repos/${GITHUB_REPOSITORY}/commits/${commit}" -H Accept:application/vnd.github.v3+json | jq -r '.author.login')"
if [ -n "${author}" ]; then
author="@${author}"
else
author="$(git show -s --format=%ae "${commit}")"
fi

line="${subject} ${author}"
author="$(gh api "/repos/${GITHUB_REPOSITORY}/commits/${commit}" | jq -r '.author.login')"
if [ -n "${author}" ]; then
author="@${author}"
else
author="$(git show -s --format=%ae "${commit}")"
fi

line="${subject} ${author}"
fi

# move ticket number prefix into to existing square brackets at end
Expand Down Expand Up @@ -91,8 +95,8 @@ EOF

if [ -n "${existing_comment_id}" ]; then
echo "Updating comment #${existing_comment_id}"
hub api "/repos/${GITHUB_REPOSITORY}/issues/comments/${existing_comment_id}" -f body="${comment_body}"
gh api "/repos/${GITHUB_REPOSITORY}/issues/comments/${existing_comment_id}" -f body="${comment_body}"
else
echo "Creating comment"
hub api "/repos/${GITHUB_REPOSITORY}/issues/${pr_number}/comments" -f body="${comment_body}"
gh pr comment "${pr_number}" --body "${comment_body}"
fi

0 comments on commit ab53bce

Please sign in to comment.