in functions/src/plugins/merge.ts [344:386]
async onPush(context: Context): Promise<void> {
const config = await this.getConfig(context);
if(!config.checks.noConflict) {
return;
}
const {owner, repo} = context.repo();
const repoId = context.payload.repository.id;
let ref = context.payload.ref.split('/');
ref = ref[ref.length - 1];
const pullRequests = await this.pullRequests.where('state', '==', 'open')
.where('base.ref', '==', ref)
.where('repository.id', '==', repoId)
.get();
return await pullRequests.forEach(async doc => {
let pr = doc.data();
// We need to get the updated mergeable status
// TODO(ocombe): we might need to setTimeout this until we get a mergeable value !== null (or use probot scheduler)
pr = await this.updateDbPR(context.github, owner, repo, pr.number, repoId);
if(pr.mergeable === false) {
// Get the comments since the last time the PR was synchronized
if((pr.conflict_comment_at && pr.synchronized_at && pr.conflict_comment_at >= pr.synchronized_at) || (!pr.synchronized_at && pr.conflict_comment_at)) {
this.logDebug({context}, `This PR already contains a merge conflict comment since the last synchronized date, skipping it`);
return;
}
if(config.mergeConflictComment) {
await context.github.issues.createComment({
owner,
repo,
number: pr.number,
body: config.mergeConflictComment.replace("{{PRAuthor}}", pr.user.login)
});
this.pullRequests.doc(pr.id.toString()).set({conflict_comment_at: new Date()}, {merge: true}).catch(err => {
throw err;
});
this.log({context}, `Added comment: conflict with the base branch "${pr.base.ref}"`);
}
}
});
}