Skip to content

Commit 532792c

Browse files
committed
Refactor splitting of refs
1 parent 2cd608d commit 532792c

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/main/java/org/jenkinsci/plugins/gogs/GogsWebHook.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ associated documentation files (the "Software"), to deal in the Software without
4343
import java.net.URLDecoder;
4444
import java.nio.charset.Charset;
4545
import java.util.Arrays;
46-
import java.util.List;
4746
import java.util.Map;
47+
import java.util.StringJoiner;
4848
import java.util.concurrent.atomic.AtomicBoolean;
4949
import java.util.concurrent.atomic.AtomicReference;
5050
import java.util.logging.Logger;
@@ -177,15 +177,10 @@ public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException
177177
SecurityContext saveCtx = ACL.impersonate(ACL.SYSTEM);
178178

179179
try {
180-
String ref = (String) jsonObject.get("ref");
181-
String[] components = ref.split("/");
182-
if (components.length > 3) {
183-
/* refs contains branch/tag with a slash */
184-
List<String> test = Arrays.asList(ref.split("/"));
185-
ref = String.join("%2F", test.subList(2, test.size()));
186-
} else {
187-
ref = components[components.length - 1];
188-
}
180+
StringJoiner stringJoiner = new StringJoiner("%2F");
181+
Pattern.compile("/").splitAsStream((String) jsonObject.get("ref")).skip(2)
182+
.forEach(stringJoiner::add);
183+
String ref = stringJoiner.toString();
189184

190185
Arrays.asList(jobName, jobName + "/" + ref).forEach(j -> {
191186
Job job = GogsUtils.find(j, Job.class);
@@ -223,7 +218,7 @@ public void doIndex(StaplerRequest req, StaplerResponse rsp) throws IOException
223218
} else if (isNullOrEmpty(jSecret.get()) && isNullOrEmpty(gSecret)) {
224219
/* No password is set in Jenkins and Gogs, run without secrets */
225220
result = payloadProcessor.triggerJobs(jobName, gogsDelivery);
226-
} else if (!isNullOrEmpty(jSecret.get()) && jSecret.equals(gSecret)) {
221+
} else if (!isNullOrEmpty(jSecret.get()) && jSecret.get().equals(gSecret)) {
227222
/* Password is set in Jenkins and Gogs, and is correct */
228223
result = payloadProcessor.triggerJobs(jobName, gogsDelivery);
229224
} else {

0 commit comments

Comments
 (0)