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
-
Constructor Summary
ModifierConstructorDescriptionprotected
BitbucketApi
(String apiUrl, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials credentials) -
Method Summary
Modifier and TypeMethodDescriptionabstract BbBranch
Create branch.protected static String
abstract boolean
fileExists
(String orgId, String repoSlug, String path, String branch) Checks if a file exists in Bitbucket repo.abstract BbBranch
Gives Bitbucket branchabstract String
getContent
(String orgId, String repoSlug, String path, String commitId) Gives content of files in Bitbucket.abstract BbBranch
getDefaultBranch
(String orgId, String repoSlug) Get default branch of a repo.abstract BbOrg
GivesBbOrg
for given project/team name.getOrgs
(int pageNumber, int pageSize) Gives collection of Bitbucket organizations (Project/Team).abstract BbRepo
GivesBbRepo
Gives collection ofBbRepo
s.getUser()
abstract BbUser
Gives user for given userName.protected io.jenkins.blueocean.commons.ServiceException
Converts thrown exception during BB HTTP call in to JSON serializableServiceException
abstract boolean
isEmptyRepo
(String orgId, String repoSlug) Checks if its empty/un-initializedabstract BbSaveContentResponse
saveContent
(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
BbOrg
s
-
getOrg
GivesBbOrg
for given project/team name.- Parameters:
orgName
- Bitbucket project/team keyBbOrg.getKey()
- Returns:
BbOrg
instance
-
getRepo
GivesBbRepo
- Parameters:
orgId
- Bitbucket project/team keyBbOrg.getKey()
repoSlug
- repo slugBbRepo.getSlug()
- Returns:
BbRepo
instance
-
getRepos
@NonNull public abstract BbPage<BbRepo> getRepos(@NonNull String orgId, int pageNumber, int pageSize) Gives collection ofBbRepo
s.- 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.NotFoundException
is 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:
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 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:
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 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:
ServiceException
instance
-
ensureTrailingSlash
-