Created
July 18, 2023 14:11
-
-
Save mbiarnes/5fdac3ca0496f7b8a7bcf30b5f0d2bcc 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
void umbToGHPRB(String umbMessage, String repositoryName, String pullRequestId) { | |
if(umbMessage?.trim()) { | |
def ghrprbToGHAPIPRMap = [ | |
'ghprbSourceBranch' : 'head.ref', | |
'ghprbTargetBranch' : 'base.ref', | |
'ghprbPullId' : 'number', | |
'ghprbGhRepository' : 'repo.full_name', | |
'ghprbPullLink' : 'html_url', | |
'ghprbAuthorRepoGitUrl' : 'head.repo.clone_url', | |
'ghprbCommentBody' :'body', | |
'ghprbPullTitle': 'title', | |
'ghprbActualCommit':'head.sha', | |
'ghprbPullLongDescription' : 'labels.description' | |
] | |
def curlResult = sh(returnStdout: true, script: "curl -L https://api.github.com/repos/${repositoryName}/pulls/${pullRequestId}")?.trim() | |
if (curlResult) { | |
def prInfoObject = readJSON text: curlResult | |
ghrprbToGHAPIPRMap.each { entry -> | |
def newValue = prInfoObject["${entry.value}"] | |
env["${entry.key}"] = newValue | |
println "[INFO] ${entry.value}:${newValue} mapped to ${entry.key}" | |
} | |
} | |
} else { | |
println "[WARN] Nothing to map grom UMB message. The content is empty." | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment