• Stars
    star
    291
  • Rank 141,430 (Top 3 %)
  • Language
    Java
  • License
    Other
  • Created almost 11 years ago
  • Updated about 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Java Object-Oriented Wrapper of GitHub API, with a fake implementation of the entire GitHub API (for your tests)

logo

EO principles respected here DevOps By Rultor.com We recommend IntelliJ IDEA

mvn PDD status codecov Maven Central JavaDoc Hits-of-Code Lines of code License

This is a Java adapter to the GitHub RESTful API. There are a few other similar implementations on the market, but jcabi-github has a very strong focus on object-oriented principles of programming. On top of that, we have a unique implemenation of GitHub server-side functionality, which you can use in your unit tests, eliminating the necessity to connect to GitHub during unit/integration testing. Please, read the blog post Object-Oriented Github API by Yegor Bugayenko, the creator of this library.

Java 8 or higher is required.

More details are here: github.jcabi.com.

You may also get help in this Telegram chat.

The set of classes in the com.jcabi.github package is the object-oriented API. Use it like this:

Work with Github's API

By default, the library works with Github's API (https://api.github.com)

import com.jcabi.github.*;
public class Main {
  public static void main(String[] args) throws IOException {
    Github github = new RtGithub(".. your OAuth token ..");
    Repo repo = github.repos().get(
        new Coordinates.Simple("octocat/Hello-World")
    );
    Issue issue = repo.issues().create("Test title", "Test description");
    issue.comments().post("My first comment!");
  }
}

Work with Github Enterprise or other

If you want to work with Github's API through another domain, you can use the URI-constructors of class RtGithub. For instance, if you have your own instance of Github deployed under the domain https://github.mydomain.com, do the following:

final Github github = new RtGithub(URI.create("https://github.mydomain.com"));

//OR

final Github github = new RtGithub(
    "<<oauth2_token>>",
    URI.create("https://github.mydomain.com")
);

//OR

final Github github = new RtGithub(
    "username", "password",
    URI.create("https://github.mydomain.com")
);

DO NOT change or mask your URIs! Using Github under a different domain is fine but do not change the URI paths. Changing the requests' paths is not possible since the whole architecture of this library relies on Github's URI paths.

For more complex configurations, you can instantiate RtGithub with your own custom Request, by using the RtGithub(Request) constructor. Be sure to configure the Request properly. See how the default Request is created -- you basically have to do the same thing.

Mock Implementation Of The API

We also provide MkGithub, a mock version of the GitHub server, which you can use in your unit tests, for example:

import com.jcabi.github.*;
public class FooTest {
  public void submitsCommentToGithubIssue() {
    final Repo repo = new MkGithub().repos().create(
      Json.createObjectBuilder().add("name", "test").build()
    );
    final Issue issue = repo.issues().create("how are you?", "");
    new Foo(issue).doSomething(); // should post a message to the issue
    MasterAssert.assertThat(
      issue.comments().iterate(),
      Matchers.iterableWithSize(1)
    );
  }
}

How to contribute?

Fork the repository, make changes, submit a pull request. We promise to review your changes same day and apply to the master branch, if they look correct.

Please run Maven (3.1 or higher!) build before submitting a pull request:

$ mvn clean install -Pqulice

There are many integration tests that check our classes against live Github accounts. In order to run them, you should create a new Github OAuth access tokens (how?), and provide them in command line, like this:

$ mvn clean install -Dit.test=RtGistITCase -Dfailsafe.github.key=<token> -Dfailsafe.github.key.second=<second-token> -Dfailsafe.github.repo=<repo>

Replace <token> and <second-token> with the OAuth access tokens of two different Github accounts. This test case will try to fork a gist from first account into second. Replace <repo> with the name of repository you create in your first account (for test purposes only), for example yegor256/test. OAuth access tokens should have permissions in their respective repos to all scopes needed by the integration test suite you want to run (including delete_repo, which is not set by default!).

Please note that different integration tests may need keys with permissions to different scopes. To run all integration tests, the key should have the following OAuth scopes:

  • read:org
  • repo
  • delete_repo
  • admin:public_key
  • gist
  • admin:repo_hook
  • user
  • user:email

RtForksITCase requires additional parameter -Dfailsafe.github.organization=<organization> where <organization> is an organization name to fork test github repository.

In order to run static analysis checks only use this:

$ mvn clean install -DskipTests -Dinvoker.skip=true -Pqulice

More Repositories

1

jcabi-aspects

Collection of AspectJ Java Aspects to facilitate aspect-oriented programming patterns: logging, caching, validating, etc.
Java
506
star
2

jcabi-ssh

Java SSH client (an object-oriented wrapper around JSch)
Java
256
star
3

jcabi-http

Fluent Java HTTP client
Java
148
star
4

jcabi-jdbc

Fluent Object-Oriented Wrapper of JDBC
Java
101
star
5

jcabi-xml

Java XML Parsing, Transforming, Printing, and Validating
Java
95
star
6

jcabi

Elementary Java components, each in its own repository and its own Maven artifact
89
star
7

jcabi-aether

Wrapper of Sonatype Aether
Java
61
star
8

jcabi-manifests

Java library for convenient reading of MANIFEST.MF files available in classpath
Java
57
star
9

jcabi-log

Static Wrapper of SLF4J easing you from the necessity to create static LOGGER instances in each Java class
Java
55
star
10

jcabi-email

Object-Oriented Email Sending Java SDK
Java
52
star
11

jcabi-dynamo

Object Oriented Wrapper of AWS DynamoDB SDK
Java
47
star
12

jcabi-parent

A convenient parent Maven POM artifact, which we recommend using in all Maven projects
Java
42
star
13

jcabi-mysql-maven-plugin

MySQL Maven Plugin: starts MySQL server on pre-integration phase and shuts it down on post-integration phase
Java
34
star
14

jcabi-immutable

Immutable Collections
Java
30
star
15

jcabi-dynamodb-maven-plugin

DynamoDB Local Maven Plugin: starts and stops a local test server
Java
30
star
16

jcabi-maven-plugin

Supplementary maven plugin for AspectJ weaving and versioning of artifacts
Java
28
star
17

jcabi-s3

Object-Oriented Layer on Top of Amazon S3 SDK
Java
27
star
18

jcabi-w3c

W3C Validators in Java
Java
18
star
19

jcabi-urn

Java URN as in RFC 2141
Java
16
star
20

jcabi-maven-slf4j

SLF4J Binding for Apache Maven
Java
14
star
21

jcabi-matchers

A few convenient Hamcrest matchers, mostly for XPath vs XHTML and fields in JAXB
Java
13
star
22

jcabi-simpledb

Object-Oriented Java SDK for Amazon SimpleDB
Java
13
star
23

jcabi-beanstalk-maven-plugin

Maven Plugin for AWS Elastic Beanstalk
Java
11
star
24

jcabi-velocity

Wrapper of Apache Velocity
Java
11
star
25

jcabi-odesk

Object-Oriented oDesk Java SDK
Java
10
star
26

jcabi-ssl-maven-plugin

SSL Plugin for Apache Maven: it generates fake SSL certificates for the testing purposes of your Java web app
Java
10
star
27

jcabi-heroku-maven-plugin

Maven Plugin for Deploying to Heroku
Java
8
star
28

jcabi-maven-skin

Skin for Apache Maven
SCSS
8
star
29

jcabi-latex-maven-plugin

LaTeX Maven Plugin
Java
7
star
30

.github

Front page
2
star