Last active
November 17, 2020 01:39
-
-
Save TRahulSam1997/4cc8520d5d68de7801054c1e42bd6f41 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
app.post("/hook", (req, res) => { | |
let payload = req.body; | |
let header = req.headers; | |
res.status(200).end() | |
let pullRequestBranch = getPullRequestBranch(payload); | |
let baseBranch = getBaseBranch(payload); | |
let commitURL = getCommitURL(payload); | |
let action = getAction(payload); | |
let XGithubDelivery = getXGithubDelivery(header); | |
let XGithubEvent = getXGithubEvent(header); | |
let jenkinsTargetUrl = process.env.JENKINS_BASE_URL; | |
let token = process.env.JENKINS_TOKEN; | |
let basicAuth = process.env.JENKINS_BASIC_AUTH; | |
let state = process.env.GITHUB_STATE; | |
let message = process.env.MESSAGE; | |
let accessToken = process.env.GITHUB_TOKEN; | |
if ((action == "opened" && XGithubEvent == "pull_request") && (baseBranch == process.env.SUBJECT_BRANCH) && (pullRequestBranch || baseBranch || commitURL != undefined)) { | |
updateCommitStatus(commitURL, state, jenkinsTargetUrl, message, accessToken); | |
postToJenkins(payload, jenkinsTargetUrl, token, basicAuth, XGithubDelivery, baseBranch, process.env.SUBJECT_BRANCH); | |
} else { | |
console.log(`Request not made: \n\n Action: ${action} \n XGithubEvent: ${XGithubEvent} \n pullRequestBranch: ${pullRequestBranch} \n commitURL: ${commitURL} \n Subject Branch: ${process.env.SUBJECT_BRANCH} \n Base Branch: ${baseBranch}`); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment