Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Only apply milestone to PR if it exists [DOC-268] #16

Merged
merged 2 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions backport
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ if [ -n "$ORIGINAL_PR_NUMBER" ]; then
fi
fi
log_info "Creating new PR..."
gh pr create --base "$BASE_BRANCH" --title "$NEW_COMMIT_MSG" \
--body "Backport of $ORIGINAL_PR_URL$(echo -e "\n\n")$PR_BODY" \
--assignee "${GITHUB_ACTOR:-@me}" $REVIEWERS_ARG "${LABELS_ARG[@]}" --milestone "$SUFFIX" \
$( [ "$NON_INTERACTIVE" != true ] && echo "--web" )
gh pr create \
--base "${BASE_BRANCH}" \
--title "${NEW_COMMIT_MSG}" \
--body "Backport of ${ORIGINAL_PR_URL}$(echo -e "\n\n")${PR_BODY}" \
--assignee "${GITHUB_ACTOR:-@me}" \
${REVIEWERS_ARG} \
"${LABELS_ARG[@]}" \
$( [ "$(check_if_milestone_in_repo ${REPO_UPSTREAM} ${SUFFIX})" == "true" ] && echo "--milestone ${SUFFIX}" ) \
$( [ "${NON_INTERACTIVE}" != true ] && echo "--web" )
17 changes: 15 additions & 2 deletions backport.functions
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,27 @@ function get_pr_reviewers() {
local repo_upstream=$1
local pr_number=$2

gh api repos/"${repo_upstream}"/pulls/"${pr_number}"/reviews --jq '[.[] | select(.state == "APPROVED") | .user.login] | unique | join(",")'
gh api "repos/${repo_upstream}/pulls/${pr_number}/reviews" --jq '[.[] | select(.state == "APPROVED") | .user.login] | unique | join(",")'
}

function get_pr_labels() {
local repo_upstream=$1
local pr_number=$2

gh api repos/"${repo_upstream}"/pulls/"${pr_number}" --jq '[.labels[].name] | join(",")'
gh api "repos/${repo_upstream}/pulls/${pr_number}" --jq '[.labels[].name] | join(",")'
}

function check_if_milestone_in_repo() {
local repo_upstream=$1
local milestone=$2

response=$(gh api "repos/${repo_upstream}/milestones?state=all" --paginate --jq ".[] | select(.title == \"${milestone}\")")

if [[ -n "${response}" ]]; then
echo true
else
echo false
fi
}

# upstream/5.2.z -> 5.2z
Expand Down
14 changes: 14 additions & 0 deletions backport.functions_tests
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,15 @@ function test_get_pr_labels {
assert_eq "$expected_labels" "$actual_labels" "$MSG" && log_success "$MSG" || TESTS_RESULT=$?
}

function test_check_if_milestone_in_repo {
local repo_upstream=$1
local milestone=$2
local expected_output=$3
local actual_output=$(check_if_milestone_in_repo "$repo_upstream" "$milestone")
local MSG="Queried \"$repo_upstream\" for milestone \"$milestone\", expecting \"$expected_output\""
assert_eq "$expected_output" "$actual_output" "$MSG" && log_success "$MSG" || TESTS_RESULT=$?
}

function test_get_branch_from_ref {
local ref=$1
local expected_branch=$2
Expand All @@ -61,6 +70,11 @@ test_get_pr_reviewers 'hazelcast/backport' '1' 'ldziedziul'
log_header "Tests for get_pr_labels"
test_get_pr_labels 'hazelcast/backport' '1' 'enhancement'

log_header "Tests for check_if_milestone_in_repo"
# https://github.com/hazelcast/hazelcast/milestones
test_check_if_milestone_in_repo 'hazelcast/hazelcast' '2.1' 'true'
test_check_if_milestone_in_repo 'hazelcast/hazelcast' 'this-milestone-does-not-exist' 'false'

log_header "Tests for get_branch_from_ref"
test_get_branch_from_ref 'upstream/5.2.z' '5.2.z'
test_get_branch_from_ref 'upstream/v/5.2' 'v/5.2'
Expand Down