This is an automated email from the ASF dual-hosted git repository.

jstastnycz pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-kie-kogito-docs.git


The following commit(s) were added to refs/heads/main by this push:
     new 367ed7ac3 kie-issues#776: automate PR merge into protected branches 
(#626)
367ed7ac3 is described below

commit 367ed7ac3a6d9549d3acbdd6772fe34d525a0454
Author: Jan Stastny <[email protected]>
AuthorDate: Mon May 13 10:49:36 2024 +0200

    kie-issues#776: automate PR merge into protected branches (#626)
    
    Co-authored-by: jstastny-cz <[email protected]>
---
 .ci/jenkins/Jenkinsfile.post-release |  2 +-
 .ci/jenkins/Jenkinsfile.setup-branch | 29 ++++++++++++++++++++++++++---
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/.ci/jenkins/Jenkinsfile.post-release 
b/.ci/jenkins/Jenkinsfile.post-release
index f0217268d..ae16bdf77 100644
--- a/.ci/jenkins/Jenkinsfile.post-release
+++ b/.ci/jenkins/Jenkinsfile.post-release
@@ -78,7 +78,7 @@ pipeline {
                         }
 
                         // Tag repository
-                        githubscm.tagLocalAndRemoteRepository('origin', 
getKogitoVersion(), getGitAuthorCredsId(), env.BUILD_TAG, true)
+                        githubscm.tagLocalAndRemoteRepository('origin', 
getKogitoVersion(), getGitAuthorPushCredsId(), env.BUILD_TAG, true)
                     }
                 }
             }
diff --git a/.ci/jenkins/Jenkinsfile.setup-branch 
b/.ci/jenkins/Jenkinsfile.setup-branch
index 4560937ce..87c317be5 100644
--- a/.ci/jenkins/Jenkinsfile.setup-branch
+++ b/.ci/jenkins/Jenkinsfile.setup-branch
@@ -32,7 +32,8 @@ pipeline {
     }
 
     environment {
-        CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}")
+        CI_EMAIL_TO = credentials("${JENKINS_EMAIL_CREDS_ID}")\
+        PR_BRANCH_HASH = "${util.generateHash(10)}"
     }
 
     stages {
@@ -107,16 +108,19 @@ pipeline {
                             if (!antoraConfig.content.sources[0].branches.find 
{ it == getBuildBranch() }) {
                                 
antoraConfig.content.sources[0].branches.add(getBuildBranch())
                         }
-                    }
 
                         // Add changed files, commit, open and merge PR
                         if (githubscm.isThereAnyChanges()) {
+                            String branchName = getPRBranchName()
+                            githubScm.createBranch(branchName)
                             
githubscm.setUserConfigFromCreds(getGitAuthorPushCredsId())
                             githubscm.commitChanges("Add branch 
${getBuildBranch()} for generation")
-                            githubscm.pushObject('origin', 'main', 
getGitAuthorPushCredsId())
+                            String prLink = commitAndCreatePR("Add branch 
${getBuildBranch()} for generation", branchName,"main")
+                            approveAndMergePR(prLink)
                         } else {
                             echo 'No changes to push.'
                         }
+                    }
                 }
             }
         }
@@ -171,3 +175,22 @@ void updateYaml(String filePath, Closure updateClosure) {
 boolean isMainBranch() {
     return env.IS_MAIN_BRANCH ? env.IS_MAIN_BRANCH.toBoolean() : false
 }
+
+void approveAndMergePR(String prLink) {
+    if (prLink?.trim()) {
+        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, getGitAuthorPushCredsId())
+    return githubscm.createPR(commitMsg, prBody, targetBranch, 
getGitAuthorCredsId())
+}
+
+String getPRBranchName() {
+    return "${getKogitoVersion().toLowerCase()}-${env.PR_BRANCH_HASH}"
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to