@@ -81,6 +81,10 @@ pipeline {
8181 stage('Checkout SCM') {
8282 steps {
8383 checkout scm
84+ script { // Always load the script from the very same state this pipeline is loaded (to ensure consistency)
85+ githubAPI = load "JenkinsJobs/shared/githubAPI.groovy"
86+ githubAPI.setDryRun(params.DRY_RUN)
87+ }
8488 sh '''
8589 git submodule update --init --recursive
8690 git config --global user.email '
[email protected] '
@@ -240,7 +244,7 @@ pipeline {
240244 script {
241245 def prHeadline = "Prepare ${NEXT_RELEASE_VERSION} development"
242246 def prBranch = "prepare_R${NEXT_RELEASE_VERSION}"
243- def aggregatorPreparationPR = createPullRequest('eclipse-platform/eclipse.platform.releng.aggregator', prHeadline, """\
247+ def aggregatorPreparationPR = githubAPI. createPullRequest('eclipse-platform/eclipse.platform.releng.aggregator', prHeadline, """\
244248 Prepare development of Eclipse ${NEXT_RELEASE_VERSION}.
245249 This includes:
246250 - Updating the version of the Maven parent, all references to it and the Eclipse products to `${NEXT_RELEASE_VERSION}`
@@ -263,7 +267,7 @@ pipeline {
263267 error "Unexpected of submodule URL: ${submoduleURL}"
264268 }
265269 def repoName = submoduleURL.substring(expectedPrefix.length(), submoduleURL.length() - expectedSuffix.length())
266- createPullRequest(repoName, prHeadline, """\
270+ githubAPI. createPullRequest(repoName, prHeadline, """\
267271 Prepare development of Eclipse ${NEXT_RELEASE_VERSION}.
268272 This complements:
269273 - ${aggregatorPreparationPR}
@@ -280,7 +284,7 @@ pipeline {
280284 script {
281285 def organisations = [ 'eclipse-platform', 'eclipse-jdt', 'eclipse-pde', 'eclipse-equinox' ]
282286 for (organisation in organisations) {
283- def repositories = listReposOfOrganization(organisation)
287+ def repositories = githubAPI. listReposOfOrganization(organisation)
284288 echo "${organisation} repositories: ${repositories.name}"
285289 for (repositoryData in repositories) {
286290 def repository = repositoryData.name
@@ -291,12 +295,12 @@ pipeline {
291295 echo "Skipping .eclipsefdn repository of : ${organisation}"
292296 continue
293297 }
294- createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION} M1", "${NEXT_RELEASE_VERSION} Milestone 1", "${M1_DATE}")
295- createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION} M2", "${NEXT_RELEASE_VERSION} Milestone 2", "${M2_DATE}")
296- createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION} M3", "${NEXT_RELEASE_VERSION} Milestone 3", "${M3_DATE}")
297- createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION} RC1", "${NEXT_RELEASE_VERSION} Release Candidate 1", "${RC1_DATE}")
298- createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION} RC2", "${NEXT_RELEASE_VERSION} Release Candidate 2", "${RC2_DATE}")
299- createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION}", "${NEXT_RELEASE_VERSION} Release", "${GA_DATE}")
298+ githubAPI. createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION} M1", "${NEXT_RELEASE_VERSION} Milestone 1", "${M1_DATE}")
299+ githubAPI. createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION} M2", "${NEXT_RELEASE_VERSION} Milestone 2", "${M2_DATE}")
300+ githubAPI. createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION} M3", "${NEXT_RELEASE_VERSION} Milestone 3", "${M3_DATE}")
301+ githubAPI. createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION} RC1", "${NEXT_RELEASE_VERSION} Release Candidate 1", "${RC1_DATE}")
302+ githubAPI. createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION} RC2", "${NEXT_RELEASE_VERSION} Release Candidate 2", "${RC2_DATE}")
303+ githubAPI. createMilestone(organisation, repository, "${NEXT_RELEASE_VERSION}", "${NEXT_RELEASE_VERSION} Release", "${GA_DATE}")
300304 }
301305 }
302306 }
@@ -305,6 +309,9 @@ pipeline {
305309 }
306310}
307311
312+ @groovy.transform.Field
313+ def githubAPI = null
314+
308315// --- utility methods
309316
310317@NonCPS
@@ -334,68 +341,3 @@ def commitAllChangesExcludingSubmodules(String commitMessage) {
334341 '''
335342 }
336343}
337-
338- // Github API interactions
339-
340- def listReposOfOrganization(String orga) {
341- def response = queryGithubAPI('', "orgs/${orga}/repos", null)
342- if (!(response instanceof List) && (response.errors || (response.status && response.status != 201))) {
343- error "Response contains errors:\n${response}"
344- }
345- return response
346- }
347-
348- /**
349- * Create a new milestone.
350- * @param msDueDay the milestone's due-date, format: YYYY-MM-DD
351- */
352- def createMilestone(String orga, String repo, String msTitle, String msDescription, String msDueDay) {
353- echo "In ${orga}/${repo} create milestone: ${msTitle} due on ${msDueDay}"
354- def params = [title: msTitle, description: msDescription, due_on: "${msDueDay}T23:59:59Z"]
355- def response = queryGithubAPI('-X POST', "repos/${orga}/${repo}/milestones", params)
356- if (response?.errors || (response?.status && response.status != 201)) {
357- if (response.errors && response.errors[0]?.code == 'already_exists') {
358- echo 'Milestone already exists and is not modified'
359- // TODO: update milestone in this case: https://docs.github.com/en/rest/issues/milestones?apiVersion=2022-11-28#update-a-milestone
360- // Usefull if e.g. the dates are wrongly read from the calendar
361- } else {
362- error "Response contains errors:\n${response}"
363- }
364- }
365- }
366-
367- /**
368- * Create a PR in the specified repo, from a branch that is expected to reside in the same repository.
369- */
370- def createPullRequest(String orgaSlashRepo, String prTitle, String prBody, String headBranch, String baseBranch = 'master') {
371- echo "In ${orgaSlashRepo} create PR: '${prTitle}' on branch ${headBranch}"
372- def params = [title: prTitle, body: prBody, head: headBranch, base: baseBranch]
373- def response = queryGithubAPI('-X POST',"repos/${orgaSlashRepo}/pulls", params)
374- if (response?.errors || (response?.status && response.status != 201)) {
375- error "Response contains errors:\n${response}"
376- }
377- return response?.html_url
378- }
379-
380- def queryGithubAPI(String method, String endpoint, Map<String, String> queryParameters) {
381- def query = """\
382- curl -L ${method} \
383- -H "Accept: application/vnd.github+json" \
384- -H "Authorization: Bearer \${GITHUB_BOT_TOKEN}" \
385- -H "X-GitHub-Api-Version: 2022-11-28" \
386- https://api.github.com/${endpoint} \
387- """.stripIndent()
388- if (queryParameters != null) {
389- def params = writeJSON(json: queryParameters, returnText: true)
390- query += "-d '" + params + "'"
391- }
392- if (params.DRY_RUN && !method.isEmpty()) {
393- echo "Query (not send): ${query}"
394- return null
395- }
396- def response = sh(script: query, returnStdout: true)
397- if (response == null || response.isEmpty()) {
398- error 'Response is null or empty. This commonly indicates: HTTP/1.1 500 Internal Server Error'
399- }
400- return readJSON(text: response)
401- }
0 commit comments