Skip to content

Commit

Permalink
Add github labels API wrappers
Browse files Browse the repository at this point in the history
Change-Id: I8312f521b958323529fa0eb5b582085460e585aa
Signed-off-by: Sandu Postaru <sandu.postaru@thalesgroup.com>
  • Loading branch information
sandupostaru committed Aug 31, 2020
1 parent 1608f94 commit 4e11304
Showing 1 changed file with 83 additions and 1 deletion.
84 changes: 83 additions & 1 deletion vars/github.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
def isPullRequest() {
return "${BRANCH_NAME}".contains('PR-');
return "${BRANCH_NAME}".contains('PR-')
}

def getPullRequestId() {
Expand Down Expand Up @@ -54,3 +54,85 @@ def buildAbortedComment() {

pullRequestComment(message)
}

def private isDraftCommit() {
def commitMsg = sh (script: 'git log -1 --pretty=%B ${GIT_COMMIT}', returnStdout: true).trim()

return commitMsg.contains("DRAFT")
}

def private getExistingLabels() {
def pullRequestId = getPullRequestId()
def projectName = getProjectName()
def apiURL = "https://api.github.com/repos/eclipse/${projectName}/issues/${pullRequestId}/labels"
def labels = ""

withCredentials([string(credentialsId: '0dea5761-867c-44db-92fa-9304c81a8653', variable: 'password')]) {
def script = """curl ${apiURL} -u "eclipse-capella-bot:${password}" -H "Content-Type: application/json" """

labels = sh(script: "${script}", returnStdout: true)
}

return labels
}

def private getCustomLabels() {
return ['build-aborted', 'build-unstable', 'build-failed', 'build-successfull', 'build-started']
}

def private removeLabel(label) {
def pullRequestId = getPullRequestId()
def projectName = getProjectName()
def apiURL = "https://api.github.com/repos/eclipse/${projectName}/issues/${pullRequestId}/labels/${label}"

withCredentials([string(credentialsId: '0dea5761-867c-44db-92fa-9304c81a8653', variable: 'password')]) {
sh """curl ${apiURL} -X DELETE -u "eclipse-capella-bot:${password}" -H "Content-Type: application/json" """
}
}

def removeCustomPullRequestLabels() {
def pullRequestId = getPullRequestId()
def projectName = getProjectName()
def existingLabels = getExistingLabels()
def customLabels = getCustomLabels()

customLabels.each {
if(existingLabels.contains("${it}")) {
removeLabel("${it}")
}
}
}

def private addPullRequestLabel(label) {
def pullRequestId = getPullRequestId()
def projectName = getProjectName()
def apiURL = "https://api.github.com/repos/eclipse/${projectName}/issues/${pullRequestId}/labels"

withCredentials([string(credentialsId: '0dea5761-867c-44db-92fa-9304c81a8653', variable: 'password')]) {
sh """curl ${apiURL} --data '{"labels":["${label}"]}' -u "eclipse-capella-bot:${password}" --request POST -H "Content-Type: application/json" """
}
}

def buildStartedLabel() {
addPullRequestLabel('build-started')
}

def buildSuccessfullLabel() {
addPullRequestLabel('build-successfull')
}

def buildFailedLabel() {
addPullRequestLabel('build-failed')
}

def buildUnstableLabel() {
addPullRequestLabel('build-unstable')
}

def buildAbortedLabel() {
addPullRequestLabel('build-aborted')
}

def removeBuildStartedLabel() {
removeLabel('build-started')
}

0 comments on commit 4e11304

Please sign in to comment.