Skip to content
Merged
Show file tree
Hide file tree
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 @@ -25,6 +25,7 @@

import com.cloudbees.jenkins.plugins.bitbucket.api.webhook.BitbucketWebhookConfiguration;
import com.cloudbees.jenkins.plugins.bitbucket.endpoints.BitbucketEndpointConfiguration;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.AbstractBitbucketEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketCloudEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.endpoint.BitbucketServerEndpoint;
import com.cloudbees.jenkins.plugins.bitbucket.impl.util.BitbucketApiUtils;
Expand Down Expand Up @@ -171,6 +172,27 @@
return endpoint;
}

/**
* Register a new {@link BitbucketEndpoint} to the global configuration. The
* endpoint is created with default values and could be customised by the
* given endpointCustomiser.
* <p>
* The given customiser can also return a different implementation
*
* @param name of the endpoint, alias for label
* @param serverURL the bitbucket endpoint URL
* @param webhook configuration
* @param endpointCustomiser an optional customiser for the created endpoint
* @return the registered endpoint instance.
*/
public static BitbucketEndpoint registerEndpoint(@NonNull String name, @NonNull String serverURL, @NonNull BitbucketWebhookConfiguration webhook, @Nullable UnaryOperator<BitbucketEndpoint> endpointCustomiser) {
BitbucketEndpoint endpoint = registerEndpoint(name, serverURL, endpointCustomiser);
if (endpoint instanceof AbstractBitbucketEndpoint ep) {
ep.setWebhook(webhook);
}
return endpoint;

Check warning on line 193 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/api/endpoint/BitbucketEndpointProvider.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Not covered lines

Lines 189-193 are not covered by tests
}

/**
* Removes a {@link BitbucketEndpoint} that matches the given URl from the
* global configuration.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* The MIT License
*
* Copyright (c) 2025, Nikolas Falco
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cloudbees.jenkins.plugins.bitbucket.api.webhook;

import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.ExtensionPoint;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;

/**
* Base interface that a builder must implement or extend to provide an instance
* of {@link BitbucketWebhookConfiguration}.
*
* @since 937.1.0
*/
@Restricted(Beta.class)
public interface BitbucketWebhookConfigurationBuilder extends ExtensionPoint {

/**
* Returns the identifier of built {@link BitbucketWebhookConfiguration}.
*
* @return configuration identifier
* @see BitbucketWebhookConfiguration#getId()
*/
@NonNull
String getId();

/**
* Enable the auto manage of webhook for each repository in a Jenkins
* project.
*
* @param credentialsId with admin right to add, update or delete webhook of
* a bitbucket repository
* @return builder itself
*/
BitbucketWebhookConfigurationBuilder autoManaged(@NonNull String credentialsId);

/**
* Set the Jenkins root URL used to send event payload.
*
* @param callbackRootURL URL of Jenkins accessible from the Bitbucket
* server instance.
* @return builder itself
*/
BitbucketWebhookConfigurationBuilder callbackRootURL(@NonNull String callbackRootURL);

/**
* Returns an instance of {@link BitbucketWebhookConfiguration} using the
* provided configuration.
*
* @return instance of {@link BitbucketWebhookConfiguration}
*/
BitbucketWebhookConfiguration build();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* The MIT License
*
* Copyright (c) 2025, Nikolas Falco
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cloudbees.jenkins.plugins.bitbucket.api.webhook;

import com.google.common.base.Objects;
import edu.umd.cs.findbugs.annotations.NonNull;
import edu.umd.cs.findbugs.annotations.Nullable;
import hudson.ExtensionList;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.Beta;

/**
* Provider of {@link BitbucketWebhookConfiguration} builders registered in the
* system.
*
* @since 937.1.0
*/
@Restricted(Beta.class)
public final class BitbucketWebhookConfigurationsBuilder {

private BitbucketWebhookConfigurationsBuilder() {
}

/**
* Returns a {@link BitbucketWebhookConfiguration} builder for the given
* configuration identifier.
*
* @param <T> specific builder interface
* @param id webhook configuration identifier
* @param builderInterface class of specific builder
* @return an instance of {@link BitbucketWebhookConfigurationBuilder},
* {@code null} otherwise if no builder found with the given
* paramenters.
*/
@Nullable
public static <T extends BitbucketWebhookConfigurationBuilder> T lookup(@NonNull String id, Class<T> builderInterface) {
return ExtensionList.lookup(builderInterface) //
.stream() //
.filter(provider -> Objects.equal(id, provider.getId())) //
.findFirst() //
.orElse(null);
}

/**
* Returns a {@link BitbucketWebhookConfiguration} builder for the given
* configuration identifier.
*
* @param id webhook configuration identifier
* @return an instance of {@link BitbucketWebhookConfigurationBuilder},
* {@code null} otherwise if no builder found.
*/
@Nullable
public static BitbucketWebhookConfigurationBuilder lookup(@NonNull String id) {
return lookup(id, BitbucketWebhookConfigurationBuilder.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* The MIT License
*
* Copyright (c) 2025, Nikolas Falco
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cloudbees.jenkins.plugins.bitbucket.api.webhook;

import edu.umd.cs.findbugs.annotations.NonNull;
import org.jenkinsci.plugins.plaincredentials.StringCredentials;

/**
* This interface is intended for webhooks to meet the configuration
* specifications provided natively with Atlassian products.
*/
public interface NativeBitbucketWebhookConfigurationBuilder extends BitbucketWebhookConfigurationBuilder {

/**
* Enable the payload signature verification using the given
* {@link StringCredentials}.
*
* @param credentialsId used to verify the signature sent with in payload
* @return the builder that can be used to customise a new instance of
* {@link BitbucketWebhookConfiguration}.
*/
NativeBitbucketWebhookConfigurationBuilder signature(@NonNull String credentialsId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
import java.util.Collection;
import java.util.List;
import jenkins.model.Jenkins;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;
import org.kohsuke.stapler.DataBoundConstructor;
import org.kohsuke.stapler.interceptor.RequirePOST;
import org.kohsuke.stapler.verb.POST;
Expand Down Expand Up @@ -73,7 +75,17 @@ public class BitbucketCloudEndpoint extends AbstractBitbucketEndpoint {
* Default constructor.
*/
public BitbucketCloudEndpoint() {
this(false, 0, 0, new CloudWebhookConfiguration(false, null, false, null));
this(new CloudWebhookConfiguration(false, null, false, null));
}

/**
* Internal Constructor.
*
* @param webhook configuration
*/
@Restricted(NoExternalUse.class)
public BitbucketCloudEndpoint(BitbucketWebhookConfiguration webhook) {
this(false, 0, 0, webhook);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* The MIT License
*
* Copyright (c) 2025, Nikolas Falco
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cloudbees.jenkins.plugins.bitbucket.impl.webhook;

import com.cloudbees.jenkins.plugins.bitbucket.api.webhook.BitbucketWebhookConfigurationBuilder;
import com.cloudbees.jenkins.plugins.bitbucket.api.webhook.NativeBitbucketWebhookConfigurationBuilder;
import edu.umd.cs.findbugs.annotations.NonNull;
import org.kohsuke.accmod.Restricted;
import org.kohsuke.accmod.restrictions.NoExternalUse;

@Restricted(NoExternalUse.class)
public abstract class AbstractBitbucketWebhookConfigurationBuilderImpl implements NativeBitbucketWebhookConfigurationBuilder {

protected String credentialsId;
protected String signatureId;
protected String callbackRootURL;

@Override
public NativeBitbucketWebhookConfigurationBuilder autoManaged(@NonNull String credentialsId) {
this.credentialsId = credentialsId;
return this;
}

@Override
public NativeBitbucketWebhookConfigurationBuilder signature(@NonNull String credentialsId) {
this.signatureId = credentialsId;
return this;
}

@NonNull
@Override
public BitbucketWebhookConfigurationBuilder callbackRootURL(String callbackRootURL) {
this.callbackRootURL = callbackRootURL;
return this;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* The MIT License
*
* Copyright (c) 2025, Nikolas Falco
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package com.cloudbees.jenkins.plugins.bitbucket.impl.webhook.cloud;

import com.cloudbees.jenkins.plugins.bitbucket.impl.webhook.AbstractBitbucketWebhookConfigurationBuilderImpl;
import edu.umd.cs.findbugs.annotations.NonNull;
import hudson.Extension;

@Extension
public class CloudWebhookConfigurationBuilderImpl extends AbstractBitbucketWebhookConfigurationBuilderImpl {

@NonNull
@Override
public String getId() {
return "CLOUD_NATIVE";
}

@NonNull
@Override
public CloudWebhookConfiguration build() {
CloudWebhookConfiguration configuration = new CloudWebhookConfiguration(

Check warning on line 42 in src/main/java/com/cloudbees/jenkins/plugins/bitbucket/impl/webhook/cloud/CloudWebhookConfigurationBuilderImpl.java

View check run for this annotation

ci.jenkins.io / Code Coverage

Partially covered line

Line 42 is only partially covered, 2 branches are missing
credentialsId != null, credentialsId,
signatureId != null, signatureId);
configuration.setEndpointJenkinsRootURL(callbackRootURL);
return configuration;
}

}
Loading
Loading