forked from rancher/dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request rancher#10521 from rak-phillip/bugfix/10511-port-pr
[Workflow] Port PR: Fix issues with assignees and relaying error messages
- Loading branch information
Showing
1 changed file
with
24 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,22 +80,38 @@ jobs: | |
git config --global user.email "[email protected]" | ||
git config --global user.name "Rancher Dashboard Port Bot" | ||
git checkout -b $BRANCH | ||
git am -3 "$PATCH_FILE" 2> error.log | ||
GIT_AM_EXIT_CODE=$? | ||
if [ "$GIT_AM_EXIT_CODE" -ne 0 ]; then | ||
ERROR_MESSAGE=$(cat error.log) | ||
FORMATTED_ERROR_MESSAGE=$(printf "\n```\n%s\n```" "$ERROR_MESSAGE") | ||
gh issue comment ${ORIGINAL_ISSUE_NUMBER} --body "Not creating port PR, there was an error running git am -3: $FORMATTED_ERROR_MESSAGE" | ||
if ! git am -3 "$PATCH_FILE" > error.log 2>&1; then | ||
ERROR_MESSAGE=$(cat error.log) | ||
FORMATTED_ERROR_MESSAGE=$(printf "\n\`\`\`\n%s\n\`\`\`" "$ERROR_MESSAGE") | ||
gh issue comment ${ORIGINAL_ISSUE_NUMBER} --body "Not creating port PR, there was an error running git am -3: $FORMATTED_ERROR_MESSAGE" | ||
else | ||
git push origin $BRANCH | ||
ORIGINAL_PR=$(gh pr view ${ORIGINAL_ISSUE_NUMBER} --json title,body,assignee) | ||
ORIGINAL_PR=$(gh pr view ${ORIGINAL_ISSUE_NUMBER} --json title,body,assignees) | ||
ORIGINAL_TITLE=$(echo "${ORIGINAL_PR}" | jq -r .title) | ||
ORIGINAL_ASSIGNEE=$(echo "${ORIGINAL_PR}" | jq -r '.assignee.login // empty') | ||
BODY=$(mktemp) | ||
echo -e "This is an automated request to port PR #${ORIGINAL_ISSUE_NUMBER} by @${GITHUB_ACTOR}\n\n" > $BODY | ||
echo -e "Original PR body:\n\n" >> $BODY | ||
echo "${ORIGINAL_PR}" | jq -r .body >> $BODY | ||
NEW_PR=$(gh pr create --title="[${TYPE} ${MILESTONE}] ${ORIGINAL_TITLE}" --body-file="${BODY}" --head "${BRANCH}" --base "${TARGET_BRANCH}" --milestone "${MILESTONE}" --assignee "${ORIGINAL_ASSIGNEE}") | ||
ASSIGNEES=$(echo "${ORIGINAL_PR}" | jq -r .assignees[].login) | ||
if [ -n "$ASSIGNEES" ]; then | ||
echo "Checking if assignee is member before assigning" | ||
DELIMITER="" | ||
NEW_ASSIGNEES="" | ||
for ASSIGNEE in $ASSIGNEES; do | ||
if gh api orgs/${GITHUB_REPOSITORY_OWNER}/members --paginate | jq -e --arg GITHUB_ACTOR "$GITHUB_ACTOR" '.[] | select(.login == $GITHUB_ACTOR)' > /dev/null; then | ||
echo "${ASSIGNEE} is a member, adding to assignees" | ||
NEW_ASSIGNEES="${NEW_ASSIGNEES}${DELIMITER}${ASSIGNEE}" | ||
DELIMITER="," | ||
fi | ||
done | ||
if [ -n "$NEW_ASSIGNEES" ]; then | ||
echo "Assignees for new issue: ${NEW_ASSIGNEES}" | ||
additional_cmd+=("--assignee") | ||
additional_cmd+=("${NEW_ASSIGNEES}") | ||
fi | ||
fi | ||
NEW_PR=$(gh pr create --title="[${TYPE} ${MILESTONE}] ${ORIGINAL_TITLE}" --body-file="${BODY}" --head "${BRANCH}" --base "${TARGET_BRANCH}" --milestone "${MILESTONE}" "${additional_cmd[@]}") | ||
echo "Port PR created: ${NEW_PR}" >> $GITHUB_STEP_SUMMARY | ||
fi |