This is an automated email from the ASF dual-hosted git repository.

lidavidm pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-adbc.git


The following commit(s) were added to refs/heads/main by this push:
     new 2ef0d20c ci: auto-assign milestones to pull requests (#1301)
2ef0d20c is described below

commit 2ef0d20c1a66e88a095b9006708b1672446b6604
Author: David Li <[email protected]>
AuthorDate: Mon Nov 20 09:36:05 2023 -0500

    ci: auto-assign milestones to pull requests (#1301)
    
    Fixes #1296.
    
    ---------
    
    Co-authored-by: Sutou Kouhei <[email protected]>
---
 .github/workflows/dev_pr.yml          |  7 +++++
 .github/workflows/dev_pr/milestone.sh | 55 +++++++++++++++++++++++++++++++++++
 2 files changed, 62 insertions(+)

diff --git a/.github/workflows/dev_pr.yml b/.github/workflows/dev_pr.yml
index 3d6cb852..ed9852b8 100644
--- a/.github/workflows/dev_pr.yml
+++ b/.github/workflows/dev_pr.yml
@@ -48,3 +48,10 @@ jobs:
           script: |
             const script = 
require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_pr/title_check.js`);
             await script({github, context});
+
+      - name: Assign milestone
+        if: always()
+        env:
+          GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
+        run: |
+          ./.github/workflows/dev_pr/milestone.sh "${GITHUB_REPOSITORY}" 
${{github.event.number}}
diff --git a/.github/workflows/dev_pr/milestone.sh 
b/.github/workflows/dev_pr/milestone.sh
new file mode 100755
index 00000000..7d50bc4c
--- /dev/null
+++ b/.github/workflows/dev_pr/milestone.sh
@@ -0,0 +1,55 @@
+#!/usr/bin/env bash
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Assign a milestone to the given PR based on the open milestones and known
+# releases.
+
+set -euo pipefail
+
+main() {
+    local -r repo="${1}"
+    local -r pr_number="${2}"
+    echo "On ${repo} pull ${pr_number}"
+
+    local -r existing_milestone=$(gh pr view "${pr_number}" \
+                                  --json milestone \
+                                  -t '{{if 
.milestone}}{{.milestone.title}}{{end}}')
+
+    if [[ -n "${existing_milestone}" ]]; then
+        echo "PR has milestone: ${existing_milestone}"
+        return 0
+    fi
+
+    local -r latest_version=$(git ls-remote --heads origin |
+                                  grep -o '[0-9.]*$' |
+                                  sort --version-sort |
+                                  tail -n1)
+
+    local -r milestone=$(gh api "/repos/${repo}/milestones" |
+                             jq -r '.[] | .title' |
+                             grep -E '^ADBC Libraries' |
+                             grep -v "${latest_version}" |
+                             head -n1)
+
+    echo "Latest tagged version: ${latest_version}"
+    echo "Assigning milestone: ${milestone}"
+
+    gh pr edit "${pr_number}" -m "${milestone}"
+}
+
+main "$@"

Reply via email to