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
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
BitbucketApi(String apiUrl, com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials credentials)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract BbBranch
createBranch(String orgId, String repoSlug, Map<String,String> payload)
Create branch.protected static String
ensureTrailingSlash(String url)
abstract boolean
fileExists(String orgId, String repoSlug, String path, String branch)
Checks if a file exists in Bitbucket repo.abstract BbBranch
getBranch(String orgId, String repoSlug, String branch)
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
getOrg(String orgName)
GivesBbOrg
for given project/team name.abstract BbPage<BbOrg>
getOrgs(int pageNumber, int pageSize)
Gives collection of Bitbucket organizations (Project/Team).abstract BbRepo
getRepo(String orgId, String repoSlug)
GivesBbRepo
abstract BbPage<BbRepo>
getRepos(String orgId, int pageNumber, int pageSize)
Gives collection ofBbRepo
s.BbUser
getUser()
abstract BbUser
getUser(String userSlug)
Gives user for given userName.protected io.jenkins.blueocean.commons.ServiceException
handleException(Exception e)
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 Detail
-
apiUrl
protected final String apiUrl
-
userName
protected final String userName
-
request
protected final HttpRequest request
-
-
Constructor Detail
-
BitbucketApi
protected BitbucketApi(@NonNull String apiUrl, @NonNull com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials credentials)
-
-
Method Detail
-
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 numberpageSize
- number of items in a page- Returns:
- Collection of
BbOrg
s
-
getOrg
@NonNull public abstract BbOrg getOrg(@NonNull String orgName)
GivesBbOrg
for given project/team name.- Parameters:
orgName
- Bitbucket project/team keyBbOrg.getKey()
- Returns:
BbOrg
instance
-
getRepo
@NonNull public abstract BbRepo getRepo(@NonNull String orgId, String repoSlug)
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
public abstract boolean isEmptyRepo(@NonNull String orgId, @NonNull String repoSlug)
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
protected io.jenkins.blueocean.commons.ServiceException handleException(Exception e)
Converts thrown exception during BB HTTP call in to JSON serializableServiceException
- Parameters:
e
- exception- Returns:
ServiceException
instance
-
-