Class BitbucketServerAPIClient
java.lang.Object
com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient
- All Implemented Interfaces:
BitbucketApi
Bitbucket API client.
Developed and test with Bitbucket 4.3.2
-
Constructor Summary
ConstructorDescriptionBitbucketServerAPIClient
(String baseURL, String owner, String repositoryName, BitbucketAuthenticator authenticator, boolean userCentric) BitbucketServerAPIClient
(String baseURL, String owner, String repositoryName, BitbucketAuthenticator authenticator, boolean userCentric, BitbucketServerWebhookImplementation webhookImplementation) BitbucketServerAPIClient
(String baseURL, String owner, String repositoryName, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials credentials, boolean userCentric) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkPathExists
(String branchOrHash, String path) Checks if the given path exists in the repository at the specified branch.protected org.apache.http.client.methods.CloseableHttpResponse
executeMethodNoRetry
(org.apache.http.impl.client.CloseableHttpClient client, org.apache.http.client.methods.HttpRequestBase httpMethod, org.apache.http.client.protocol.HttpClientContext context) Returns a branch in the repository.Returns the branches in the repository.Gets the default branch in the repository.Iterable<jenkins.scm.api.SCMFile>
getDirectoryContent
(BitbucketSCMFile directory) Returns a list of all children file for the given folder.Return an input stream for the given file.Retrieves all available clone urls for the specified repository.Returns the mirror servers.getMirrors
(Long repositoryId) Returns the repository mirror descriptors.getOutgoingOpenPullRequests
(String fromRef) getOwner()
Bitbucket Server manages two top level entities, owner and/or project.Returns a specific pull request.Returns the pull requests in the repository.Returns all the repositories for the current owner (even if it's a regular user or a team).The role parameter is ignored for Bitbucket Server.Returns the repository details.Returns the repository name.protected String
getRequest
(String path) Returns a tag in the repository.getTags()
Returns the tags in the repository.getTeam()
There is no such Team concept in Bitbucket Server but Project.Get Team avatarIn Bitbucket server the top level entity is the Project, but the JSON API accepts users as a replacement of Projects in most of the URLs (it's called user centric API).List<? extends BitbucketWebHook>
Returns the webhooks defined in the repository.boolean
Returnstrue
if and only if the repository is private.void
postBuildStatus
(BitbucketBuildStatus status) Set the build status for the given commit hash.void
postCommitComment
(String hash, String comment) Post a comment to a given commit hash.void
Register a webhook on the repository.void
Remove the webhook (ID field required) from the repository.Resolve the head commit object of the pull request source repository branch.resolveCommit
(String hash) Resolve the commit object given its hash.Resolve the head commit hash of the pull request source repository branch.void
Update a webhook on the repository.
-
Constructor Details
-
BitbucketServerAPIClient
@Deprecated public BitbucketServerAPIClient(@NonNull String baseURL, @NonNull String owner, @CheckForNull String repositoryName, @CheckForNull com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials credentials, boolean userCentric) Deprecated. -
BitbucketServerAPIClient
public BitbucketServerAPIClient(@NonNull String baseURL, @NonNull String owner, @CheckForNull String repositoryName, @CheckForNull BitbucketAuthenticator authenticator, boolean userCentric) -
BitbucketServerAPIClient
public BitbucketServerAPIClient(@NonNull String baseURL, @NonNull String owner, @CheckForNull String repositoryName, @CheckForNull BitbucketAuthenticator authenticator, boolean userCentric, @NonNull BitbucketServerWebhookImplementation webhookImplementation)
-
-
Method Details
-
getOwner
Bitbucket Server manages two top level entities, owner and/or project. Only one of them makes sense for a specific client object.- Specified by:
getOwner
in interfaceBitbucketApi
- Returns:
- the repository owner name.
-
getUserCentricOwner
In Bitbucket server the top level entity is the Project, but the JSON API accepts users as a replacement of Projects in most of the URLs (it's called user centric API). This method returns the appropriate string to be placed in request URLs taking into account if this client object was created as a user centric instance or not.- Returns:
- the ~user or project
-
getRepositoryName
Returns the repository name.- Specified by:
getRepositoryName
in interfaceBitbucketApi
- Returns:
- the repository name.
-
getPullRequests
@NonNull public List<BitbucketServerPullRequest> getPullRequests() throws IOException, InterruptedExceptionReturns the pull requests in the repository.- Specified by:
getPullRequests
in interfaceBitbucketApi
- Returns:
- the list of pull requests in the repository.
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getOutgoingOpenPullRequests
@NonNull public List<BitbucketServerPullRequest> getOutgoingOpenPullRequests(String fromRef) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
getIncomingOpenPullRequests
@NonNull public List<BitbucketServerPullRequest> getIncomingOpenPullRequests(String toRef) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-
getPullRequestById
@NonNull public BitbucketPullRequest getPullRequestById(@NonNull Integer id) throws IOException, InterruptedException Returns a specific pull request.- Specified by:
getPullRequestById
in interfaceBitbucketApi
- Parameters:
id
- the pull request ID- Returns:
- the pull request or null if the PR does not exist
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getRepository
Returns the repository details.- Specified by:
getRepository
in interfaceBitbucketApi
- Returns:
- the repository specified by
BitbucketApi.getOwner()
/BitbucketApi.getRepositoryName()
(or null if repositoryName is not set) - Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getMirrors
Returns the mirror servers.- Returns:
- the mirror servers
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getMirrors
@NonNull public List<BitbucketMirroredRepositoryDescriptor> getMirrors(@NonNull Long repositoryId) throws IOException, InterruptedException Returns the repository mirror descriptors.- Returns:
- the repository mirror descriptors for given repository id.
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getMirroredRepository
@NonNull public BitbucketMirroredRepository getMirroredRepository(@NonNull String url) throws IOException, InterruptedException Retrieves all available clone urls for the specified repository.- Parameters:
url
- mirror repository self-url- Returns:
- all available clone urls for the specified repository.
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
postCommitComment
public void postCommitComment(@NonNull String hash, @NonNull String comment) throws IOException, InterruptedException Post a comment to a given commit hash.- Specified by:
postCommitComment
in interfaceBitbucketApi
- Parameters:
hash
- commit hashcomment
- string to post as comment- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
postBuildStatus
public void postBuildStatus(@NonNull BitbucketBuildStatus status) throws IOException, InterruptedException Set the build status for the given commit hash.- Specified by:
postBuildStatus
in interfaceBitbucketApi
- Parameters:
status
- the status object to be serialized- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
checkPathExists
public boolean checkPathExists(@NonNull String branchOrHash, @NonNull String path) throws IOException, InterruptedException Checks if the given path exists in the repository at the specified branch.- Specified by:
checkPathExists
in interfaceBitbucketApi
- Parameters:
branchOrHash
- the branch name or commit hashpath
- the path to check for- Returns:
- true if the path exists
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getDefaultBranch
Description copied from interface:BitbucketApi
Gets the default branch in the repository.- Specified by:
getDefaultBranch
in interfaceBitbucketApi
- Returns:
- the default branch in the repository or null if no default branch set
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getTag
public BitbucketServerBranch getTag(@NonNull String tagName) throws IOException, InterruptedException Returns a tag in the repository.- Specified by:
getTag
in interfaceBitbucketApi
- Returns:
- a tag in the repository.
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getTags
Returns the tags in the repository.- Specified by:
getTags
in interfaceBitbucketApi
- Returns:
- the list of tags in the repository.
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getBranch
public BitbucketServerBranch getBranch(@NonNull String branchName) throws IOException, InterruptedException Returns a branch in the repository.- Specified by:
getBranch
in interfaceBitbucketApi
- Returns:
- a branch in the repository.
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getBranches
Returns the branches in the repository.- Specified by:
getBranches
in interfaceBitbucketApi
- Returns:
- the list of branches in the repository.
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
resolveCommit
@NonNull public BitbucketCommit resolveCommit(@NonNull String hash) throws IOException, InterruptedException Resolve the commit object given its hash.- Specified by:
resolveCommit
in interfaceBitbucketApi
- Parameters:
hash
- the hash to resolve- Returns:
- the commit object or null if the hash does not exist
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
resolveSourceFullHash
Resolve the head commit hash of the pull request source repository branch.- Specified by:
resolveSourceFullHash
in interfaceBitbucketApi
- Parameters:
pull
- the pull request to resolve the source hash from- Returns:
- the source head hash
-
resolveCommit
@NonNull public BitbucketCommit resolveCommit(@NonNull BitbucketPullRequest pull) throws IOException, InterruptedException Description copied from interface:BitbucketApi
Resolve the head commit object of the pull request source repository branch.- Specified by:
resolveCommit
in interfaceBitbucketApi
- Parameters:
pull
- the pull request to resolve the source hash from- Returns:
- the source head commit object
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
registerCommitWebHook
Description copied from interface:BitbucketApi
Register a webhook on the repository.- Specified by:
registerCommitWebHook
in interfaceBitbucketApi
- Parameters:
hook
- the webhook object- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
updateCommitWebHook
Description copied from interface:BitbucketApi
Update a webhook on the repository.- Specified by:
updateCommitWebHook
in interfaceBitbucketApi
- Parameters:
hook
- the webhook object- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
removeCommitWebHook
Description copied from interface:BitbucketApi
Remove the webhook (ID field required) from the repository.- Specified by:
removeCommitWebHook
in interfaceBitbucketApi
- Parameters:
hook
- the webhook object- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getWebHooks
@NonNull public List<? extends BitbucketWebHook> getWebHooks() throws IOException, InterruptedExceptionDescription copied from interface:BitbucketApi
Returns the webhooks defined in the repository.- Specified by:
getWebHooks
in interfaceBitbucketApi
- Returns:
- the list of webhooks registered in the repository.
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getTeam
There is no such Team concept in Bitbucket Server but Project.- Specified by:
getTeam
in interfaceBitbucketApi
- Returns:
- the team profile of the current owner, or
null
ifBitbucketApi.getOwner()
is not a team ID. - Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getTeamAvatar
Get Team avatar- Specified by:
getTeamAvatar
in interfaceBitbucketApi
- Returns:
- the team profile of the current owner, or
null
ifBitbucketApi.getOwner()
is not a team ID. - Throws:
IOException
- if there was a network communications error.
-
getRepositories
@NonNull public List<BitbucketServerRepository> getRepositories(@CheckForNull UserRoleInRepository role) throws IOException, InterruptedException The role parameter is ignored for Bitbucket Server.- Specified by:
getRepositories
in interfaceBitbucketApi
- Parameters:
role
- Filter repositories by the owner having this role in. SeeUserRoleInRepository
for more information. Use role = null if the repoOwner is a team ID.- Returns:
- the repositories list (it can be empty)
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getRepositories
@NonNull public List<BitbucketServerRepository> getRepositories() throws IOException, InterruptedExceptionReturns all the repositories for the current owner (even if it's a regular user or a team).- Specified by:
getRepositories
in interfaceBitbucketApi
- Returns:
- all repositories for the current
BitbucketApi.getOwner()
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
isPrivate
Description copied from interface:BitbucketApi
Returnstrue
if and only if the repository is private.- Specified by:
isPrivate
in interfaceBitbucketApi
- Returns:
true
if the repository (BitbucketApi.getOwner()
/BitbucketApi.getRepositoryName()
) is private.- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getRequest
- Throws:
IOException
InterruptedException
-
getDirectoryContent
public Iterable<jenkins.scm.api.SCMFile> getDirectoryContent(BitbucketSCMFile directory) throws IOException, InterruptedException Description copied from interface:BitbucketApi
Returns a list of all children file for the given folder.- Specified by:
getDirectoryContent
in interfaceBitbucketApi
- Parameters:
directory
- to list- Returns:
- an iterable of
SCMFile
children of the given folder. - Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getFileContent
Description copied from interface:BitbucketApi
Return an input stream for the given file.- Specified by:
getFileContent
in interfaceBitbucketApi
- Parameters:
file
- and instance of SCM file- Returns:
- the stream of the given
SCMFile
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
executeMethodNoRetry
@Restricted(org.kohsuke.accmod.restrictions.ProtectedExternally.class) protected org.apache.http.client.methods.CloseableHttpResponse executeMethodNoRetry(org.apache.http.impl.client.CloseableHttpClient client, org.apache.http.client.methods.HttpRequestBase httpMethod, org.apache.http.client.protocol.HttpClientContext context) throws IOException, InterruptedException - Throws:
IOException
InterruptedException
-