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

public class BitbucketServerAPIClient extends AbstractBitbucketApi implements BitbucketApi
Bitbucket API client. Developed and test with Bitbucket 4.3.2
  • Constructor Details

    • BitbucketServerAPIClient

      public BitbucketServerAPIClient(@NonNull String baseURL, @NonNull String owner, @CheckForNull String repositoryName, @CheckForNull BitbucketAuthenticator authenticator, boolean userCentric)
  • Method Details

    • isSupportedAuthenticator

      protected boolean isSupportedAuthenticator(@CheckForNull BitbucketAuthenticator authenticator)
      Description copied from class: AbstractBitbucketApi
      Implementation must validate if the configured authenticator is supported by this client implementation.
      Specified by:
      isSupportedAuthenticator in class AbstractBitbucketApi
    • 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.

      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:
      getOwner in interface BitbucketApi
      Returns:
      the ~user or project
    • getRepositoryName

      @CheckForNull public String getRepositoryName()
      Returns the repository name.
      Specified by:
      getRepositoryName in interface BitbucketApi
      Returns:
      the repository name.
    • getPullRequests

      @NonNull public List<BitbucketServerPullRequest> getPullRequests() throws IOException
      Returns the pull requests in the repository.
      Specified by:
      getPullRequests in interface BitbucketApi
      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

      @NonNull public BitbucketPullRequest getPullRequestById(@NonNull Integer id) throws IOException
      Returns a specific pull request.
      Specified by:
      getPullRequestById in interface BitbucketApi
      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

      @NonNull public BitbucketRepository getRepository() throws IOException
      Returns the repository details.
      Specified by:
      getRepository in interface BitbucketApi
      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

      @NonNull public List<BitbucketMirrorServer> getMirrors() throws IOException
      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

      public void postCommitComment(@NonNull String hash, @NonNull String comment) throws IOException
      Post a comment to a given commit hash.
      Specified by:
      postCommitComment in interface BitbucketApi
      Parameters:
      hash - commit hash
      comment - string to post as comment
      Throws:
      IOException - if there was a network communications error.
    • postBuildStatus

      @Deprecated public void postBuildStatus(@NonNull BitbucketBuildStatus status) throws IOException
      Deprecated.
      Set the build status for the given commit hash.
      Specified by:
      postBuildStatus in interface BitbucketApi
      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:
      checkPathExists in interface BitbucketApi
      Parameters:
      branchOrHash - the branch name or commit hash
      path - the path to check for
      Returns:
      true if the path exists
      Throws:
      IOException - if there was a network communications error.
    • getDefaultBranch

      @CheckForNull public String getDefaultBranch() throws IOException
      Description copied from interface: BitbucketApi
      Gets the default branch in the repository.
      Specified by:
      getDefaultBranch in interface BitbucketApi
      Returns:
      the default branch in the repository or null if no default branch set
      Throws:
      IOException - if there was a network communications error.
    • getTag

      public BitbucketBranch getTag(@NonNull String tagName) throws IOException
      Returns a tag in the repository.
      Specified by:
      getTag in interface BitbucketApi
      Returns:
      a tag in the repository.
      Throws:
      IOException - if there was a network communications error.
    • getTags

      @NonNull public List<BitbucketBranch> getTags() throws IOException
      Returns the tags in the repository.
      Specified by:
      getTags in interface BitbucketApi
      Returns:
      the list of tags in the repository.
      Throws:
      IOException - if there was a network communications error.
    • getBranch

      public BitbucketBranch getBranch(@NonNull String branchName) throws IOException
      Returns a branch in the repository.
      Specified by:
      getBranch in interface BitbucketApi
      Returns:
      a branch in the repository.
      Throws:
      IOException - if there was a network communications error.
    • getBranches

      @NonNull public List<BitbucketBranch> getBranches() throws IOException
      Returns the branches in the repository.
      Specified by:
      getBranches in interface BitbucketApi
      Returns:
      the list of branches in the repository.
      Throws:
      IOException - if there was a network communications error.
    • resolveCommit

      @NonNull public BitbucketCommit resolveCommit(@NonNull String hash) throws IOException
      Resolve the commit object given its hash.
      Specified by:
      resolveCommit in interface BitbucketApi
      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

      @NonNull public String resolveSourceFullHash(@NonNull BitbucketPullRequest pull)
      Resolve the head commit hash of the pull request source repository branch.
      Specified by:
      resolveSourceFullHash in interface BitbucketApi
      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: BitbucketApi
      Resolve the head commit object of the pull request source repository branch.
      Specified by:
      resolveCommit in interface BitbucketApi
      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

      public BitbucketTeam getTeam() throws IOException
      There is no such Team concept in Bitbucket Data Center but Project.
      Specified by:
      getTeam in interface BitbucketApi
      Returns:
      the team profile of the current owner, or null if BitbucketApi.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 IOException
      Deprecated, for removal: This API element is subject to removal in a future version.
      Returns the team Avatar of the current owner or null if the current owner is not a team.
      Specified by:
      getTeamAvatar in interface BitbucketApi
      Returns:
      the team profile of the current owner, or null if BitbucketApi.getOwner() is not a team ID.
      Throws:
      IOException - if there was a network communications error.
    • getAvatar

      public jenkins.scm.impl.avatars.AvatarImage getAvatar(@NonNull String url) throws IOException
      Returns an Avatar image from the given URL.

      The URL link could come from repository, project, workspace or user links.

      Specified by:
      getAvatar in interface BitbucketApi
      Returns:
      the resource image.
      Throws:
      IOException - if there was a network communications error.
    • getRepositories

      @NonNull @Deprecated public List<BitbucketServerRepository> getRepositories(@CheckForNull UserRoleInRepository role) throws IOException
      Deprecated.
      The role parameter is ignored for Bitbucket Server.
      Specified by:
      getRepositories in interface BitbucketApi
      Parameters:
      role - Filter repositories by the owner having this role in. See UserRoleInRepository 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.
    • getRepositories

      @NonNull public List<BitbucketServerRepository> getRepositories(@CheckForNull UserRoleInRepository role, @Nullable String filterName, @Nullable Integer page) throws IOException
      Description copied from interface: BitbucketApi
      Returns repositories applying the given filters. The compatibility implementation filters and pages the deprecated method's results locally.
      Specified by:
      getRepositories in interface BitbucketApi
      Parameters:
      role - the owner's role, or null for a team
      filterName - optional repository name filter
      page - must be null to retrieve all pages, or greater than or equal to 1; 1 identifies the first page
      Returns:
      matching repositories
      Throws:
      IOException - if communication fails
    • getRepositories

      @NonNull public List<BitbucketServerRepository> getRepositories() throws IOException
      Returns all the repositories for the current owner (even if it's a regular user or a team).
      Specified by:
      getRepositories in interface BitbucketApi
      Returns:
      all repositories for the current BitbucketApi.getOwner()
      Throws:
      IOException - if there was a network communications error.
    • isPrivate

      public boolean isPrivate() throws IOException
      Description copied from interface: BitbucketApi
      Returns true if and only if the repository is private.
      Specified by:
      isPrivate in interface BitbucketApi
      Returns:
      true if 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:
      getConnectionManager in class AbstractBitbucketApi
    • getClient

      @NonNull protected org.apache.hc.client5.http.impl.classic.CloseableHttpClient getClient()
      Specified by:
      getClient in class AbstractBitbucketApi
    • getHost

      @NonNull protected org.apache.hc.core5.http.HttpHost getHost()
      Specified by:
      getHost in class AbstractBitbucketApi
    • getBaseURL

      @NonNull protected String getBaseURL()
      Specified by:
      getBaseURL in class AbstractBitbucketApi
    • getDirectoryContent

      public Iterable<jenkins.scm.api.SCMFile> getDirectoryContent(BitbucketSCMFile directory) throws IOException
      Description copied from interface: BitbucketApi
      Returns a list of all children file for the given folder.
      Specified by:
      getDirectoryContent in interface BitbucketApi
      Parameters:
      directory - to list
      Returns:
      an iterable of SCMFile children of the given folder.
      Throws:
      IOException - if there was a network communications error.
    • getFileContent

      public InputStream getFileContent(BitbucketSCMFile file) throws IOException
      Description copied from interface: BitbucketApi
      Return an input stream for the given file.
      Specified by:
      getFileContent in interface BitbucketApi
      Parameters:
      file - an instance of SCM file
      Returns:
      the stream of the given SCMFile
      Throws:
      IOException - if there was a network communications error.
    • getFile

      @NonNull public jenkins.scm.api.SCMFile getFile(@NonNull BitbucketSCMFile file) throws IOException
      Description copied from interface: BitbucketApi
      Return the metadata for the given file.
      Specified by:
      getFile in interface BitbucketApi
      Parameters:
      file - an instance of SCM file
      Returns:
      a SCMFile file 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: BitbucketApi
      Return a set of base informations between the two given commits.
      Specified by:
      getCommits in interface BitbucketApi
      Parameters:
      fromCommit - the commit or reference containing the changes we wish to preview or null to 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.