Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
import com.cloudbees.jenkins.plugins.bitbucket.api.webhook.BitbucketWebhookConfiguration;
import com.cloudbees.jenkins.plugins.bitbucket.api.webhook.BitbucketWebhookManager;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.URLUtils;
import com.cloudbees.jenkins.plugins.bitbucket.trait.DiscardOldBranchTrait;
import com.cloudbees.jenkins.plugins.bitbucket.trait.DiscardOldTagTrait;
import com.cloudbees.jenkins.plugins.bitbucket.util.BitbucketCredentialsUtils;
import com.cloudbees.plugins.credentials.common.StandardCredentials;
import edu.umd.cs.findbugs.annotations.CheckForNull;
Expand Down Expand Up @@ -214,6 +216,12 @@
if (endpoint == null) {
continue;
}
if (keepWebhook(source)) {

Check warning on line 219 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/WebhookAutoRegisterListener.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 219 is only partially covered, one branch is missing
logger.log(Level.INFO, "Not removing hook for {0}/{1} because of DiscardOldBranch trait, new commit will recrete project without the need trigger a repository scan",
new Object[] { source.getRepoOwner(), source.getRepository() });
continue;

Check warning on line 222 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/WebhookAutoRegisterListener.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 220-222 are not covered by tests
}

BitbucketApi client = getClientBySource(source, endpoint);
if (client != null) {
try (BitbucketAuthenticatedClient webhookClient = client.adapt(BitbucketAuthenticatedClient.class)) {
Expand Down Expand Up @@ -242,6 +250,11 @@
}
}

private boolean keepWebhook(BitbucketSCMSource source) {
return source.getTraits().stream()
.anyMatch(trait -> trait instanceof DiscardOldBranchTrait || trait instanceof DiscardOldTagTrait);

Check warning on line 255 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/hooks/WebhookAutoRegisterListener.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 255 is only partially covered, 2 branches are missing
}

@CheckForNull
private BitbucketApi getClientBySource(@NonNull BitbucketSCMSource source, @NonNull BitbucketEndpoint endpoint) {
switch (getRegistration(source)) {
Expand Down
Loading