Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,54 @@
* limitations under the License.
*/

function detectISSUESID(title) {
function detectIssueID(title) {
if (!title) {
return null;
}
const matched = /^\[GLUTEN-\d+\]/.exec(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);
}
};
29 changes: 0 additions & 29 deletions .github/workflows/labeler.yml

This file was deleted.

29 changes: 20 additions & 9 deletions .github/workflows/dev_cron.yml → .github/workflows/pr_bot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,42 @@
# 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
- edited
- 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});