Class BitbucketApi
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 Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedBitbucketApi(String apiUrl, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials credentials) -
Method Summary
Modifier and TypeMethodDescriptionabstract BbBranchCreate branch.protected static Stringabstract booleanfileExists(String orgId, String repoSlug, String path, String branch) Checks if a file exists in Bitbucket repo.abstract BbBranchGives Bitbucket branchabstract StringgetContent(String orgId, String repoSlug, String path, String commitId) Gives content of files in Bitbucket.abstract BbBranchgetDefaultBranch(String orgId, String repoSlug) Get default branch of a repo.abstract BbOrgGivesBbOrgfor given project/team name.getOrgs(int pageNumber, int pageSize) Gives collection of Bitbucket organizations (Project/Team).abstract BbRepoGivesBbRepoGives collection ofBbRepos.getUser()abstract BbUserGives user for given userName.protected io.jenkins.blueocean.commons.ServiceExceptionConverts thrown exception during BB HTTP call in to JSON serializableServiceExceptionabstract booleanisEmptyRepo(String orgId, String repoSlug) Checks if its empty/un-initializedabstract BbSaveContentResponsesaveContent(String orgId, String repoSlug, String path, String content, String commitMessage, String branch, String sourceBranch, String commitId) Saves file to Bitbucket.
-
Field Details
-
apiUrl
-
userName
-
request
-
-
Constructor Details
-
BitbucketApi
protected BitbucketApi(@NonNull String apiUrl, @NonNull com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials credentials)
-
-
Method Details
-
getUser
- Returns:
BbUser
-
getUser
Gives user for given userName.- Parameters:
userSlug- name of user,BbUser.getSlug()- Returns:
BbUser
-
getOrgs
Gives collection of Bitbucket organizations (Project/Team).- Parameters:
pageNumber- page numberpageSize- number of items in a page- Returns:
- Collection of
BbOrgs
-
getOrg
GivesBbOrgfor given project/team name.- Parameters:
orgName- Bitbucket project/team keyBbOrg.getKey()- Returns:
BbOrginstance
-
getRepo
GivesBbRepo- Parameters:
orgId- Bitbucket project/team keyBbOrg.getKey()repoSlug- repo slugBbRepo.getSlug()- Returns:
BbRepoinstance
-
getRepos
@NonNull public abstract BbPage<BbRepo> getRepos(@NonNull String orgId, int pageNumber, int pageSize) Gives collection ofBbRepos.- Parameters:
orgId- Bitbucket project/team keyBbOrg.getKey()pageNumber- page numberpageSize- 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 thenServiceException.NotFoundExceptionis thrown.- Parameters:
orgId- Bitbucket project/team keyBbOrg.getKey()repoSlug- Bitbucket repo sligBbRepo.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 keyBbOrg.getKey()repoSlug- Repo slugBbRepo.getSlug()path- destination path, e.g. "Jenkinsfile"content- file content to savecommitMessage- commit messagebranch- branch name. If null then implementation should save on default branchcommitId- if not provided, then file should be saved on tip of branch.- Returns:
BbSaveContentResponseon 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 keyBbOrg.getKey()repoSlug- repo slugBbRepo.getSlug()path- path of file, e.g. "Jenkinsfile"branch- Bitbucket branchBbBranch.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 keyBbOrg.getKey()repoSlug- Repo slugBbRepo.getSlug()branch- branch nameBbBranch.getDisplayId()- Returns:
BbBranchinstance. 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 keyBbOrg.getKey()repoSlug- repo slugBbRepo.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 keyBbOrg.getKey()repoSlug- Repo slugBbRepo.getSlug()- Returns:
- Default branch. null if it's empty repo or if the scm doesn't support default branch concept.
-
isEmptyRepo
Checks if its empty/un-initialized- Parameters:
orgId- Bitbucket project/team keyBbOrg.getKey()repoSlug- Repo slugBbRepo.getSlug()- Returns:
- true if this is empty or un-initialized repo
-
handleException
Converts thrown exception during BB HTTP call in to JSON serializableServiceException- Parameters:
e- exception- Returns:
ServiceExceptioninstance
-
ensureTrailingSlash
-