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


##########
.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:
   Yes, the payload is stale by the time a queued run starts. In d7e105116 the 
decision reads the pull request's current labels through the API before 
deciding, and the logic now lives in `dev/ci/pr-type-label.mjs` so it can be 
tested: `dev/ci/pr-type-label.test.mjs` covers the case you describe (event 
labels empty, current labels already carry a type, nothing added) alongside the 
normal addition, a title without a prefix, and an already-present label, and 
Preflight runs it. The workflow checks out the base branch to read that module; 
under pull_request_target the default ref is the base commit, and nothing from 
the pull request is read or executed.



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