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-pipelines.git


The following commit(s) were added to refs/heads/main by this push:
     new cfc00ab3 kie-issues#771: fix pullrequest.getAuthorAndRepoForPr() 
method (#1148)
cfc00ab3 is described below

commit cfc00ab3f1f29c10680e71ca6b70e929d9791c64
Author: Jan Stastny <[email protected]>
AuthorDate: Fri Dec 15 14:29:08 2023 +0100

    kie-issues#771: fix pullrequest.getAuthorAndRepoForPr() method (#1148)
    
    Co-authored-by: jstastny-cz <[email protected]>
---
 .../test/vars/PullRequestSpec.groovy                         | 12 ++++++++++++
 jenkins-pipeline-shared-libraries/vars/pullrequest.groovy    | 11 +++++++++--
 2 files changed, 21 insertions(+), 2 deletions(-)

diff --git a/jenkins-pipeline-shared-libraries/test/vars/PullRequestSpec.groovy 
b/jenkins-pipeline-shared-libraries/test/vars/PullRequestSpec.groovy
index 2545e8e5..fa069d37 100644
--- a/jenkins-pipeline-shared-libraries/test/vars/PullRequestSpec.groovy
+++ b/jenkins-pipeline-shared-libraries/test/vars/PullRequestSpec.groovy
@@ -32,4 +32,16 @@ class PullRequestSpec extends JenkinsPipelineSpecification {
         then:
         result == 'owner/repo'
     }
+
+    def "PR from fork with matching name getAuthorAndRepoForPr" () {
+        setup:
+        def env = [:]
+        env['CHANGE_FORK']='contributor'
+        env['CHANGE_URL']='https://github.com/owner/repo/pull/1'
+        groovyScript.getBinding().setVariable('env', env)
+        when:
+        def result = groovyScript.getAuthorAndRepoForPr()
+        then:
+        result == 'contributor/repo'
+    }
 }
\ No newline at end of file
diff --git a/jenkins-pipeline-shared-libraries/vars/pullrequest.groovy 
b/jenkins-pipeline-shared-libraries/vars/pullrequest.groovy
index ef2b111c..c95c2f77 100644
--- a/jenkins-pipeline-shared-libraries/vars/pullrequest.groovy
+++ b/jenkins-pipeline-shared-libraries/vars/pullrequest.groovy
@@ -23,11 +23,18 @@ String getAuthorAndRepoForPr() {
     if (!env.CHANGE_FORK && !env.CHANGE_URL) {
         error "CHANGE_FORK neither CHANGE_URL variables are set. Are you sure 
you're running with Github Branch Source plugin?"
     }
+    def group = ''
+    def repository = ''
     if (env.CHANGE_FORK) {
-        return env.CHANGE_FORK
+        def parsedFork = env.CHANGE_FORK.split('/')
+        group = parsedFork[0]
+        if (parsedFork.length==2) {
+            repository = parsedFork[1]
+        }
     }
     String fullUrl = env.CHANGE_URL
     String urlWithoutProtocol = fullUrl.split('://')[1]
     String path = urlWithoutProtocol.substring(urlWithoutProtocol.indexOf('/'))
-    return path.substring(1, path.indexOf('/pull/'))
+    def parsedUrl = path.substring(1, path.indexOf('/pull/')).split('/')
+    return "${group?:parsedUrl[0]}/${repository?:parsedUrl[1]}"
 }
\ No newline at end of file


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

Reply via email to