Class BitbucketCloudApiClient
- java.lang.Object
-
- com.cloudbees.jenkins.plugins.bitbucket.client.BitbucketCloudApiClient
-
- All Implemented Interfaces:
BitbucketApi
public class BitbucketCloudApiClient extends Object implements BitbucketApi
-
-
Constructor Summary
Constructors Constructor Description BitbucketCloudApiClient(boolean enableCache, int teamCacheDuration, int repositoriesCacheDuration, String owner, String repositoryName, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials credentials)
Deprecated.BitbucketCloudApiClient(boolean enableCache, int teamCacheDuration, int repositoriesCacheDuration, String owner, String projectKey, String repositoryName, BitbucketAuthenticator authenticator)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated 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.static void
clearCaches()
protected org.apache.http.client.methods.CloseableHttpResponse
executeMethod(org.apache.http.client.methods.HttpRequestBase httpMethod)
protected org.apache.http.client.methods.CloseableHttpResponse
executeMethod(org.apache.http.HttpHost host, org.apache.http.client.methods.HttpRequestBase httpMethod)
protected void
finalize()
BitbucketCloudBranch
getBranch(String branchName)
Returns a branch in the repository.List<BitbucketCloudBranch>
getBranches()
Returns the branches in the repository.List<BitbucketCloudBranch>
getBranchesByRef(String nodePath)
String
getDefaultBranch()
Gets the default branch in the repository.Iterable<jenkins.scm.api.SCMFile>
getDirectoryContent(BitbucketSCMFile parent)
Returns a list of all children file for the given folder.InputStream
getFileContent(BitbucketSCMFile file)
Return an input stream for the given file.String
getLogin()
Deprecated.String
getOwner()
Returns the owner name for the repository.BitbucketPullRequest
getPullRequestById(Integer id)
Returns a specific pull request.List<BitbucketPullRequestValue>
getPullRequests()
Returns the pull requests in the repository.List<BitbucketCloudRepository>
getRepositories()
Returns all the repositories for the current owner (even if it's a regular user or a team).List<BitbucketCloudRepository>
getRepositories(UserRoleInRepository role)
The role parameter only makes sense when the request is authenticated, so if there is no auth information (authenticator
) the role will be omitted.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.BitbucketCloudBranch
getTag(String tagName)
Returns a tag in the repository.List<BitbucketCloudBranch>
getTags()
Returns the tags in the repository.BitbucketTeam
getTeam()
Returns the team of the current owner ornull
if the current owner is not a team.AvatarCacheSource.AvatarImage
getTeamAvatar()
Returns the team Avatar of the current owner ornull
if the current owner is not a team.List<BitbucketRepositoryHook>
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.static List<String>
stats()
void
updateCommitWebHook(BitbucketWebHook hook)
Update a webhook on the repository.
-
-
-
Constructor Detail
-
BitbucketCloudApiClient
@Deprecated public BitbucketCloudApiClient(boolean enableCache, int teamCacheDuration, int repositoriesCacheDuration, String owner, String repositoryName, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials credentials)
Deprecated.
-
BitbucketCloudApiClient
public BitbucketCloudApiClient(boolean enableCache, int teamCacheDuration, int repositoriesCacheDuration, String owner, String projectKey, String repositoryName, BitbucketAuthenticator authenticator)
-
-
Method Detail
-
clearCaches
public static void clearCaches()
-
finalize
protected void finalize() throws Throwable
-
getOwner
@NonNull public String getOwner()
Returns the owner name for the repository.- Specified by:
getOwner
in interfaceBitbucketApi
- Returns:
- the repository owner name.
-
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<BitbucketPullRequestValue> getPullRequests() throws InterruptedException, IOException
Returns the pull requests in the repository.- Specified by:
getPullRequests
in interfaceBitbucketApi
- Returns:
- the list of pull requests in the repository.
- Throws:
InterruptedException
- if interrupted while waiting on remote communications.IOException
- if there was a network communications error.
-
getLogin
@Deprecated @CheckForNull public String getLogin()
Deprecated.
-
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.
-
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
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 BitbucketCloudBranch 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<BitbucketCloudBranch> 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 BitbucketCloudBranch 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<BitbucketCloudBranch> 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.
-
getBranchesByRef
public List<BitbucketCloudBranch> getBranchesByRef(String nodePath) throws IOException, InterruptedException
- Throws:
IOException
InterruptedException
-
resolveCommit
@CheckForNull 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) throws IOException, InterruptedException
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
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
resolveCommit
@NonNull public BitbucketCommit resolveCommit(@NonNull BitbucketPullRequest pull) throws IOException, InterruptedException
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(@NonNull BitbucketWebHook hook) throws IOException, InterruptedException
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(@NonNull BitbucketWebHook hook) throws IOException, InterruptedException
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(@NonNull BitbucketWebHook hook) throws IOException, InterruptedException
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<BitbucketRepositoryHook> getWebHooks() throws IOException, InterruptedException
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.
-
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.
-
isPrivate
public boolean isPrivate() throws IOException, InterruptedException
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.
-
getTeam
@CheckForNull public BitbucketTeam getTeam() throws IOException, InterruptedException
Returns the team of the current owner ornull
if the current owner is not a team.- 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
@CheckForNull public AvatarCacheSource.AvatarImage getTeamAvatar() throws IOException, InterruptedException
Returns the team Avatar of the current owner ornull
if the current owner is not a team.- 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.InterruptedException
- if interrupted while waiting on remote communications.
-
getRepositories
@NonNull public List<BitbucketCloudRepository> getRepositories(@CheckForNull UserRoleInRepository role) throws InterruptedException, IOException
The role parameter only makes sense when the request is authenticated, so if there is no auth information (authenticator
) the role will be omitted.- 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:
InterruptedException
- if interrupted while waiting on remote communications.IOException
- if there was a network communications error.
-
getRepositories
@NonNull public List<BitbucketCloudRepository> 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.
-
executeMethod
@Restricted(org.kohsuke.accmod.restrictions.ProtectedExternally.class) protected org.apache.http.client.methods.CloseableHttpResponse executeMethod(org.apache.http.client.methods.HttpRequestBase httpMethod) throws InterruptedException, IOException
- Throws:
InterruptedException
IOException
-
executeMethod
@Restricted(org.kohsuke.accmod.restrictions.ProtectedExternally.class) protected org.apache.http.client.methods.CloseableHttpResponse executeMethod(org.apache.http.HttpHost host, org.apache.http.client.methods.HttpRequestBase httpMethod) throws InterruptedException, IOException
- Throws:
InterruptedException
IOException
-
getDirectoryContent
public Iterable<jenkins.scm.api.SCMFile> getDirectoryContent(BitbucketSCMFile parent) 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:
parent
- 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.
-
-