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

philo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-gluten.git


The following commit(s) were added to refs/heads/main by this push:
     new 05b0389099 [INFRA] Link referenced issues in PR description and unify 
with label pull requests job (#10863)
05b0389099 is described below

commit 05b0389099d753b678f26eff0aceff84515dadf1
Author: PHILO-HE <[email protected]>
AuthorDate: Mon Oct 13 12:10:48 2025 +0800

    [INFRA] Link referenced issues in PR description and unify with label pull 
requests job (#10863)
---
 .../{issues_link.js => pr_issue_linker.js}         | 56 +++++++++++-----------
 .github/workflows/labeler.yml                      | 29 -----------
 .github/workflows/{dev_cron.yml => pr_bot.yml}     | 29 +++++++----
 3 files changed, 47 insertions(+), 67 deletions(-)

diff --git a/.github/workflows/dev_cron/issues_link.js 
b/.github/workflows/dev_cron/pr_issue_linker.js
similarity index 51%
rename from .github/workflows/dev_cron/issues_link.js
rename to .github/workflows/dev_cron/pr_issue_linker.js
index e47ecb50a5..2fa2c7cd5e 100644
--- a/.github/workflows/dev_cron/issues_link.js
+++ b/.github/workflows/dev_cron/pr_issue_linker.js
@@ -15,7 +15,7 @@
  * limitations under the License.
  */
 
-function detectISSUESID(title) {
+function detectIssueID(title) {
   if (!title) {
     return null;
   }
@@ -23,48 +23,46 @@ function detectISSUESID(title) {
   if (!matched) {
     return null;
   }
-  const issues_number = matched[0].replace(/[^0-9]/ig,"");
-  return issues_number;
+  // Currently only consider one GitHub issue is referenced.
+  const issueID = matched[0].replace(/[^0-9]/ig, "");
+  return issueID;
 }
 
-async function haveComment(github, context, pullRequestNumber, body) {
-  const options = {
+async function appendToPRDescription(github, context, pullRequestNumber, 
issuesID) {
+  const issueURL = 
`https://github.com/apache/incubator-gluten/issues/${issuesID}`;
+  const issueReference = `#${issuesID}`
+
+  // Fetch the current PR description.
+  const { data: pullRequest } = await github.rest.pulls.get({
     owner: context.repo.owner,
     repo: context.repo.repo,
-    issue_number: pullRequestNumber,
-    page: 1
-  };
-  while (true) {
-    const response = await github.rest.issues.listComments(options);
-    if (response.data.some(comment => comment.body === body)) {
-      return true;
-    }
-    if (!/;\s*rel="next"/.test(response.headers.link || "")) {
-      break;
-    }
-    options.page++;
-  }
-  return false;
-}
+    pull_number: pullRequestNumber
+  });
 
-async function commentISSUESURL(github, context, pullRequestNumber, issuesID) {
-  const issuesURL = 
`https://github.com/apache/incubator-gluten/issues/${issuesID}`;
-  if (await haveComment(github, context, pullRequestNumber, issuesURL)) {
+  const currentBody = pullRequest.body || "";
+
+  // Check if the issues URL or reference is already in the PR description.
+  if (currentBody.includes(issueURL) || currentBody.includes(issueReference)) {
     return;
   }
-  await github.rest.issues.createComment({
+
+  // Append the issues URL to the PR description.
+  const updatedBody = `${currentBody}\n\nRelated issue: ${issueReference}`;
+
+  // Update the PR description.
+  await github.rest.pulls.update({
     owner: context.repo.owner,
     repo: context.repo.repo,
-    issue_number: pullRequestNumber,
-    body: issuesURL
+    pull_number: pullRequestNumber,
+    body: updatedBody
   });
 }
 
-module.exports = async ({github, context}) => {
+module.exports = async ({ github, context }) => {
   const pullRequestNumber = context.payload.number;
   const title = context.payload.pull_request.title;
-  const issuesID = detectISSUESID(title);
+  const issuesID = detectIssueID(title);
   if (issuesID) {
-    await commentISSUESURL(github, context, pullRequestNumber, issuesID);
+    await appendToPRDescription(github, context, pullRequestNumber, issuesID);
   }
 };
diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml
deleted file mode 100644
index e18670d16e..0000000000
--- a/.github/workflows/labeler.yml
+++ /dev/null
@@ -1,29 +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: Label Pull Requests
-on: pull_request_target
-
-jobs:
-  label:
-    runs-on: ubuntu-latest
-    permissions:
-      contents: read
-      pull-requests: write
-    steps:
-    - uses: actions/labeler@v5
-      with:
-        repo-token: "${{ secrets.GITHUB_TOKEN }}"
-        sync-labels: true
diff --git a/.github/workflows/dev_cron.yml b/.github/workflows/pr_bot.yml
similarity index 69%
rename from .github/workflows/dev_cron.yml
rename to .github/workflows/pr_bot.yml
index 834ab8d579..7f3219fc11 100644
--- a/.github/workflows/dev_cron.yml
+++ b/.github/workflows/pr_bot.yml
@@ -13,10 +13,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-name: Dev PR
+name: PR Bot
 
 on:
-
   pull_request_target:
     types:
       - opened
@@ -24,20 +23,32 @@ on:
       - synchronize
 
 jobs:
+  label:
+    name: label-pull-requests
+    runs-on: ubuntu-latest
+    permissions:
+      contents: read
+      pull-requests: write
+    steps:
+      - uses: actions/labeler@v5
+        with:
+          repo-token: "${{ secrets.GITHUB_TOKEN }}"
+          sync-labels: true
+
   process:
-    name: Process
+    name: link-referenced-issues
     runs-on: ubuntu-latest
-    permissions: write-all
+    permissions:
+      pull-requests: write
     steps:
       - uses: actions/checkout@v4
-      - name: Comment Issues link
+      - name: Link referenced issues
         if: |
-          github.event_name == 'pull_request_target' &&
-            (github.event.action == 'opened' ||
-             github.event.action == 'edited')
+          github.event.action == 'opened' ||
+          github.event.action == 'edited'
         uses: actions/github-script@v7
         with:
           github-token: ${{ secrets.GITHUB_TOKEN }}
           script: |
-            const script = 
require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_cron/issues_link.js`);
+            const script = 
require(`${process.env.GITHUB_WORKSPACE}/.github/workflows/dev_cron/pr_issue_linker.js`);
             script({github, context});


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

Reply via email to