From 6c829319d076361827476b19a253b19c58a19efc Mon Sep 17 00:00:00 2001 From: Jarun Madhesh Date: Thu, 8 Jan 2026 11:28:33 +0530 Subject: [PATCH 1/2] Increase timeout for fetching protected branch names and add error handling in PR raising process Signed-off-by: Jarun Madhesh --- apps/github.js | 3 ++- dist/index.js | 38 ++++++++++++++++++++++---------------- handlers/pr.js | 35 ++++++++++++++++++++--------------- 3 files changed, 44 insertions(+), 32 deletions(-) diff --git a/apps/github.js b/apps/github.js index 8306a92..1bbe3c6 100644 --- a/apps/github.js +++ b/apps/github.js @@ -1,5 +1,5 @@ async function fetchProtectedBranchNames(context) { - let branches = await context.octokit.repos.listBranches(context.repo({protected : true, per_page : 100})) + let branches = await context.octokit.repos.listBranches(context.repo({protected : true, per_page : 100, request: { timeout: 120_000 }})) return branches.data.map(branch => branch.name) } @@ -48,6 +48,7 @@ async function mergePr(context, pr, onMergeFailure) { let isMerged = false while (i++ < maxRetries) { try { + await resolveAllComments(context, prNumber); await context.octokit.pulls.merge(context.repo({pull_number : pr.number, commit_message : "\r\n\r\n skip-checks: true"})) isMerged = true break; diff --git a/dist/index.js b/dist/index.js index d4e3bb5..da0a275 100644 --- a/dist/index.js +++ b/dist/index.js @@ -28,7 +28,7 @@ module.exports = (app) => { /***/ ((module) => { async function fetchProtectedBranchNames(context) { - let branches = await context.octokit.repos.listBranches(context.repo({protected : true, per_page : 100})) + let branches = await context.octokit.repos.listBranches(context.repo({protected : true, per_page : 100, request: { timeout: 120_000 }})) return branches.data.map(branch => branch.name) } @@ -77,6 +77,7 @@ async function mergePr(context, pr, onMergeFailure) { let isMerged = false while (i++ < maxRetries) { try { + await resolveAllComments(context, prNumber); await context.octokit.pulls.merge(context.repo({pull_number : pr.number, commit_message : "\r\n\r\n skip-checks: true"})) isMerged = true break; @@ -324,21 +325,26 @@ async function onPrOpen(context) { } async function raisePrToAllStagingBranches(context, onMergeConflict) { - let stagingBranchNames = await fetchingStagingBranchNames(context) - console.log(`Raising PR to all staging branches - ${stagingBranchNames.join(", ")}`) - return stagingBranchNames.map(async (branchName) => { - let existingOpenPr = await github.fetchOpenPr(context, masterBranch, branchName); - if (existingOpenPr) { - await github.closePr(context, existingOpenPr.number) - } - let createdPr = await github.createPr(context, masterBranch, branchName, `Syncing with latest ${masterBranch}`) - let newPr = toPr({payload: {pull_request: createdPr.data}}) - let isMergeable = await github.isMergeable(context, newPr.number) - if (isMergeable === false) { - await onMergeConflict(context, newPr) - } - return createdPr - }) + try { + let stagingBranchNames = await fetchingStagingBranchNames(context) + console.log(`Raising PR to all staging branches - ${stagingBranchNames.join(", ")}`) + return stagingBranchNames.map(async (branchName) => { + let existingOpenPr = await github.fetchOpenPr(context, masterBranch, branchName); + if (existingOpenPr) { + await github.closePr(context, existingOpenPr.number) + } + let createdPr = await github.createPr(context, masterBranch, branchName, `Syncing with latest ${masterBranch}`) + let newPr = toPr({payload: {pull_request: createdPr.data}}) + let isMergeable = await github.isMergeable(context, newPr.number) + if (isMergeable === false) { + await onMergeConflict(context, newPr) + } + return createdPr + }) + } catch(err) { + console.log("ERROR!") + console.log(err) + } } async function raisePrToCorrespondingDevelopBranch(context, pr, onMergeConflict) { diff --git a/handlers/pr.js b/handlers/pr.js index d48516b..43b1fc4 100644 --- a/handlers/pr.js +++ b/handlers/pr.js @@ -132,21 +132,26 @@ async function onPrOpen(context) { } async function raisePrToAllStagingBranches(context, onMergeConflict) { - let stagingBranchNames = await fetchingStagingBranchNames(context) - console.log(`Raising PR to all staging branches - ${stagingBranchNames.join(", ")}`) - return stagingBranchNames.map(async (branchName) => { - let existingOpenPr = await github.fetchOpenPr(context, masterBranch, branchName); - if (existingOpenPr) { - await github.closePr(context, existingOpenPr.number) - } - let createdPr = await github.createPr(context, masterBranch, branchName, `Syncing with latest ${masterBranch}`) - let newPr = toPr({payload: {pull_request: createdPr.data}}) - let isMergeable = await github.isMergeable(context, newPr.number) - if (isMergeable === false) { - await onMergeConflict(context, newPr) - } - return createdPr - }) + try { + let stagingBranchNames = await fetchingStagingBranchNames(context) + console.log(`Raising PR to all staging branches - ${stagingBranchNames.join(", ")}`) + return stagingBranchNames.map(async (branchName) => { + let existingOpenPr = await github.fetchOpenPr(context, masterBranch, branchName); + if (existingOpenPr) { + await github.closePr(context, existingOpenPr.number) + } + let createdPr = await github.createPr(context, masterBranch, branchName, `Syncing with latest ${masterBranch}`) + let newPr = toPr({payload: {pull_request: createdPr.data}}) + let isMergeable = await github.isMergeable(context, newPr.number) + if (isMergeable === false) { + await onMergeConflict(context, newPr) + } + return createdPr + }) + } catch(err) { + console.log("ERROR!") + console.log(err) + } } async function raisePrToCorrespondingDevelopBranch(context, pr, onMergeConflict) { From 8a985ed59c150b7111ea8694c86a9d0c4fa81a22 Mon Sep 17 00:00:00 2001 From: Jarun Madhesh Date: Thu, 8 Jan 2026 11:34:12 +0530 Subject: [PATCH 2/2] Resolve comments by snyk-io[bot] Signed-off-by: Jarun Madhesh --- apps/github.js | 2 +- dist/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/github.js b/apps/github.js index 1bbe3c6..32e06d3 100644 --- a/apps/github.js +++ b/apps/github.js @@ -30,7 +30,7 @@ async function resolveAllComments(context, prNumber) { ) for (const comment of comments) { - if (comment.user.login !== 'cursor[bot]') continue; + if (comment.user.login !== 'cursor[bot]' || comment.user.login !== 'snyk-io[bot]') continue; console.log("deleting comment : " + comment.id); await context.octokit.request( 'DELETE /repos/{owner}/{repo}/pulls/comments/{comment_id}', diff --git a/dist/index.js b/dist/index.js index da0a275..f54dacc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -59,7 +59,7 @@ async function resolveAllComments(context, prNumber) { ) for (const comment of comments) { - if (comment.user.login !== 'cursor[bot]') continue; + if (comment.user.login !== 'cursor[bot]' || comment.user.login !== 'snyk-io[bot]') continue; console.log("deleting comment : " + comment.id); await context.octokit.request( 'DELETE /repos/{owner}/{repo}/pulls/comments/{comment_id}',