Interface BitbucketApi
- All Known Implementing Classes:
BitbucketCloudApiClient
,BitbucketServerAPIClient
public interface BitbucketApi
Provides access to a specific repository.
One API object needs to be created for each repository you want to work with.
-
Method Summary
Modifier and TypeMethodDescriptionboolean
checkPathExists
(String branchOrHash, String path) Checks if the given path exists in the repository at the specified branch.Returns a branch in the repository.List<? extends BitbucketBranch>
Returns the branches in the repository.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.Return an input stream for the given file.getOwner()
Returns the owner name for the repository.Returns a specific pull request.List<? extends BitbucketPullRequest>
Returns the pull requests in the repository.List<? extends BitbucketRepository>
Returns all the repositories for the current owner (even if it's a regular user or a team).List<? extends BitbucketRepository>
Returns the repositories where the user has the given role.Returns the repository details.Returns the repository name.Returns a tag in the repository.List<? extends BitbucketBranch>
getTags()
Returns the tags in the repository.getTeam()
Returns the team of the current owner ornull
if the current owner is not a team.Returns the team Avatar of the current owner ornull
if the current owner is not a team.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.
-
Method Details
-
getOwner
Returns the owner name for the repository.- Returns:
- the repository owner name.
-
getRepositoryName
Returns the repository name.- Returns:
- the repository name.
-
getPullRequests
@NonNull List<? extends BitbucketPullRequest> getPullRequests() throws IOException, InterruptedExceptionReturns the pull requests in the repository.- 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.
-
getPullRequestById
@NonNull BitbucketPullRequest getPullRequestById(@NonNull Integer id) throws IOException, InterruptedException Returns a specific pull request.- 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.- Returns:
- the repository specified by
getOwner()
/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
void postCommitComment(@NonNull String hash, @NonNull String comment) throws IOException, InterruptedException Post a comment to a given commit hash.- 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
boolean checkPathExists(@NonNull String branchOrHash, @NonNull String path) throws IOException, InterruptedException Checks if the given path exists in the repository at the specified branch.- 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
Gets the default branch in the repository.- 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.
-
getBranch
@CheckForNull BitbucketBranch getBranch(@NonNull String branchName) throws IOException, InterruptedException Returns a branch in the repository.- 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.- 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.
-
getTag
@CheckForNull BitbucketBranch getTag(@NonNull String tagName) throws IOException, InterruptedException Returns a tag in the repository.- 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.- 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.
-
resolveCommit
@CheckForNull BitbucketCommit resolveCommit(@NonNull String hash) throws IOException, InterruptedException Resolve the commit object given its hash.- 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.
-
resolveCommit
@NonNull BitbucketCommit resolveCommit(@NonNull BitbucketPullRequest pull) throws IOException, InterruptedException Resolve the head commit object of the pull request source repository branch.- 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.- Since:
- 2.2.14
-
resolveSourceFullHash
@NonNull String resolveSourceFullHash(@NonNull BitbucketPullRequest pull) throws IOException, InterruptedException Resolve the head commit hash of the pull request source repository branch.- 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.
-
registerCommitWebHook
Register a webhook on the repository.- Parameters:
hook
- the webhook object- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
updateCommitWebHook
Update a webhook on the repository.- Parameters:
hook
- the webhook object- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
removeCommitWebHook
Remove the webhook (ID field required) from the repository.- Parameters:
hook
- the webhook object- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getWebHooks
Returns the webhooks defined in the repository.- 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
Returns the team of the current owner ornull
if the current owner is not a team.- Returns:
- the team profile of the current owner, or
null
ifgetOwner()
is not a team ID. - Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getTeamAvatar
@CheckForNull AvatarCacheSource.AvatarImage getTeamAvatar() throws IOException, InterruptedExceptionReturns the team Avatar of the current owner ornull
if the current owner is not a team.- Returns:
- the team profile of the current owner, or
null
ifgetOwner()
is not a team ID. - Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getRepositories
@NonNull List<? extends BitbucketRepository> getRepositories(@CheckForNull UserRoleInRepository role) throws IOException, InterruptedException Returns the repositories where the user has the given role.- 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 List<? extends BitbucketRepository> getRepositories() throws IOException, InterruptedExceptionReturns all the repositories for the current owner (even if it's a regular user or a team).- Returns:
- all repositories for the current
getOwner()
- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
postBuildStatus
Set the build status for the given commit hash.- 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
Returnstrue
if and only if the repository is private.- Returns:
true
if the repository (getOwner()
/getRepositoryName()
) is private.- Throws:
IOException
- if there was a network communications error.InterruptedException
- if interrupted while waiting on remote communications.
-
getDirectoryContent
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) Iterable<jenkins.scm.api.SCMFile> getDirectoryContent(BitbucketSCMFile parent) throws IOException, InterruptedException Returns a list of all children file for the given folder.- 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
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) InputStream getFileContent(BitbucketSCMFile file) throws IOException, InterruptedException Return an input stream for the given file.- 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.
-