Skip to content

Instantly share code, notes, and snippets.

@mbiarnes
Created July 18, 2023 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbiarnes/5fdac3ca0496f7b8a7bcf30b5f0d2bcc to your computer and use it in GitHub Desktop.
Save mbiarnes/5fdac3ca0496f7b8a7bcf30b5f0d2bcc to your computer and use it in GitHub Desktop.
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