java.lang.Object
io.jenkins.blueocean.blueocean_bitbucket_pipeline.BitbucketApi
Direct Known Subclasses:
BitbucketCloudApi, BitbucketServerApi

@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public abstract class BitbucketApi extends Object
Bitbucket APIs needed to perform BlueOcean pipeline creation flow.
Author:
Vivek Pandey
  • Field Details

    • apiUrl

      protected final String apiUrl
    • userName

      protected final String userName
    • request

      protected final HttpRequest request
  • Constructor Details

    • BitbucketApi

      protected BitbucketApi(@NonNull String apiUrl, @NonNull com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials credentials)
  • Method Details

    • getUser

      @NonNull public BbUser getUser()
      Returns:
      BbUser
    • getUser

      @NonNull public abstract BbUser getUser(@NonNull String userSlug)
      Gives user for given userName.
      Parameters:
      userSlug - name of user, BbUser.getSlug()
      Returns:
      BbUser
    • getOrgs

      @NonNull public abstract BbPage<BbOrg> getOrgs(int pageNumber, int pageSize)
      Gives collection of Bitbucket organizations (Project/Team).
      Parameters:
      pageNumber - page number
      pageSize - number of items in a page
      Returns:
      Collection of BbOrgs
    • getOrg

      @NonNull public abstract BbOrg getOrg(@NonNull String orgName)
      Gives BbOrg for given project/team name.
      Parameters:
      orgName - Bitbucket project/team key BbOrg.getKey()
      Returns:
      BbOrg instance
    • getRepo

      @NonNull public abstract BbRepo getRepo(@NonNull String orgId, String repoSlug)
      Gives BbRepo
      Parameters:
      orgId - Bitbucket project/team key BbOrg.getKey()
      repoSlug - repo slug BbRepo.getSlug()
      Returns:
      BbRepo instance
    • getRepos

      @NonNull public abstract BbPage<BbRepo> getRepos(@NonNull String orgId, int pageNumber, int pageSize)
      Gives collection of BbRepos.
      Parameters:
      orgId - Bitbucket project/team key BbOrg.getKey()
      pageNumber - page number
      pageSize - page size
      Returns:
    • getContent

      @NonNull public abstract String getContent(@NonNull String orgId, @NonNull String repoSlug, @NonNull String path, @NonNull String commitId)
      Gives content of files in Bitbucket. If given path is not available then ServiceException.NotFoundException is thrown.
      Parameters:
      orgId - Bitbucket project/team key BbOrg.getKey()
      repoSlug - Bitbucket repo slig BbRepo.getSlug()
      path - path to file in bitbucket repo, e.g. "Jenkinsfile"
      commitId - commitId of branch, path will be served off it.
      Returns:
      content
    • saveContent

      @NonNull public abstract BbSaveContentResponse saveContent(@NonNull String orgId, @NonNull String repoSlug, @NonNull String path, @NonNull String content, @NonNull String commitMessage, @Nullable String branch, @Nullable String sourceBranch, @Nullable String commitId)
      Saves file to Bitbucket.
      Parameters:
      orgId - Bitbucket project/team key BbOrg.getKey()
      repoSlug - Repo slug BbRepo.getSlug()
      path - destination path, e.g. "Jenkinsfile"
      content - file content to save
      commitMessage - commit message
      branch - branch name. If null then implementation should save on default branch
      commitId - if not provided, then file should be saved on tip of branch.
      Returns:
      BbSaveContentResponse on successful save.
      Throws:
      io.jenkins.blueocean.commons.ServiceException.ConflictException - in case of conflict during save
    • fileExists

      public abstract boolean fileExists(@NonNull String orgId, @NonNull String repoSlug, @NonNull String path, @NonNull String branch)
      Checks if a file exists in Bitbucket repo.
      Parameters:
      orgId - Bitbucket project/team key BbOrg.getKey()
      repoSlug - repo slug BbRepo.getSlug()
      path - path of file, e.g. "Jenkinsfile"
      branch - Bitbucket branch BbBranch.getDisplayId()
      Returns:
      true if file exists
    • getBranch

      @CheckForNull public abstract BbBranch getBranch(@NonNull String orgId, @NonNull String repoSlug, @NonNull String branch)
      Gives Bitbucket branch
      Parameters:
      orgId - Bitbucket project/team key BbOrg.getKey()
      repoSlug - Repo slug BbRepo.getSlug()
      branch - branch name BbBranch.getDisplayId()
      Returns:
      BbBranch instance. Could be null if there is no such branch.
    • createBranch

      @NonNull public abstract BbBranch createBranch(@NonNull String orgId, @NonNull String repoSlug, Map<String,String> payload)
      Create branch.
      Parameters:
      orgId - Bitbucket project/team key BbOrg.getKey()
      repoSlug - repo slug BbRepo.getSlug()
      payload - branch payload
      Returns:
      Created branch
    • getDefaultBranch

      @CheckForNull public abstract BbBranch getDefaultBranch(@NonNull String orgId, @NonNull String repoSlug)
      Get default branch of a repo.
      Parameters:
      orgId - Bitbucket project/team key BbOrg.getKey()
      repoSlug - Repo slug BbRepo.getSlug()
      Returns:
      Default branch. null if it's empty repo or if the scm doesn't support default branch concept.
    • isEmptyRepo

      public abstract boolean isEmptyRepo(@NonNull String orgId, @NonNull String repoSlug)
      Checks if its empty/un-initialized
      Parameters:
      orgId - Bitbucket project/team key BbOrg.getKey()
      repoSlug - Repo slug BbRepo.getSlug()
      Returns:
      true if this is empty or un-initialized repo
    • handleException

      protected io.jenkins.blueocean.commons.ServiceException handleException(Exception e)
      Converts thrown exception during BB HTTP call in to JSON serializable ServiceException
      Parameters:
      e - exception
      Returns:
      ServiceException instance
    • ensureTrailingSlash

      protected static String ensureTrailingSlash(String url)