Skip to content

Commit

Permalink
kie-issues#776: automate PR merge into protected branches
Browse files Browse the repository at this point in the history
  • Loading branch information
jstastny-cz committed May 10, 2024
1 parent 59b5ddb commit c199049
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions .ci/jenkins/Jenkinsfile.kie-kogito-post-release
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pipeline {
script{
sh 'printenv'
dir(docsRepo){
checkoutRepo(docsRepo, GIT_AUTHOR, getDocsRepoBranch(), GIT_AUTHOR_CREDENTIALS_ID)
checkoutRepo(docsRepo, GIT_AUTHOR, getDocsRepoBranch(), getGitAuthorCredsId())
}
}
}
Expand Down Expand Up @@ -83,6 +83,7 @@ pipeline {
dir("${docsRepo}/doc-content/kogito-docs") {
maven.mvnVersionsSet(parseVersion(getKogitoDocsVersion()))
if (githubscm.isThereAnyChanges()){
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges(commitMsg)
}
}
Expand Down Expand Up @@ -116,7 +117,7 @@ pipeline {
steps {
script {
dir("${docsRepo}/doc-content/kogito-docs") {
githubscm.pushRemoteTag('origin', "${getKogitoDocsVersion()}-kogito")
githubscm.pushRemoteTag('origin', "${getKogitoDocsVersion()}-kogito", getGitAuthorPushCredsId())
}
}
}
Expand Down Expand Up @@ -152,9 +153,7 @@ pipeline {
script{
// Add changed files, commit, open and merge PR
String prLink = commitAndCreatePR(commitMsg, PR_BRANCH, getDocsRepoBranch())
sh "git checkout ${getDocsRepoBranch()}"
mergeAndPush(prLink, getDocsRepoBranch())
githubscm.removeRemoteBranch('origin', PR_BRANCH, getGitAuthorCredsId())
approveAndMergePR(prLink)
}
}
}
Expand All @@ -170,8 +169,8 @@ pipeline {
}
}

void checkoutRepo(String repo, String GIT_AUTHOR, String branch, String GIT_AUTHOR_CREDENTIALS_ID) {
checkout(githubscm.resolveRepository(repo, GIT_AUTHOR, branch, false, GIT_AUTHOR_CREDENTIALS_ID))
void checkoutRepo(String repo, String gitAuthor, String branch, String credsId) {
checkout(githubscm.resolveRepository(repo, gitAuthor, branch, false, credsId))
// need to manually checkout branch since on a detached branch after checkout command
sh "git checkout ${branch}"
}
Expand Down Expand Up @@ -219,7 +218,11 @@ boolean isNewVersionRequired() {
}

String getGitAuthorCredsId() {
return env.GIT_AUTHOR_CREDENTIALS_ID
return env.GIT_AUTHOR_CREDS_ID
}

String getGitAuthorPushCredsId() {
return env.GIT_AUTHOR_PUSH_CREDS_ID
}

void sendErrorNotification() {
Expand All @@ -236,16 +239,17 @@ String parseCommunityVersion(String docVersion) {
return "${versionSplit[0]}.${versionSplit[1]}"
}

void mergeAndPush(String prLink, String targetBranch) {
void approveAndMergePR(String prLink) {
if (prLink?.trim()) {
githubscm.mergePR(prLink, getGitAuthorCredsId())
githubscm.pushObject('origin', targetBranch, getGitAuthorCredsId())
githubscm.approvePR(prLink, getGitAuthorPushCredsId())
githubscm.mergePR(prLink, getGitAuthorPushCredsId())
}
}

String commitAndCreatePR(String commitMsg, String localBranch, String targetBranch) {
def prBody = "Generated by build ${BUILD_TAG}: ${BUILD_URL}"
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
githubscm.commitChanges(commitMsg)
githubscm.pushObject('origin', localBranch, getGitAuthorCredsId())
githubscm.pushObject('origin', localBranch, getGitAuthorPushCredsId())
return githubscm.createPR(commitMsg, prBody, targetBranch, getGitAuthorCredsId())
}
}

0 comments on commit c199049

Please sign in to comment.