1- < img alt = " logo " src = " https://www.jcabi.com/logo-square.svg " width = " 64px " height = " 64px " />
1+ # GitHub API Object-Oriented Java Client
22
33[ ![ EO principles respected here] ( https://www.elegantobjects.org/badge.svg )] ( https://www.elegantobjects.org )
44[ ![ DevOps By Rultor.com] ( https://www.rultor.com/b/jcabi/jcabi-github )] ( https://www.rultor.com/p/jcabi/jcabi-github )
1212[ ![ Hits-of-Code] ( https://hitsofcode.com/github/jcabi/jcabi-github )] ( https://hitsofcode.com/view/github/jcabi/jcabi-github )
1313[ ![ License] ( https://img.shields.io/badge/license-MIT-green.svg )] ( https://github.com/jcabi/jcabi-github/blob/master/LICENSE.txt )
1414
15- This is a Java adapter to the [ GitHub RESTful API] ( https://developer.github.com/v3/ ) .
16- There are a few other similar implementations on the market, but jcabi-github has a very strong
17- focus on object-oriented principles of programming. On top of that,
18- we have a unique implemenation of GitHub server-side functionality,
15+ This is a Java adapter to the [ GitHub RESTful API] .
16+ There are a few other similar implementations on the market,
17+ but jcabi-github has a very strong focus on
18+ object-oriented principles of programming. On top of that,
19+ we have a unique implementation of GitHub server-side functionality,
1920which you can use in your unit tests, eliminating the necessity to connect
2021to GitHub during unit/integration testing.
2122Please, read the blog post
22- [ _ Object-Oriented Github API_ ] ( https://www.yegor256.com/2014/05/14/object-oriented-github-java-sdk.html )
23+ [ _ Object-Oriented GitHub API_ ] [ blog ]
2324by [ Yegor Bugayenko] ( https://www.yegor256.com ) , the creator of this library.
2425
2526Java 8 or higher is required.
@@ -29,69 +30,73 @@ More details are here: [github.jcabi.com](https://github.jcabi.com/).
2930You may also get help in this [ Telegram chat] ( https://t.me/elegantobjects ) .
3031
3132The set of classes in the
32- [ ` com.jcabi.github ` ] ( https://static.javadoc.io/com.jcabi/jcabi-github/1.0/com/jcabi/github/ package-frame.html )
33+ [ ` com.jcabi.github ` ] [ package ]
3334package is the object-oriented API. Use it like this:
3435
35- ## Work with Github's API
36-
37- By default, the library works with Github's API (https://api.github.com )
36+ By default, the library works with [ GitHub RESTful API] :
3837
3938``` java
4039import com.jcabi.github.* ;
4140public class Main {
4241 public static void main (String [] args ) throws IOException {
43- Github github = new RtGithub (" .. your OAuth token .." );
42+ GitHub github = new RtGitHub (" .. your OAuth token .." );
4443 Repo repo = github. repos(). get(
4544 new Coordinates .Simple (" octocat/Hello-World" )
4645 );
47- Issue issue = repo. issues(). create(" Test title" , " Test description" );
46+ final Issue issue = repo. issues(). create(" Test title" , " Test description" );
4847 issue. comments(). post(" My first comment!" );
4948 }
5049}
5150```
5251
53- ## Work with Github Enterprise or other
54-
55- If you want to work with Github's API through another domain, you can use the URI-constructors
56- of class `` RtGithub `` . For instance, if you have your own instance of Github deployed under the
57- domain `` https://github.mydomain.com ` ` , do the following:
52+ If you want to work with GitHub's API through another domain,
53+ you can use the URI-constructors
54+ of class ` RtGitHub ` . For instance, if you have your own instance
55+ of GitHub deployed under the
56+ domain ` https://github.mydomain.com ` , do the following:
5857
5958``` java
60- final Github github = new RtGithub (URI . create(" https://github.mydomain.com" ));
59+ final GitHub github = new RtGitHub (URI . create(" https://github.mydomain.com" ));
6160
6261// OR
6362
64- final Github github = new RtGithub (
63+ final GitHub github = new RtGitHub (
6564 " <<oauth2_token>>" ,
6665 URI . create(" https://github.mydomain.com" )
6766);
6867
6968// OR
7069
71- final Github github = new RtGithub (
70+ final GitHub github = new RtGitHub (
7271 " username" , " password" ,
7372 URI . create(" https://github.mydomain.com" )
7473);
7574```
7675
77- ** DO NOT** change or mask your URIs! Using Github under a different domain is fine but do not
78- change the URI ** paths** . Changing the requests' paths is not possible since the whole architecture
79- of this library relies on Github's URI paths.
76+ ** DO NOT** change or mask your URIs!
77+ Using GitHub under a different domain is fine but do not
78+ change the URI ** paths** . Changing the requests'
79+ paths is not possible since the whole architecture
80+ of this library relies on GitHub's URI paths.
8081
81- For more complex configurations, you can instantiate `` RtGithub `` with your own custom `` Request `` , by using the [ RtGithub(Request)] ( https://github.com/jcabi/jcabi-github/blob/master/src/main/java/com/jcabi/github/RtGithub.java#L147 ) constructor.
82- Be sure to configure the `` Request `` properly. See how the [ default Request] ( https://github.com/jcabi/jcabi-github/blob/master/src/main/java/com/jcabi/github/RtGithub.java#L82 ) is created -- you basically have to do the same thing.
82+ For more complex configurations, you can instantiate
83+ ` RtGitHub ` with your own custom ` Request ` ,
84+ by using the [ RtGitHub(Request)] [ RtGitHub ] constructor.
85+ Be sure to configure the ` Request ` properly.
86+ See how the [ default Request] [ Request ]
87+ is created -- you basically have to do the same thing.
8388
8489## Mock Implementation Of The API
8590
86- We also provide [ ` MkGithub ` ] ( https://static.javadoc.io/com.jcabi/jcabi-github/1.0/com/jcabi/github/mock/MkGithub.html ) ,
91+ We also provide [ MkGitHub ] ,
8792a mock version of the GitHub server, which
8893you can use in your unit tests, for example:
8994
9095``` java
9196import com.jcabi.github.* ;
9297public class FooTest {
93- public void submitsCommentToGithubIssue () {
94- final Repo repo = new MkGithub (). repos(). create(
98+ public void submitsCommentToGitHubIssue () {
99+ final Repo repo = new MkGitHub (). repos(). create(
95100 Json . createObjectBuilder(). add(" name" , " test" ). build()
96101 );
97102 final Issue issue = repo. issues(). create(" how are you?" , " " );
@@ -112,45 +117,61 @@ the `master` branch, if they look correct.
112117
113118Please run Maven (3.1 or higher!) build before submitting a pull request:
114119
115- ```
116- $ mvn clean install -Pqulice
120+ ``` bash
121+ mvn clean install -Pqulice
117122```
118123
119124There are many integration tests that check our classes against
120- live Github accounts. In order to run them, you should create
121- a new Github OAuth access tokens
122- ([ how?] ( https://help.github.com/articles/creating-an-access-token-for-command-line-use ) ),
125+ live GitHub accounts. In order to run them, you should create
126+ a new GitHub OAuth access tokens
127+ ([ how?] [ pat ] ),
123128and provide them in command line, like this:
124129
125- ```
126- $ mvn clean install -Dit.test=RtGistITCase -Dfailsafe.github.key=<token> -Dfailsafe.github.key.second=<second-token> -Dfailsafe.github.repo=<repo>
130+ ``` bash
131+ mvn clean install -Dit.test=RtGistITCase -Dfailsafe.github.key=< token> \
132+ -Dfailsafe.github.key.second=< second-token> -Dfailsafe.github.repo=< repo>
127133```
128134
129- Replace ` <token> ` and ` <second-token> ` with the OAuth access tokens of two different Github
130- accounts. This test case will try to fork a gist from first account into second. Replace
131- ` <repo> ` with the name of repository you create in your first account (for test purposes
132- only), for example ` yegor256/test ` . OAuth access tokens should have permissions in their
133- respective repos to all scopes needed by the integration test suite you want to run
135+ Replace ` <token> ` and ` <second-token> ` with the OAuth access tokens
136+ of two different GitHub
137+ accounts. This test case will try to fork a gist from first account
138+ into second. Replace
139+ ` <repo> ` with the name of repository you create in your first account
140+ (for test purposes only), for example ` yegor256/test ` .
141+ OAuth access tokens should have permissions in their
142+ respective repos to all scopes needed by the integration test
143+ suite you want to run
134144(including ` delete_repo ` , which is not set by default!).
135145
136- Please note that different integration tests may need keys with permissions to different
137- [ scopes] ( https://developer.github.com/v3/oauth/#scopes ) . To run all integration tests, the key should
146+ Please note that different integration tests may need keys with
147+ permissions to different
148+ [ scopes] ( https://developer.github.com/v3/oauth/#scopes ) .
149+ To run all integration tests, the key should
138150have the following OAuth scopes:
139151
140- - ` read:org `
141- - ` repo `
142- - ` delete_repo `
143- - ` admin:public_key `
144- - ` gist `
145- - ` admin:repo_hook `
146- - ` user `
147- - ` user:email `
148-
149- ` RtForksITCase ` requires additional parameter ` -Dfailsafe.github.organization=<organization> `
152+ - ` read:org `
153+ - ` repo `
154+ - ` delete_repo `
155+ - ` admin:public_key `
156+ - ` gist `
157+ - ` admin:repo_hook `
158+ - ` user `
159+ - ` user:email `
160+
161+ ` RtForksITCase ` requires additional
162+ parameter ` -Dfailsafe.github.organization=<organization> `
150163where ` <organization> ` is an organization name to fork test github repository.
151164
152165In order to run static analysis checks only use this:
153166
167+ ``` bash
168+ mvn clean install -DskipTests -Dinvoker.skip=true -Pqulice
154169```
155- $ mvn clean install -DskipTests -Dinvoker.skip=true -Pqulice
156- ```
170+
171+ [ GitHub RESTful API ] : https://developer.github.com/v3/
172+ [ blog ] : https://www.yegor256.com/2014/05/14/object-oriented-github-java-sdk.html
173+ [ pat ] : https://help.github.com/articles/creating-an-access-token-for-command-line-use
174+ [ MkGitHub ] : https://static.javadoc.io/com.jcabi/jcabi-github/1.0/com/jcabi/github/mock/MkGitHub.html
175+ [ RtGitHub ] : https://github.com/jcabi/jcabi-github/blob/master/src/main/java/com/jcabi/github/RtGitHub.java#L147
176+ [ package ] : https://static.javadoc.io/com.jcabi/jcabi-github/1.0/com/jcabi/github/package-frame.html
177+ [ Request ] : https://github.com/jcabi/jcabi-github/blob/master/src/main/java/com/jcabi/github/RtGitHub.java#L82
0 commit comments