andreahlert commented on code in PR #750:
URL: https://github.com/apache/burr/pull/750#discussion_r3176421758


##########
scripts/milestone_management_preview.py:
##########
@@ -0,0 +1,120 @@
+#!/usr/bin/env python3
+# 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.
+"""Preview milestone selection for the milestone-management workflow.
+
+Examples:
+  python scripts/milestone_management_preview.py --base-branch main 
--open-milestones 0.43.0 0.43.1
+  python scripts/milestone_management_preview.py --base-branch release-0.43.1 
--open-milestones 0.43.0 0.43.1
+  python scripts/milestone_management_preview.py --base-branch v0.43-test 
--open-milestones 0.43.0
+"""
+
+import argparse
+import re

Review Comment:
   burr supports py3.9 per `pyproject.toml` but `str | None` on line 42 needs 
3.10+. import breaks on 3.9 and the test file blows up with it since it loads 
the module at top level.
   
   ```suggestion
   from __future__ import annotations
   
   import argparse
   import re
   import sys
   ```



##########
.github/workflows/milestone-management.yml:
##########
@@ -0,0 +1,228 @@
+#<!--
+#     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.
+#-->
+# Milestone management for release tracking
+#
+# - Auto-assigns milestones to merged PRs
+# - Supports main plus release/test branch naming conventions
+# - Can create/open upcoming release milestones on demand
+
+name: Milestone Management
+
+on:
+  pull_request_target:
+    types: [closed]
+  workflow_dispatch:
+    inputs:
+      versions:
+        description: "Comma- or newline-separated milestone versions in X.Y.Z 
format"
+        required: true
+        type: string
+
+permissions:
+  issues: write
+  pull-requests: read
+
+jobs:
+  assign-milestone:
+    if: github.event_name == 'pull_request_target' && 
github.event.pull_request.merged == true
+    runs-on: ubuntu-latest
+    steps:
+      - name: Assign milestone to merged PR
+        uses: actions/github-script@v7
+        with:
+          github-token: ${{ secrets.GITHUB_TOKEN }}
+          script: |
+            const SEMVER_RE = /^(\d+)\.(\d+)\.(\d+)$/;
+
+            function parseVersion(version) {
+              const match = version.match(SEMVER_RE);
+              if (!match) {
+                return null;
+              }
+              return match.slice(1).map(part => Number(part));
+            }
+
+            function compareVersions(left, right) {
+              const leftParts = parseVersion(left);
+              const rightParts = parseVersion(right);
+              for (let index = 0; index < 3; index += 1) {
+                if (leftParts[index] !== rightParts[index]) {
+                  return leftParts[index] - rightParts[index];
+                }
+              }
+              return 0;
+            }
+
+            function milestoneTitleForBranch(branchName) {
+              const exactPatterns = [
+                /^release[-/](\d+\.\d+\.\d+)$/,
+                /^apache-burr-(\d+\.\d+\.\d+)-release$/,
+                /^v(\d+\.\d+\.\d+)-test$/,
+              ];
+              for (const pattern of exactPatterns) {
+                const match = branchName.match(pattern);
+                if (match) {
+                  return match[1];
+                }
+              }
+
+              const minorPatterns = [
+                /^release[-/](\d+\.\d+)$/,
+                /^v(\d+\.\d+)-test$/,
+              ];
+              for (const pattern of minorPatterns) {
+                const match = branchName.match(pattern);
+                if (match) {
+                  return `${match[1]}.0`;
+                }
+              }
+
+              return null;
+            }
+
+            async function listMilestones(state) {
+              return github.paginate(github.rest.issues.listMilestones, {
+                owner: context.repo.owner,
+                repo: context.repo.repo,
+                state,
+                per_page: 100,
+              });
+            }
+
+            async function findMilestoneByTitle(title, state = "open") {
+              const milestones = await listMilestones(state);
+              return milestones.find(milestone => milestone.title === title) 
|| null;
+            }
+
+            async function findCurrentOpenMilestone() {
+              const openMilestones = await listMilestones("open");
+              const releaseMilestones = openMilestones
+                .filter(milestone => SEMVER_RE.test(milestone.title))
+                .sort((left, right) => compareVersions(left.title, 
right.title));
+
+              return releaseMilestones[0] || null;
+            }
+
+            const pr = context.payload.pull_request;
+            if (pr.milestone) {
+              console.log(`#${pr.number}: already has milestone 
${pr.milestone.title}, leaving unchanged`);
+              return;
+            }
+
+            let milestone = null;
+            if (pr.base.ref === "main") {
+              milestone = await findCurrentOpenMilestone();
+              if (!milestone) {
+                throw new Error(
+                  "No open X.Y.Z milestone found for main. Create one with the 
workflow_dispatch path first."

Review Comment:
   this fails the workflow run on every merge until a milestone exists. a 
`console.warn` + return would skip quietly instead of spamming failed-run 
notifications.
   
   ```suggestion
                   console.warn(`#${pr.number}: no open X.Y.Z milestone for 
main, skipping assignment.`);
                   return;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to