Class BitbucketServerApiClient
java.lang.Object
io.jenkins.plugins.explain_error.autofix.scm.BitbucketServerApiClient
- All Implemented Interfaces:
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidCommits multiple files to a branch on Bitbucket Server.voidcreateBranch(String branchName, String fromBranch) Creates a new branch from the given base branch.createPullRequest(String title, String body, String headBranch, String baseBranch, boolean draft) Creates a pull request and returns the created PR.voiddeleteBranch(String branchName) Deletes a branch (for cleanup/rollback).Returns the default branch name (e.g., "main", "master").getFileContent(String filePath, String branch) Returns the current file content as a UTF-8 string, or null if the file does not exist.voidValidates that the token has write access to the repository.
-
Constructor Details
-
BitbucketServerApiClient
-
-
Method Details
-
getDefaultBranch
Description copied from interface:ScmApiClientReturns the default branch name (e.g., "main", "master").- Specified by:
getDefaultBranchin interfaceScmApiClient- Returns:
- the default branch name
- Throws:
IOException- if the API call fails
-
validateWriteAccess
Description copied from interface:ScmApiClientValidates that the token has write access to the repository.- Specified by:
validateWriteAccessin interfaceScmApiClient- Throws:
IOException- with a clear message if the token does not have push/write access
-
createBranch
Description copied from interface:ScmApiClientCreates a new branch from the given base branch.- Specified by:
createBranchin interfaceScmApiClient- Parameters:
branchName- the name of the new branchfromBranch- the branch to create from- Throws:
IOException- if the API call fails
-
getFileContent
Description copied from interface:ScmApiClientReturns the current file content as a UTF-8 string, or null if the file does not exist.- Specified by:
getFileContentin interfaceScmApiClient- Parameters:
filePath- the file path relative to repository rootbranch- 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 IOExceptionCommits 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
sourceCommitIdto preserve history and detect concurrent edits.- Specified by:
commitFilesin interfaceScmApiClient- Parameters:
branchName- the branch to commit tocommitMessage- the commit messagefileContents- 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:ScmApiClientCreates a pull request and returns the created PR.- Specified by:
createPullRequestin interfaceScmApiClient- Parameters:
title- the pull request titlebody- the pull request description bodyheadBranch- the source branchbaseBranch- the target branchdraft- whether to create as a draft PR- Returns:
- the created PullRequest
- Throws:
IOException- if the API call fails
-
deleteBranch
Description copied from interface:ScmApiClientDeletes a branch (for cleanup/rollback).- Specified by:
deleteBranchin interfaceScmApiClient- Parameters:
branchName- the branch to delete- Throws:
IOException- if the API call fails
-