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
5 changes: 3 additions & 2 deletions apps/github.js
Original file line number Diff line number Diff line change
@@ -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)
}

Expand Down Expand Up @@ -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}',
Expand All @@ -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;
Expand Down
40 changes: 23 additions & 17 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

Expand Down Expand Up @@ -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}',
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
35 changes: 20 additions & 15 deletions handlers/pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down