From 76b7330e0c6e947a4c1a6dbf2fdb8d8bb99f48f1 Mon Sep 17 00:00:00 2001 From: amrit Date: Thu, 7 Aug 2025 14:19:31 +0530 Subject: [PATCH] fix: update cron schedule and improve conflict detection in PR closures (#1945) Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --- .github/workflows/close-conflicted-prs.yml | 33 +++++++++++++++++----- .github/workflows/close-stale-issues.yml | 2 +- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/.github/workflows/close-conflicted-prs.yml b/.github/workflows/close-conflicted-prs.yml index 4cb12112f..d6ed5de66 100644 --- a/.github/workflows/close-conflicted-prs.yml +++ b/.github/workflows/close-conflicted-prs.yml @@ -2,7 +2,7 @@ name: Close Old Conflicted PRs on: schedule: - - cron: "0 * * * *" + - cron: "0 0 * * *" jobs: close_conflicted_prs: @@ -10,7 +10,7 @@ jobs: permissions: pull-requests: write steps: - - name: Close PRs with merge conflicts older than 3 days + - name: Close PRs with conflicts older than 3 days uses: actions/github-script@v7 with: script: | @@ -28,15 +28,34 @@ jobs: pull_number: pr.number }); - if (details.data.mergeable === false || details.data.mergeable === null) { - const createdAt = new Date(pr.created_at); - const diffDays = (now - createdAt) / (1000 * 60 * 60 * 24); - if (diffDays > 3) { + if (details.data.mergeable === null) { + continue; + } + + if (details.data.mergeable === false) { + const timeline = await github.rest.issues.listEventsForTimeline({ owner: context.repo.owner, repo: context.repo.repo, issue_number: pr.number, per_page: 100 }); + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: pr.number + }); + + let conflictStartTime = new Date(pr.updated_at); + + for (const event of timeline.data) { + if (event.event === 'cross-referenced' && event.commit_id) { + conflictStartTime = new Date(event.created_at); + break; + } + } + + const conflictAgeDays = (now - conflictStartTime) / (1000 * 60 * 60 * 24); + + if (conflictAgeDays >= 3) { await github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: pr.number, - body: "This PR has merge conflicts and has been open for more than 3 days. It will be automatically closed. Please resolve the conflicts and reopen the PR if you'd like to continue working on it." + body: "This PR has had merge conflicts for more than 3 days. It will be automatically closed. Please resolve the conflicts and reopen the PR if you'd like to continue working on it." }); await github.rest.pulls.update({ diff --git a/.github/workflows/close-stale-issues.yml b/.github/workflows/close-stale-issues.yml index 1457e1c9d..dd2d3244e 100644 --- a/.github/workflows/close-stale-issues.yml +++ b/.github/workflows/close-stale-issues.yml @@ -2,7 +2,7 @@ name: Close Stale Issues on: schedule: - - cron: "0 * * * *" + - cron: "0 0 * * *" jobs: stale: