|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | + |
| 20 | +# Assign the milestone on PRs/issues. This used to be done by CI, but since |
| 21 | +# we can no longer use pull_request_target workflows, do it manually instead. |
| 22 | + |
| 23 | +set -euo pipefail |
| 24 | + |
| 25 | +SOURCE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" |
| 26 | +source "${SOURCE_DIR}/utils-common.sh" |
| 27 | + |
| 28 | +main() { |
| 29 | + # Scan the Git log for PRs since the last release |
| 30 | + local -r commits=$(git log --abbrev-commit --pretty=oneline apache-arrow-adbc-${PREVIOUS_RELEASE}..) |
| 31 | + local -r pr_numbers=$(echo "${commits}" | grep -E -o ' \(#[0-9]+\)$' | grep -E -o '[0-9]+') |
| 32 | + |
| 33 | + local -r milestone=$(gh api graphql \ |
| 34 | + --paginate \ |
| 35 | + --jq ".data.repository.milestones.nodes.[]" \ |
| 36 | + -f query="{ |
| 37 | + repository(owner: \"apache\", name: \"arrow-adbc\") { |
| 38 | + milestones(states: [OPEN], first: 10, query: \"ADBC Libraries ${RELEASE}\") { |
| 39 | + nodes { |
| 40 | + id |
| 41 | + title |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | +}") |
| 46 | + local -r milestone_title=$(echo "${milestone}" | jq -r '.title') |
| 47 | + |
| 48 | + echo "Milestone to use: ${milestone_title}" |
| 49 | + read -p "Press ENTER to continue..." ignored |
| 50 | + |
| 51 | + for pr_number in ${pr_numbers}; do |
| 52 | + local pr=$(gh api graphql \ |
| 53 | + --paginate \ |
| 54 | + --jq ".data.repository.pullRequest" \ |
| 55 | + -f query="{ |
| 56 | + repository(owner: \"apache\", name: \"arrow-adbc\") { |
| 57 | + pullRequest(number: ${pr_number}) { |
| 58 | + title |
| 59 | + milestone { |
| 60 | + title |
| 61 | + } |
| 62 | + closingIssuesReferences(first: 10) { |
| 63 | + nodes { |
| 64 | + number |
| 65 | + milestone { |
| 66 | + title |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + } |
| 72 | +}") |
| 73 | + |
| 74 | + local existing_milestone=$(echo "${pr}" | jq -r '.milestone.title') |
| 75 | + if [[ "${existing_milestone}" != "null" ]]; then |
| 76 | + echo "#${pr_number}: has milestone \`${existing_milestone}\`" |
| 77 | + else |
| 78 | + echo "#${pr_number}: assigning ${milestone_title}" |
| 79 | + gh pr edit "${pr_number}" --milestone "${milestone_title}" |
| 80 | + sleep 0.3 |
| 81 | + fi |
| 82 | + |
| 83 | + echo "${pr}" | jq -c '.closingIssuesReferences.nodes.[]' | while read -r issue; do |
| 84 | + local issue_number=$(echo "${issue}" | jq -r '.number') |
| 85 | + local issue_milestone=$(echo "${issue}" | jq -r '.milestone.title') |
| 86 | + if [[ "${issue_milestone}" != "null" ]]; then |
| 87 | + echo " linked issue #${issue_number}: has milestone \`${issue_milestone}\`" |
| 88 | + else |
| 89 | + echo " linked issue #${issue_number}: assigning ${milestone_title}" |
| 90 | + gh issue edit "${issue_number}" --milestone "${milestone_title}" |
| 91 | + sleep 0.3 |
| 92 | + fi |
| 93 | + done |
| 94 | + |
| 95 | + sleep 0.3 |
| 96 | + done |
| 97 | +} |
| 98 | + |
| 99 | +main "$@" |
0 commit comments