sunchao commented on code in PR #5762:
URL: https://github.com/apache/datafusion-comet/pull/5762#discussion_r3959978511


##########
.github/workflows/label_prs.yml:
##########
@@ -0,0 +1,93 @@
+# 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.
+
+name: Label pull requests
+
+# Runs on pull_request_target so it can label pull requests from forks. 
Nothing from the pull
+# request is checked out or executed: the labeler reads the changed file list 
through the API
+# and the title step reads the event payload.
+on:
+  pull_request_target:
+    types: [opened, synchronize, reopened]
+
+permissions:
+  contents: read
+  pull-requests: write
+
+# One group per pull request with cancellation, so at most one run writes 
labels at a time:
+# the labeler action reads the label set and writes it back whole, and two 
runs writing at
+# once can drop a label the other just added. A cancelled or replaced run 
loses nothing
+# because every step below is safe to repeat on the next event.
+concurrency:
+  group: ${{ github.workflow }}-${{ github.event.pull_request.number }}
+  cancel-in-progress: true
+
+jobs:
+  label:
+    runs-on: ubuntu-slim
+    steps:
+      # The type label follows the conventional commit prefix in the title, 
matching how
+      # maintainers label by hand. It is added only while the pull request 
carries no type
+      # label at all, so a hand-picked replacement stays, and a run cut short 
by a newer push
+      # is completed by that push. Dependabot pull requests already carry 
their label.
+      - name: Label by title prefix
+        if: github.actor != 'dependabot[bot]'
+        uses: actions/github-script@v9
+        with:
+          script: |
+            const title = context.payload.pull_request.title.trim();
+            const match = 
/^(feat|fix|perf|test|docs?|chore|refactor|ci|build|deps)(\([^)]*\))?!?:/i.exec(title);
+            if (!match) {
+              core.info(`No conventional prefix in "${title}", skipping the 
type label`);
+              return;
+            }
+            const byPrefix = {
+              feat: ['enhancement'],
+              refactor: ['enhancement'],
+              chore: ['enhancement'],
+              fix: ['bug'],
+              perf: ['enhancement', 'performance'],
+              test: ['enhancement', 'test'],
+              doc: ['documentation'],
+              docs: ['documentation'],
+              ci: ['enhancement', 'build'],
+              build: ['enhancement', 'build'],
+              deps: ['dependencies'],
+            };
+            const labels = byPrefix[match[1].toLowerCase()];
+            const typeLabels = new Set(Object.values(byPrefix).flat());
+            const present = new 
Set(context.payload.pull_request.labels.map((l) => l.name));
+            if ([...present].some((l) => typeLabels.has(l))) {
+              core.info('A type label is already present, leaving it as is');
+              return;

Review Comment:
   ### Correctness
   
   [P2] Read current labels before deciding no type label exists
   
   Could this guard fetch the PR's current labels rather than using 
`context.payload.pull_request.labels`? That is the [triggering webhook 
payload](https://docs.github.com/en/actions/reference/workflows-and-actions/contexts#github-context),
 so a `synchronize` event can contain no type labels even when a maintainer has 
finished adding `enhancement` before its queued run starts. For a `fix:` title, 
this check still passes and adds `bug` alongside that choice. Label changes do 
not dispatch this workflow, and the later path step preserves both labels. This 
does not require overlapping runs or a manual write during the check, and 
differs from the documented case of intentionally removing every type label. 
Reading current labels before the decision would respect an already-completed 
maintainer choice. Please add a regression where event labels are empty but 
current labels contain a type. The exact inline script confirmed this branch 
with an in-memory API double, with no real label writes.
   



-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to