Skip to content

Commit

Permalink
New field for status propagation of pipeline (#338)
Browse files Browse the repository at this point in the history
* renaming more clear

* renaming more clear

* mock get propagation Url

* reincorporate jelly stapler connection

* incorporated new propagation url field at trigger level

* add null check

* google style for java

* getting url type from config

* Revert "getting url type from config"

This reverts commit 8cc1367.

* check if url if malformed in form

* cloud config propagation url and tests adjusted

* abstract class and central propagation url overriden by the trigger class

* take out assert of abstract class

---------

Co-authored-by: [email protected] <[email protected]>
  • Loading branch information
julioc-p and [email protected] authored Sep 12, 2024
1 parent 45d815b commit 733e403
Show file tree
Hide file tree
Showing 24 changed files with 1,262 additions and 564 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,17 @@ public void triggerMatchingJobs(BitBucketPPRHookEvent bitbucketEvent,
String.format("Unsupported SCM type %s", bitbucketAction.getScm()));
}

Function<String, URIish> f = a -> {
Function<String, URIish> makeUrl = a -> {
try {
return new URIish(a);
} catch (URISyntaxException e) {
logger.warning(String.format("Invalid URI %s.", e.getMessage()));
return null;
}
};
List<URIish> remotes = bitbucketAction.getScmUrls().stream().map(f)


List<URIish> remoteScmUrls = bitbucketAction.getScmUrls().stream().map(makeUrl)
.filter(Objects::nonNull).collect(Collectors.toList());

try (ACLContext ctx = ACL.as(ACL.SYSTEM)) {
Expand All @@ -98,14 +100,14 @@ public void triggerMatchingJobs(BitBucketPPRHookEvent bitbucketEvent,
logger.log(Level.WARNING, "Job could not be found!");
return;
}
triggerScmForSingleJob(job, remotes, bitbucketEvent, bitbucketAction, observable);
triggerScmForSingleJob(job, remoteScmUrls, bitbucketEvent, bitbucketAction, observable);
} catch (TriggerNotSetException e) {
logger.log(Level.FINE, "Trigger not set");
}
} else {
Jenkins.get().getAllItems(Job.class).forEach(job -> {
try {
triggerScm(job, remotes, bitbucketEvent, bitbucketAction, observable);
triggerScm(job, remoteScmUrls, bitbucketEvent, bitbucketAction, observable);
} catch (TriggerNotSetException e) {
logger.log(Level.FINE, "Trigger not set");
}
Expand All @@ -118,16 +120,16 @@ private void triggerScmForSingleJob(@Nonnull Job<?, ?> job, List<URIish> remotes
BitBucketPPRHookEvent bitbucketEvent, BitBucketPPRAction bitbucketAction,
BitBucketPPRObservable observable) throws TriggerNotSetException {

Trigger trigger = new Trigger(getBitBucketTrigger(job)
Trigger jobTrigger = new Trigger(getBitBucketTrigger(job)
.orElseThrow(() -> new TriggerNotSetException(job.getFullDisplayName())), Optional.ofNullable(SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job)));

trigger.scmTriggerItem.ifPresent(it -> it.getSCMs().forEach(scmTrigger -> {
jobTrigger.scmTriggerItem.ifPresent(it -> it.getSCMs().forEach(scm -> {

if (!scmTriggered.contains(scmTrigger)) {
scmTriggered.add(scmTrigger);
if (!scmTriggered.contains(scm)) {
scmTriggered.add(scm);

try {
trigger.bitbucketTrigger.onPost(bitbucketEvent, bitbucketAction, scmTrigger, observable);
jobTrigger.bitbucketTrigger.onPost(bitbucketEvent, bitbucketAction, scm, observable);
return;

} catch (Exception e) {
Expand All @@ -145,10 +147,10 @@ private void triggerScm(@Nonnull Job<?, ?> job, List<URIish> remotes,
BitBucketPPRHookEvent bitbucketEvent, BitBucketPPRAction bitbucketAction,
BitBucketPPRObservable observable) throws TriggerNotSetException {

Trigger trigger = new Trigger(getBitBucketTrigger(job)
Trigger jobTrigger = new Trigger(getBitBucketTrigger(job)
.orElseThrow(() -> new TriggerNotSetException(job.getFullDisplayName())), Optional.ofNullable(SCMTriggerItem.SCMTriggerItems.asSCMTriggerItem(job)));

trigger.scmTriggerItem.ifPresent(it -> it.getSCMs().forEach(scmTrigger -> {
jobTrigger.scmTriggerItem.ifPresent(it -> it.getSCMs().forEach(scm -> {

// @todo add comments to explain what is this check for
if (job.getParent() instanceof MultiBranchProject
Expand All @@ -157,13 +159,13 @@ && mPJobShouldNotBeTriggered(job, bitbucketEvent, bitbucketAction)) {
return;
}

Predicate<URIish> p = (url) -> scmTrigger instanceof GitSCM && matchGitScm(scmTrigger, url);
Predicate<URIish> checkSCM = (url) -> scm instanceof GitSCM && matchGitScm(scm, url);

if (remotes.stream().anyMatch(p) && !scmTriggered.contains(scmTrigger)) {
scmTriggered.add(scmTrigger);
if (remotes.stream().anyMatch(checkSCM) && !scmTriggered.contains(scm)) {
scmTriggered.add(scm);

try {
trigger.bitbucketTrigger.onPost(bitbucketEvent, bitbucketAction, scmTrigger, observable);
jobTrigger.bitbucketTrigger.onPost(bitbucketEvent, bitbucketAction, scm, observable);
return;

} catch (Exception e) {
Expand Down Expand Up @@ -241,7 +243,7 @@ private Optional<BitBucketPPRTrigger> getBitBucketTrigger(Job<?, ?> job) {

private boolean matchGitScm(SCM scm, URIish remote) {
return ((GitSCM) scm).getRepositories().stream()
.anyMatch((a) -> a.getURIs().stream().anyMatch((b) -> GitStatus.looselyMatches(b, remote)));
.anyMatch((repo) -> repo.getURIs().stream().anyMatch((repoUrl) -> GitStatus.looselyMatches(repoUrl, remote)));

Check warning on line 246 in src/main/java/io/jenkins/plugins/bitbucketpushandpullrequest/BitBucketPPRJobProbe.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 103-246 are not covered by tests
}

}
Loading

0 comments on commit 733e403

Please sign in to comment.