Class BitbucketServerAPIClient
- java.lang.Object
-
- com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient
-
- All Implemented Interfaces:
BitbucketApi
public class BitbucketServerAPIClient extends Object implements BitbucketApi
Bitbucket API client. Developed and test with Bitbucket 4.3.2
-
-
Constructor Summary
Constructors Constructor Description BitbucketServerAPIClient(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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
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)
BitbucketServerBranch
getBranch(String branchName)
Returns a branch in the repository.List<BitbucketServerBranch>
getBranches()
Returns the branches in the repository.String
getDefaultBranch()
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.InputStream
getFileContent(BitbucketSCMFile file)
Return an input stream for the given file.List<BitbucketServerPullRequest>
getIncomingOpenPullRequests(String toRef)
List<BitbucketServerPullRequest>
getOutgoingOpenPullRequests(String fromRef)
String
getOwner()
Bitbucket Server manages two top level entities, owner and/or project.BitbucketPullRequest
getPullRequestById(Integer id)
Returns a specific pull request.List<BitbucketServerPullRequest>
getPullRequests()
Returns the pull requests in the repository.List<BitbucketServerRepository>
getRepositories()
Returns all the repositories for the current owner (even if it's a regular user or a team).List<BitbucketServerRepository>
getRepositories(UserRoleInRepository role)
The role parameter is ignored for Bitbucket Server.BitbucketRepository
getRepository()
Returns the repository details.String
getRepositoryName()
Returns the repository name.String
getRepositoryUri(BitbucketRepositoryProtocol protocol, String cloneLink, String owner, String repository)
Returns the URI of the repository.protected String
getRequest(String path)
BitbucketServerBranch
getTag(String tagName)
Returns a tag in the repository.List<BitbucketServerBranch>
getTags()
Returns the tags in the repository.BitbucketTeam
getTeam()
There is no such Team concept in Bitbucket Server but Project.AvatarCacheSource.AvatarImage
getTeamAvatar()
Get Team avatarString
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).List<? extends BitbucketWebHook>
getWebHooks()
Returns the webhooks defined in the repository.boolean
isPrivate()
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
registerCommitWebHook(BitbucketWebHook hook)
Register a webhook on the repository.void
removeCommitWebHook(BitbucketWebHook hook)
Remove the webhook (ID field required) from the repository.BitbucketCommit
resolveCommit(BitbucketPullRequest pull)
Resolve the head commit object of the pull request source repository branch.BitbucketCommit
resolveCommit(String hash)
Resolve the commit object given its hash.String
resolveSourceFullHash(BitbucketPullRequest pull)
Resolve the head commit hash of the pull request source repository branch.void
updateCommitWebHook(BitbucketWebHook hook)
Update a webhook on the repository.
-
-
-
Constructor Detail
-
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 Detail
-
getOwner
@NonNull public String 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
public String 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
@CheckForNull public String getRepositoryName()
Returns the repository name.- Specified by:
getRepositoryName
in interfaceBitbucketApi
- Returns:
- the repository name.
-
getRepositoryUri
@NonNull public String getRepositoryUri(@NonNull BitbucketRepositoryProtocol protocol, @CheckForNull String cloneLink, @NonNull String owner, @NonNull String repository)
Returns the URI of the repository.- Specified by:
getRepositoryUri
in interfaceBitbucketApi
- Parameters:
protocol
- the protocol to access the repository with.cloneLink
- the actual clone link for the repository as sent by the server, ornull
if unknown.owner
- the ownerrepository
- the repository.- Returns:
- the repository URI.
-
getPullRequests
@NonNull public List<BitbucketServerPullRequest> getPullRequests() throws IOException, InterruptedException
Returns 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
@NonNull public BitbucketRepository getRepository() throws IOException, InterruptedException
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.
-
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
@CheckForNull public String getDefaultBranch() throws IOException, InterruptedException
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
@NonNull public List<BitbucketServerBranch> getTags() throws IOException, InterruptedException
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
@NonNull public List<BitbucketServerBranch> getBranches() throws IOException, InterruptedException
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
@NonNull public String resolveSourceFullHash(@NonNull BitbucketPullRequest pull)
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
public void registerCommitWebHook(BitbucketWebHook hook) throws IOException, InterruptedException
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
public void updateCommitWebHook(BitbucketWebHook hook) throws IOException, InterruptedException
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
public void removeCommitWebHook(BitbucketWebHook hook) throws IOException, InterruptedException
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, InterruptedException
Description 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
public BitbucketTeam getTeam() throws IOException, InterruptedException
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
public AvatarCacheSource.AvatarImage getTeamAvatar() throws IOException
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, InterruptedException
Returns 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
public boolean isPrivate() throws IOException, InterruptedException
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
protected String getRequest(String path) throws IOException, InterruptedException
- 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
public InputStream getFileContent(BitbucketSCMFile file) throws IOException, InterruptedException
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
-
-