From c9c712e637bc79d87aea605ba31f9fcd0cef114c Mon Sep 17 00:00:00 2001 From: Yuxiang Zhu Date: Nov 08 2018 06:20:08 +0000 Subject: CI/CD: Marking PR status as Pending when new build starts Following https://pagure.io/waiverdb/issue/256. When a new build starts, clear the `percent` field in the PR flag so that Pagure UI will show a `Pending` label. --- diff --git a/openshift/pipelines/templates/waiverdb-polling-pagure.yaml b/openshift/pipelines/templates/waiverdb-polling-pagure.yaml index 7d3a6fc..2c005aa 100644 --- a/openshift/pipelines/templates/waiverdb-polling-pagure.yaml +++ b/openshift/pipelines/templates/waiverdb-polling-pagure.yaml @@ -239,6 +239,10 @@ objects: } def devBuildInfo = devBuild.object() env.DEV_BUILD_URL = devBuildInfo.metadata.annotations['openshift.io/jenkins-build-uri'] ?: env.BUILD_URL + if (env.PAGURE_POLLING_FOR_PR == 'true') { + // setting PR status to Pending + setBuildStatusOnPagurePR(null, 'Pending') + } echo "Waiting for dev build ${devBuildInfo.metadata.name}(${env.DEV_BUILD_URL}) to complete..." devBuild.watch { return it.object().status.phase != "Running" @@ -311,19 +315,22 @@ objects: } def payloadItems = [] if (payload) { - payloadItems = payload.collect { - URLEncoder.encode(it.key.toString(), 'utf-8') + - '=' + URLEncoder.encode(it.value.toString(), 'utf-8') + for (it in payload) { + if (it == null || it.value == null) { + continue + } + payloadItems << (URLEncoder.encode(it.key.toString(), 'utf-8') + + '=' + URLEncoder.encode(it.value.toString(), 'utf-8')) } } return steps.httpRequest( - httpMode: httpMode, - url: "${pagureApiUrl}/${apiPath}", - acceptType: 'APPLICATION_JSON', - contentType: 'APPLICATION_FORM', - requestBody: payloadItems.join('&'), - customHeaders: headers, - ) + httpMode: httpMode, + url: "${pagureApiUrl}/${apiPath}", + acceptType: 'APPLICATION_JSON', + contentType: 'APPLICATION_FORM', + requestBody: payloadItems.join('&'), + customHeaders: headers, + ) } def getPR(Map args) { def apiPath = "${args.fork?'fork/':''}${args.repo}/pull-request/${args.pr}" @@ -346,7 +353,7 @@ objects: def pagureClient = new PagureClient (pagureApiUrl: env.PAGURE_API, steps: steps) return pagureClient.getPR(fork: env.PAGURE_REPO_IS_FORK == 'true', repo: "${PAGURE_REPO_NAME}", pr: env.PR_NO) } - def setBuildStatusOnPagurePR(int percent, String comment) { + def setBuildStatusOnPagurePR(percent, String comment) { withCredentials([string(credentialsId: "${env.PIPELINE_NAMESPACE}-${PAGURE_API_KEY_SECRET_NAME}", variable: 'TOKEN')]) { def pagureClient = new PagureClient (pagureApiUrl: env.PAGURE_API, token: env.TOKEN, steps: steps) pagureClient.updatePRStatus(