constmessage=err?("Was not built:\r\n\r\n```\r\n"+err.substring(0,64000).replace(/```/g,"` ` `")+"\r\n```\r\n\r\nDO NOT MERGE!"):("Build OK\r\n\r\n"+successMessage);
conststatusUrlMessage="Build status URL: "+settings.siteRoot+"status/"+options.headRepoOptions.owner+"/"+options.headRepoOptions.reponame+"/"+options.headRepoOptions.rev+"\r\n\r\n";
constmessage=err?("Was not built:\r\n\r\n```\r\n"+err.substring(0,64000).replace(/```/g,"` ` `")+"\r\n```\r\n\r\nDO NOT MERGE!"):("Build OK\r\n\r\n"+successMessage);
conststatusUrlMessage="Build status URL: "+settings.siteRoot+"status/"+options.headRepoOptions.owner+"/"+options.headRepoOptions.reponame+"/"+options.headRepoOptions.rev+"\r\n\r\n";
console.log("Got push event for "+options.owner+"/"+options.reponame+":"+options.branch);
builder.build(options,(err,result)=>{
console.log("Done processing request from GitHub");
console.log("Error: "+err);
//console.log("Result:");
//console.log(result);
res.send("Done processing request from GitHub\r\n"+"Error: "+err+"\r\n"+"Result: "+result);
});
constrepository=payload.repository;
constoptions={
app:req.app,
url:repository.url,
owner:repository.owner.name,
reponame:repository.name,
rev:payload.after,
branch:payload.ref
};
console.log("Got push event for "+options.owner+"/"+options.reponame+":"+options.branch);
builder.build(options,(err,result)=>{
console.log("Done processing request from GitHub");
console.log("Error: "+err);
//console.log("Result:");
//console.log(result);
res.send("Done processing request from GitHub\r\n"+"Error: "+err+"\r\n"+"Result: "+result);
});
};
constprocessPullRequest=(req,res,payload)=>{
constaction=payload.action;
constnumber=payload.number;
constpullRequest=payload.pull_request;
consthead=pullRequest.head;
constheadRepo=head.repo;
constheadRepoOptions={
url:headRepo.url,
owner:headRepo.owner.name||headRepo.owner.login,
reponame:headRepo.name,
rev:head.sha,
branchname:head.ref,
branch:"refs/heads/"+head.ref
};
constbase=pullRequest.base;
constbaseRepo=base.repo;
constbaseRepoOptions={
owner:baseRepo.owner.name||baseRepo.owner.login,
reponame:baseRepo.name,
branchname:base.ref
};
constoptions={
app:req.app,
action:action,
number:number,
headRepoOptions:headRepoOptions,
baseRepoOptions:baseRepoOptions
};
constmasterOptions={
app:req.app,
action:action,
number:number,
headRepoOptions:baseRepoOptions,
baseRepoOptions:baseRepoOptions
};
console.log("Got pull request "+action+" event, from "+headRepoOptions.owner+"/"+headRepoOptions.reponame+":"+headRepoOptions.branchname+" ("+headRepoOptions.rev+") to "+baseRepoOptions.owner+"/"+baseRepoOptions.reponame+":"+baseRepoOptions.branchname);
returnres.send("Only opened/reopened/synchronize/closed actions are supported");
}
if(action==="closed"&&!pullRequest.merged){
console.log("Pull request closed without merging");
returnres.send("Pull request closed without merging");
}
if(action==="closed"){
returnres.send("");
}
commenter.commentOnPullRequest(
action==="closed"?masterOptions:options,
(err,data)=>{
if(err){
console.log("Unable to post comment: "+err);
}
res.send(err||data);
}
);
constaction=payload.action;
constnumber=payload.number;
constpullRequest=payload.pull_request;
consthead=pullRequest.head;
constheadRepo=head.repo;
constheadRepoOptions={
url:headRepo.url,
owner:headRepo.owner.name||headRepo.owner.login,
reponame:headRepo.name,
rev:head.sha,
branchname:head.ref,
branch:"refs/heads/"+head.ref
};
constbase=pullRequest.base;
constbaseRepo=base.repo;
constbaseRepoOptions={
owner:baseRepo.owner.name||baseRepo.owner.login,
reponame:baseRepo.name,
branchname:base.ref
};
constoptions={
app:req.app,
action:action,
number:number,
headRepoOptions:headRepoOptions,
baseRepoOptions:baseRepoOptions
};
constmasterOptions={
app:req.app,
action:action,
number:number,
headRepoOptions:baseRepoOptions,
baseRepoOptions:baseRepoOptions
};
console.log("Got pull request "+action+" event, from "+headRepoOptions.owner+"/"+headRepoOptions.reponame+":"+headRepoOptions.branchname+" ("+headRepoOptions.rev+") to "+baseRepoOptions.owner+"/"+baseRepoOptions.reponame+":"+baseRepoOptions.branchname);