Class BitbucketServerApiClient

java.lang.Object
io.jenkins.plugins.explain_error.autofix.scm.BitbucketServerApiClient
All Implemented Interfaces:
ScmApiClient

public class BitbucketServerApiClient extends Object implements ScmApiClient
SCM API client for Bitbucket Server (Data Center) REST API 1.0.

Authenticates with an HTTP access token (Bearer token) which is available since Bitbucket Server 5.5. For older instances, basic-auth credentials are also accepted when the token is in username:password format.

Base URL format: https://bitbucket.company.com/rest/api/1.0
Repository path: /projects/{PROJECT}/repos/{repo}

  • Constructor Details

    • BitbucketServerApiClient

      public BitbucketServerApiClient(ScmRepo repo)
  • Method Details

    • getDefaultBranch

      public String getDefaultBranch() throws IOException
      Description copied from interface: ScmApiClient
      Returns the default branch name (e.g., "main", "master").
      Specified by:
      getDefaultBranch in interface ScmApiClient
      Returns:
      the default branch name
      Throws:
      IOException - if the API call fails
    • validateWriteAccess

      public void validateWriteAccess() throws IOException
      Description copied from interface: ScmApiClient
      Validates that the token has write access to the repository.
      Specified by:
      validateWriteAccess in interface ScmApiClient
      Throws:
      IOException - with a clear message if the token does not have push/write access
    • createBranch

      public void createBranch(String branchName, String fromBranch) throws IOException
      Description copied from interface: ScmApiClient
      Creates a new branch from the given base branch.
      Specified by:
      createBranch in interface ScmApiClient
      Parameters:
      branchName - the name of the new branch
      fromBranch - the branch to create from
      Throws:
      IOException - if the API call fails
    • getFileContent

      public String getFileContent(String filePath, String branch) throws IOException
      Description copied from interface: ScmApiClient
      Returns the current file content as a UTF-8 string, or null if the file does not exist.
      Specified by:
      getFileContent in interface ScmApiClient
      Parameters:
      filePath - the file path relative to repository root
      branch - the branch to read from
      Returns:
      file content as a string, or null if not found
      Throws:
      IOException - if the API call fails for a reason other than 404
    • commitFiles

      public void commitFiles(String branchName, String commitMessage, Map<String,String> fileContents) throws IOException
      Commits multiple files to a branch on Bitbucket Server.

      Bitbucket Server does not have an atomic multi-file commit REST API, so files are committed sequentially. Each commit uses the previous commit's ID as sourceCommitId to preserve history and detect concurrent edits.

      Specified by:
      commitFiles in interface ScmApiClient
      Parameters:
      branchName - the branch to commit to
      commitMessage - the commit message
      fileContents - map of filePath to new complete file content (not diffs)
      Throws:
      IOException - if the API call fails
    • createPullRequest

      public PullRequest createPullRequest(String title, String body, String headBranch, String baseBranch, boolean draft) throws IOException
      Description copied from interface: ScmApiClient
      Creates a pull request and returns the created PR.
      Specified by:
      createPullRequest in interface ScmApiClient
      Parameters:
      title - the pull request title
      body - the pull request description body
      headBranch - the source branch
      baseBranch - the target branch
      draft - whether to create as a draft PR
      Returns:
      the created PullRequest
      Throws:
      IOException - if the API call fails
    • deleteBranch

      public void deleteBranch(String branchName) throws IOException
      Description copied from interface: ScmApiClient
      Deletes a branch (for cleanup/rollback).
      Specified by:
      deleteBranch in interface ScmApiClient
      Parameters:
      branchName - the branch to delete
      Throws:
      IOException - if the API call fails