Skip to content

Commit

Permalink
Merge pull request rancher#10521 from rak-phillip/bugfix/10511-port-pr
Browse files Browse the repository at this point in the history
[Workflow] Port PR: Fix issues with assignees and relaying error messages
  • Loading branch information
rak-phillip authored Mar 1, 2024
2 parents af1766e + f1e75b1 commit 7d1cb87
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions .github/workflows/port-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 7d1cb87

Please sign in to comment.