You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kafka.apache.org by da...@apache.org on 2024/12/18 18:13:23 UTC

(kafka) branch trunk updated: MINOR Remove triage label in nightly job (#18147)

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

davidarthur pushed a commit to branch trunk
in repository https://gitbox.apache.org/repos/asf/kafka.git


The following commit(s) were added to refs/heads/trunk by this push:
     new 5e9605a27df MINOR Remove triage label in nightly job (#18147)
5e9605a27df is described below

commit 5e9605a27dfea490d94d17a315a767f502ff4b49
Author: David Arthur <mu...@gmail.com>
AuthorDate: Wed Dec 18 13:13:15 2024 -0500

    MINOR Remove triage label in nightly job (#18147)
    
    For PRs that have been reviewed (by anyone, not just a committer), remove the "triage" label. This job runs once per night.
    
    Reviewers: Justine Olshan <jo...@confluent.io>, Chia-Ping Tsai <ch...@gmail.com>
---
 .github/workflows/README.md               | 10 +++----
 .github/workflows/pr-reviewed-trigger.yml | 42 --------------------------
 .github/workflows/pr-reviewed.yml         | 49 ++++++++++++++++++-------------
 3 files changed, 33 insertions(+), 68 deletions(-)

diff --git a/.github/workflows/README.md b/.github/workflows/README.md
index 24116f32dd6..29a72b188c0 100644
--- a/.github/workflows/README.md
+++ b/.github/workflows/README.md
@@ -67,13 +67,11 @@ Unlike trunk, the PR builds _will_ utilize the Gradle cache.
 ### PR Triage
 
 In order to get the attention of committers, we have a triage workflow for Pull Requests
-opened by non-committers. This workflow consists of three files:
+opened by non-committers. This workflow consists of two files:
 
-* [pr-update.yml](pr-update.yml) When a PR is created add the `triage` label if the PR
+* [pr-update.yml](pr-update.yml) When a PR is created, add the `triage` label if the PR
   was opened by a non-committer.
-* [pr-reviewed-trigger.yml](pr-reviewed-trigger.yml) Runs when any PR is reviewed. 
-  Used as a trigger for the next workflow
-* [pr-reviewed.yml](pr-reviewed.yml) Remove the `triage` label after a PR has been reviewed
+* [pr-reviewed.yml](pr-reviewed.yml) Cron job to remove the `triage` label from PRs which have been reviewed
 
 _The pr-update.yml workflow includes pull_request_target!_
 
@@ -100,7 +98,7 @@ There are two files related to this workflow:
 
 * [pr-labeled.yml](pr-labeled.yml) approves a pending approval for PRs that have
 been labeled with `ci-approved`
-* [ci-requested.yml](ci-requested.yml) approves future CI requests automatically
+* [ci-requested.yml](ci-requested.yml) approves future workflow requests automatically
 if the PR has the `ci-approved` label
 
 _The pr-labeled.yml workflow includes pull_request_target!_
diff --git a/.github/workflows/pr-reviewed-trigger.yml b/.github/workflows/pr-reviewed-trigger.yml
deleted file mode 100644
index f089176ff4b..00000000000
--- a/.github/workflows/pr-reviewed-trigger.yml
+++ /dev/null
@@ -1,42 +0,0 @@
-# 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: Pull Request Reviewed
-
-on:
-  pull_request_review:
-    types:
-      - submitted
-
-jobs:
-  # This job is a workaround for the fact that pull_request_review lacks necessary permissions to modify PRs.
-  # Also, there is no pull_request_target analog to pull_request_review. The approach taken here is taken from
-  # https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/.
-  pr-review-trigger:
-    name: Reviewed
-    runs-on: ubuntu-latest
-    steps:
-      - name: Env
-        run: printenv
-        env:
-          GITHUB_CONTEXT: ${{ toJson(github) }}
-      - name: Capture PR Number
-        run:
-          echo ${{ github.event.pull_request.number }} >> pr-number.txt
-      - name: Archive Event
-        uses: actions/upload-artifact@v4
-        with:
-          name: pr-number.txt
-          path: pr-number.txt
diff --git a/.github/workflows/pr-reviewed.yml b/.github/workflows/pr-reviewed.yml
index ea2a35f58e8..d39a7abf0a0 100644
--- a/.github/workflows/pr-reviewed.yml
+++ b/.github/workflows/pr-reviewed.yml
@@ -16,39 +16,48 @@
 name: Remove Triage Label
 
 on:
-  workflow_run:
-    workflows: [Pull Request Reviewed]
-    types:
-      - completed
+  workflow_dispatch:      # Let us run manually
+
+  schedule:
+    - cron: '0 3 * * *'    # Run at 3:00 UTC nightly -- just before the "stale.yml" workflow
 
 jobs:
-  # This job runs with elevated permissions and the ability to modify pull requests. The steps taken here
-  # should be limited to updating labels and adding comments to PRs. This approach is taken from
-  # https://securitylab.github.com/resources/github-actions-preventing-pwn-requests/.
   remove-triage:
-    if: ${{ github.event.workflow_run.conclusion == 'success' }}
     runs-on: ubuntu-latest
     steps:
       - name: Env
         run: printenv
         env:
           GITHUB_CONTEXT: ${{ toJson(github) }}
-      - uses: actions/download-artifact@v4
-        with:
-          github-token: ${{ github.token }}
-          run-id: ${{ github.event.workflow_run.id }}
-          name: pr-number.txt
       - name: Remove label
         uses: actions/github-script@v7
         continue-on-error: true
         with:
           github-token: ${{ secrets.GITHUB_TOKEN }}
           script: |
-            var fs = require('fs');
-            var pr_number = Number(fs.readFileSync('./pr-number.txt'));
-            await github.rest.issues.removeLabel({
-              owner: context.repo.owner,
-              repo: context.repo.repo,
-              issue_number: pr_number,
-              name: 'triage'
+            github.paginate("GET /search/issues{?q}", {
+              q: "repo:apache/kafka label:triage is:pull-request"
+            })
+            .then((pulls) => {
+              pulls.forEach(pull => {
+                github.request("GET /repos/{owner}/{repo}/pulls/{pull_number}/reviews", {
+                  owner: "apache",
+                  repo: "kafka",
+                  pull_number: pull.number,
+                  headers: {
+                    "X-GitHub-Api-Version": "2022-11-28"
+                  }
+                }).then((resp) => {
+                  console.log("Found " + resp.data.length + " reviews for PR " + pull.number);
+                  if (resp.data.length > 0) {
+                    console.log("Removing 'triage' label from PR " + pull.number + " : " + pull.title);
+                    github.rest.issues.removeLabel({
+                      owner: "apache",
+                      repo: "kafka",
+                      issue_number: pull.number,
+                      name: "triage"
+                    });
+                  }
+                });
+              });
             });