bitbucketcloud-api

Java library for interfacing with the bitbucket cloud api

License

License

GroupId

GroupId

com.chimerapps
ArtifactId

ArtifactId

bitbucketcloud-api
Last Version

Last Version

0.1.2
Release Date

Release Date

Type

Type

pom.sha512
Description

Description

bitbucketcloud-api
Java library for interfacing with the bitbucket cloud api
Project URL

Project URL

https://github.com/Chimerapps/bitbucketcloud-api
Source Code Management

Source Code Management

https://github.com/Chimerapps/bitbucketcloud-api

Download bitbucketcloud-api

Dependencies

runtime (5)

Group / Artifact Type Version
com.squareup.retrofit2 : retrofit jar 2.3.0
com.squareup.okhttp3 : okhttp jar 3.9.1
com.google.code.gson : gson jar 2.8.2
com.squareup.retrofit2 : converter-gson jar 2.3.0
org.jetbrains : annotations-java5 jar 15.0

Project Modules

There are no modules declared in this project.

Bitbucket Cloud API

Java Library to acces the Bitbucket Cloud API.
https://developer.atlassian.com/bitbucket/api/2/reference/resource/repositories

Supported API Calls

  • Get User
  • Get Repositories
  • Get Default Users
  • Create Pull Request

Authentication

Username

This is the name chosen when you created your account. (It can be found in the Bitbucket Settings under Account Settings)

App Token

This is a token you need to generate in your Bitbucket Settings. Go to App Passwords (under Acces Management). You can create a new App Password. This will be used instead of your 2 Step Verification.

settings

settings-config

The best option to save your Username and App Token is to save them in your System Environment (for Mac You can use EnvPane or just set them with commandline.)

Get User

Documentation

final Response<BitbucketUser> response = new Bitbucket(USERNAME, APP_TOKEN).getApi()
                             .getUser()
                             .execute();

Get Repositories

Documentation

final Response<PagedList<BitbucketRepository>> response = new Bitbucket(USERNAME, APP_TOKEN).getApi()
                            .getRepositories(user,PropertyCompare.eq("name", repoSlug))
                            .execute();

Get Default Users

Documentation

final Response<PagedList<BitbucketRepository>> response = new Bitbucket(USERNAME, APP_TOKEN).getApi()
                            .getDefaultReviewers(user, repoSlug)
                            .execute();

Create Pull Request

Documentation

Without reviewers:

final String title = "Title of your PR";
final String description = "Description of your PR";

final Destination source = new Destination("branch-name-you-want-to-merge");
final Destination destination = new Destination("branch-name-where-you-want-to-merge-to");

final PullRequest pullRequest = new PullRequest(title, description, source, destination, null);

final Response<PullRequest> response = mBitbucket.getApi()
                .postPullRequest(user, repoSlug, pullRequest)
                .execute();

With reviewers (your own username may not be included):

final Response<PagedList<DefaultReviewer>> responseDefaultReviewers = mBitbucket.getApi()
                .getDefaultReviewers(user, repoSlug)
                .execute();
                
final PagedList<DefaultReviewer> defaultReviewers = responseDefaultReviewers.body();

final List<DefaultReviewer> filteredList = defaultReviewers.getValues()
                .stream()
                .filter(r -> !r.getUsername().equals(USERNAME))
                .collect(Collectors.toList());

final String title = "Title of your PR";
final String description = "Description of your PR";

final Destination source = new Destination("branch-name-you-want-to-merge");
final Destination destination = new Destination("branch-name-where-you-want-to-merge-to");

final PullRequest pullRequest = new PullRequest(title, description, source, destination, filteredList);

final Response<PullRequest> response = mBitbucket.getApi()
                .postPullRequest(user, repoSlug, pullRequest)
                .execute();

With hardcoded reviewer:

final List<DefaultReviewer> reviewers = new ArrayList();
reviewers.add(new DefaultReviewer("username-of-the-reviewer"));

final String title = "Title of your PR";
final String description = "Description of your PR";

final Destination source = new Destination("branch-name-you-want-to-merge");
final Destination destination = new Destination("branch-name-where-you-want-to-merge-to");

final PullRequest pullRequest = new PullRequest(title, description, source, destination, reviewers);

final Response<PullRequest> response = mBitbucket.getApi()
                .postPullRequest(user, repoSlug, pullRequest)
                .execute();
com.chimerapps

Chimerapps

Versions

Version
0.1.2