use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.model.BbCloudTeam in project blueocean-plugin by jenkinsci.
the class BitbucketCloudApi method getOrg.
@Nonnull
@Override
public BbOrg getOrg(@Nonnull String orgName) {
try {
BbUser user = getUser();
// If user org, get user and return BbCloudTeam model
if (orgName.equalsIgnoreCase(user.getSlug())) {
return new BbCloudTeam(user.getSlug(), user.getDisplayName(), user.getAvatar());
}
InputStream inputStream = request.get(String.format("%s/%s", baseUrl + "teams", orgName)).getContent();
return om.readValue(inputStream, BbCloudTeam.class);
} catch (IOException e) {
throw handleException(e);
}
}
use of io.jenkins.blueocean.blueocean_bitbucket_pipeline.cloud.model.BbCloudTeam in project blueocean-plugin by jenkinsci.
the class BitbucketCloudApi method getOrgs.
@Nonnull
@Override
public BbPage<BbOrg> getOrgs(int pageNumber, int pageSize) {
try {
/*
* Bitbucket teams API work with three roles: admin, contributor, member
*
* We default to 'contributor' role, because we only want to only list teams that have at least one repo
* where user has WRITE access.
*
* see: https://developer.atlassian.com/bitbucket/api/2/reference/resource/teams
*/
if (pageNumber <= 0) {
pageNumber = 1;
}
if (pageSize <= 0) {
pageSize = PagedResponse.DEFAULT_LIMIT;
}
InputStream inputStream = request.get(String.format("%s&page=%s&pagelen=%s", baseUrl + "teams/?role=contributor", pageNumber, pageSize)).getContent();
BbPage<BbOrg> page = om.readValue(inputStream, new TypeReference<BbCloudPage<BbCloudTeam>>() {
});
if (pageNumber == 1) {
// add user org as the first org on first page
BbUser user = getUser();
if (page instanceof BbCloudPage) {
List<BbOrg> teams = new ArrayList<>();
teams.add(new BbCloudTeam(user.getSlug(), user.getDisplayName(), user.getAvatar()));
int newSize = page.getSize() + 1;
int newPageLength = page.getLimit();
if (page.getSize() > page.getLimit()) {
newPageLength++;
}
teams.addAll(page.getValues());
return new BbCloudPage<>(newPageLength, pageNumber, newSize, ((BbCloudPage) page).getNext(), teams);
}
}
return page;
} catch (IOException e) {
throw handleException(e);
}
}
Aggregations