in functions/src/plugins/merge.ts [51:95]
async onPRLabeled(context: Context): Promise<void> {
const newLabel = context.payload.label.name;
let pr: Github.PullRequestsGetResponse = context.payload.pull_request;
const config = await this.getConfig(context);
const {owner, repo} = context.repo();
pr = await this.updateDbPR(context.github, owner, repo, pr.number, context.payload.repository.id, pr).catch(err => {
throw err;
});
let updateStatus = false;
let statuses: GithubGQL.StatusContext[];
if(newLabel === config.mergeLabel) {
this.logDebug({context}, `Checking merge label`);
statuses = await this.getStatuses(context, pr.number, config);
const checks = await this.getChecksStatus(context, pr, config, pr.labels, statuses);
if(checks.failure.length > 0) {
const failures = checks.failure.map(check => `  ${check}`);
const pendings = checks.pending.map(check => `  ${check}`);
const reasons = `${failures.concat(pendings).join('\n')}`;
let body = config.mergeRemovedComment;
if(body) {
body = body.replace("{{MERGE_LABEL}}", config.mergeLabel).replace("{{PLACEHOLDER}}", reasons);
addComment(context.github, owner, repo, pr.number, body).catch(err => {
throw err;
});
}
}
} else if(config.mergeLinkedLabels && config.mergeLinkedLabels.includes(newLabel) && !getLabelsNames(pr.labels).includes(config.mergeLabel)) {
// Add the merge label when we add a linked label
addLabels(context.github, owner, repo, pr.number, [config.mergeLabel])
.catch(); // If it fails it's because we're trying to add a label that already exists
}
if(this.matchLabel(newLabel, pr.labels, config)) {
updateStatus = true;
}
this.updateStatus(context, config, updateStatus, pr.labels, statuses).catch(err => {
throw err;
});
}