From 84f4d813d192179558b5e74b7c01ef66b1e6aaa1 Mon Sep 17 00:00:00 2001 From: Alexander Verhaar Date: Tue, 3 Apr 2018 21:30:02 +0200 Subject: [PATCH] Fix for branches with a slash in the name --- README.md | 3 +++ pom.xml | 5 +++-- .../java/org/jenkinsci/plugins/gogs/GogsWebHook.java | 10 +++++++++- 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 850a292..0b7c178 100644 --- a/README.md +++ b/README.md @@ -16,6 +16,9 @@ Example how your the webhook in Gogs should look like: This project has some integration tests available. For more details see the [dedicated readme](about_integration_tests.md). ### Change Log +#### Version 1.0.14 (Apr 4, 2018) +- Fixes `job not found` if slashes are used in branch [[GH_ISSUE#36](https://github.com/jenkinsci/gogs-webhook-plugin/issues/36)/[PR#40](https://github.com/jenkinsci/gogs-webhook-plugin/pull/40)]. + #### Version 1.0.13 (Mar 16, 2018) - Fixes `job not found` if folders are used [[GH_ISSUE#36](https://github.com/jenkinsci/gogs-webhook-plugin/issues/36)/[PR#37](https://github.com/jenkinsci/gogs-webhook-plugin/pull/37)]. diff --git a/pom.xml b/pom.xml index 3135348..df5d69a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,4 +1,5 @@ - + 4.0.0 @@ -13,7 +14,7 @@ 1.625.3 - 7 + 8 2.13 8 diff --git a/src/main/java/org/jenkinsci/plugins/gogs/GogsWebHook.java b/src/main/java/org/jenkinsci/plugins/gogs/GogsWebHook.java index f4d06a0..6137ec2 100644 --- a/src/main/java/org/jenkinsci/plugins/gogs/GogsWebHook.java +++ b/src/main/java/org/jenkinsci/plugins/gogs/GogsWebHook.java @@ -42,7 +42,9 @@ associated documentation files (the "Software"), to deal in the Software without import java.io.UnsupportedEncodingException; import java.net.URLDecoder; import java.nio.charset.Charset; +import java.util.Arrays; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.logging.Logger; @@ -185,7 +187,13 @@ public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException } else { String ref = (String) jsonObject.get("ref"); String[] components = ref.split("/"); - ref = components[components.length - 1]; + if (components.length > 3) { + /* refs contains branch/tag with a slash */ + List test = Arrays.asList(ref.split("/")); + ref = String.join("%2F", test.subList(2, test.size())); + } else { + ref = components[components.length - 1]; + } job = GogsUtils.find(jobName + "/" + ref, Job.class);