Class BitbucketServerAPIClient
java.lang.Object
com.cloudbees.jenkins.plugins.bitbucket.impl.client.AbstractBitbucketApi
com.cloudbees.jenkins.plugins.bitbucket.server.client.BitbucketServerAPIClient
- All Implemented Interfaces:
BitbucketApi,AutoCloseable
Bitbucket API client.
Developed and test with Bitbucket 4.3.2
-
Field Summary
Fields inherited from class com.cloudbees.jenkins.plugins.bitbucket.impl.client.AbstractBitbucketApi
logger -
Constructor Summary
ConstructorsConstructorDescriptionBitbucketServerAPIClient(String baseURL, String owner, String repositoryName, BitbucketAuthenticator authenticator, boolean userCentric) -
Method Summary
Modifier and TypeMethodDescriptionbooleancheckPathExists(String branchOrHash, String path) Checks if the given path exists in the repository at the specified branch.jenkins.scm.impl.avatars.AvatarImageReturns an Avatar image from the given URL.protected StringReturns a branch in the repository.Returns the branches in the repository.protected org.apache.hc.client5.http.impl.classic.CloseableHttpClientgetCommits(String fromCommit, String toCommit) Return a set of base informations between the two given commits.protected org.apache.hc.client5.http.io.HttpClientConnectionManagerGets 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.jenkins.scm.api.SCMFilegetFile(BitbucketSCMFile file) Return the metadata for the given file.Return an input stream for the given file.protected org.apache.hc.core5.http.HttpHostgetHost()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.Returns a tag in the repository.getTags()Returns the tags in the repository.getTeam()There is no such Team concept in Bitbucket Data Center but Project.jenkins.scm.impl.avatars.AvatarImageDeprecated, for removal: This API element is subject to removal in a future version.booleanReturnstrueif and only if the repository is private.protected booleanisSupportedAuthenticator(BitbucketAuthenticator authenticator) Implementation must validate if the configured authenticator is supported by this client implementation.voidpostBuildStatus(BitbucketBuildStatus status) Deprecated.voidpostCommitComment(String hash, String comment) Post a comment to a given commit hash.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.Methods inherited from class com.cloudbees.jenkins.plugins.bitbucket.impl.client.AbstractBitbucketApi
adapt, buildResponseException, close, connectionManagerBuilder, deleteRequest, executeMethod, getAuthenticator, getRequest, getRequestAsInputStream, getResponseContent, getWebHooks, headRequestStatus, postRequest, postRequest, putRequest, registerCommitWebHook, removeCommitWebHook, setClientProxyParams, setupClientBuilder, updateCommitWebHookMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.cloudbees.jenkins.plugins.bitbucket.api.BitbucketApi
adapt, close, getWebHooks, registerCommitWebHook, removeCommitWebHook, updateCommitWebHook
-
Constructor Details
-
BitbucketServerAPIClient
public BitbucketServerAPIClient(@NonNull String baseURL, @NonNull String owner, @CheckForNull String repositoryName, @CheckForNull BitbucketAuthenticator authenticator, boolean userCentric)
-
-
Method Details
-
isSupportedAuthenticator
Description copied from class:AbstractBitbucketApiImplementation must validate if the configured authenticator is supported by this client implementation.- Specified by:
isSupportedAuthenticatorin classAbstractBitbucketApi
-
getOwner
Bitbucket Server manages two top level entities, owner and/or project. Only one of them makes sense for a specific client object.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.
- Specified by:
getOwnerin interfaceBitbucketApi- Returns:
- the ~user or project
-
getRepositoryName
Returns the repository name.- Specified by:
getRepositoryNamein interfaceBitbucketApi- Returns:
- the repository name.
-
getPullRequests
Returns the pull requests in the repository.- Specified by:
getPullRequestsin interfaceBitbucketApi- Returns:
- the list of pull requests in the repository.
- Throws:
IOException- if there was a network communications error.
-
getOutgoingOpenPullRequests
@NonNull public List<BitbucketServerPullRequest> getOutgoingOpenPullRequests(String fromRef) throws IOException - Throws:
IOException
-
getIncomingOpenPullRequests
@NonNull public List<BitbucketServerPullRequest> getIncomingOpenPullRequests(String toRef) throws IOException - Throws:
IOException
-
getPullRequestById
Returns a specific pull request.- Specified by:
getPullRequestByIdin 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.
-
getRepository
Returns the repository details.- Specified by:
getRepositoryin 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.
-
getMirrors
Returns the mirror servers.- Returns:
- the mirror servers
- Throws:
IOException- if there was a network communications error.
-
getMirrors
@NonNull public List<BitbucketMirroredRepositoryDescriptor> getMirrors(@NonNull Long repositoryId) throws IOException Returns the repository mirror descriptors.- Returns:
- the repository mirror descriptors for given repository id.
- Throws:
IOException- if there was a network communications error.
-
getMirroredRepository
@NonNull public BitbucketMirroredRepository getMirroredRepository(@NonNull String url) throws IOException 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.
-
postCommitComment
Post a comment to a given commit hash.- Specified by:
postCommitCommentin interfaceBitbucketApi- Parameters:
hash- commit hashcomment- string to post as comment- Throws:
IOException- if there was a network communications error.
-
postBuildStatus
Deprecated.Set the build status for the given commit hash.- Specified by:
postBuildStatusin interfaceBitbucketApi- Parameters:
status- the status object to be serialized- Throws:
IOException- if there was a network communications error.
-
checkPathExists
public boolean checkPathExists(@NonNull String branchOrHash, @NonNull String path) throws IOException Checks if the given path exists in the repository at the specified branch.- Specified by:
checkPathExistsin 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.
-
getDefaultBranch
Description copied from interface:BitbucketApiGets the default branch in the repository.- Specified by:
getDefaultBranchin interfaceBitbucketApi- Returns:
- the default branch in the repository or null if no default branch set
- Throws:
IOException- if there was a network communications error.
-
getTag
Returns a tag in the repository.- Specified by:
getTagin interfaceBitbucketApi- Returns:
- a tag in the repository.
- Throws:
IOException- if there was a network communications error.
-
getTags
Returns the tags in the repository.- Specified by:
getTagsin interfaceBitbucketApi- Returns:
- the list of tags in the repository.
- Throws:
IOException- if there was a network communications error.
-
getBranch
Returns a branch in the repository.- Specified by:
getBranchin interfaceBitbucketApi- Returns:
- a branch in the repository.
- Throws:
IOException- if there was a network communications error.
-
getBranches
Returns the branches in the repository.- Specified by:
getBranchesin interfaceBitbucketApi- Returns:
- the list of branches in the repository.
- Throws:
IOException- if there was a network communications error.
-
resolveCommit
Resolve the commit object given its hash.- Specified by:
resolveCommitin 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.
-
resolveSourceFullHash
Resolve the head commit hash of the pull request source repository branch.- Specified by:
resolveSourceFullHashin 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 Description copied from interface:BitbucketApiResolve the head commit object of the pull request source repository branch.- Specified by:
resolveCommitin 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.
-
getTeam
There is no such Team concept in Bitbucket Data Center but Project.- Specified by:
getTeamin interfaceBitbucketApi- Returns:
- the team profile of the current owner, or
nullifBitbucketApi.getOwner()is not a team ID. - Throws:
IOException- if there was a network communications error.
-
getTeamAvatar
@Deprecated(since="935.0.0", forRemoval=true) public jenkins.scm.impl.avatars.AvatarImage getTeamAvatar() throws IOExceptionDeprecated, for removal: This API element is subject to removal in a future version.Returns the team Avatar of the current owner ornullif the current owner is not a team.- Specified by:
getTeamAvatarin interfaceBitbucketApi- Returns:
- the team profile of the current owner, or
nullifBitbucketApi.getOwner()is not a team ID. - Throws:
IOException- if there was a network communications error.
-
getAvatar
Returns an Avatar image from the given URL.The URL link could come from repository, project, workspace or user links.
- Specified by:
getAvatarin interfaceBitbucketApi- Returns:
- the resource image.
- Throws:
IOException- if there was a network communications error.
-
getRepositories
@NonNull public List<BitbucketServerRepository> getRepositories(@CheckForNull UserRoleInRepository role) throws IOException The role parameter is ignored for Bitbucket Server.- Specified by:
getRepositoriesin interfaceBitbucketApi- Parameters:
role- Filter repositories by the owner having this role in. SeeUserRoleInRepositoryfor 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.
-
getRepositories
Returns all the repositories for the current owner (even if it's a regular user or a team).- Specified by:
getRepositoriesin interfaceBitbucketApi- Returns:
- all repositories for the current
BitbucketApi.getOwner() - Throws:
IOException- if there was a network communications error.
-
isPrivate
Description copied from interface:BitbucketApiReturnstrueif and only if the repository is private.- Specified by:
isPrivatein interfaceBitbucketApi- Returns:
trueif the repository (BitbucketApi.getOwner()/BitbucketApi.getRepositoryName()) is private.- Throws:
IOException- if there was a network communications error.
-
getConnectionManager
protected org.apache.hc.client5.http.io.HttpClientConnectionManager getConnectionManager()- Specified by:
getConnectionManagerin classAbstractBitbucketApi
-
getClient
@NonNull protected org.apache.hc.client5.http.impl.classic.CloseableHttpClient getClient()- Specified by:
getClientin classAbstractBitbucketApi
-
getHost
@NonNull protected org.apache.hc.core5.http.HttpHost getHost()- Specified by:
getHostin classAbstractBitbucketApi
-
getBaseURL
- Specified by:
getBaseURLin classAbstractBitbucketApi
-
getDirectoryContent
public Iterable<jenkins.scm.api.SCMFile> getDirectoryContent(BitbucketSCMFile directory) throws IOException Description copied from interface:BitbucketApiReturns a list of all children file for the given folder.- Specified by:
getDirectoryContentin interfaceBitbucketApi- Parameters:
directory- to list- Returns:
- an iterable of
SCMFilechildren of the given folder. - Throws:
IOException- if there was a network communications error.
-
getFileContent
Description copied from interface:BitbucketApiReturn an input stream for the given file.- Specified by:
getFileContentin interfaceBitbucketApi- Parameters:
file- an instance of SCM file- Returns:
- the stream of the given
SCMFile - Throws:
IOException- if there was a network communications error.
-
getFile
Description copied from interface:BitbucketApiReturn the metadata for the given file.- Specified by:
getFilein interfaceBitbucketApi- Parameters:
file- an instance of SCM file- Returns:
- a
SCMFilefile with updated the metadata - Throws:
IOException- if there was a network communications error.
-
getCommits
@NonNull public List<BitbucketServerCommit> getCommits(String fromCommit, String toCommit) throws IOException Description copied from interface:BitbucketApiReturn a set of base informations between the two given commits.- Specified by:
getCommitsin interfaceBitbucketApi- Parameters:
fromCommit- the commit or reference containing the changes we wish to preview ornullto get changes since the beginning.toCommit- the commit or reference representing the state to which we want to compare the first commit- Returns:
- the list of commit between first commit and second source commit.
- Throws:
IOException- if there was a network communications error.
-