@@ -25,30 +25,20 @@ In Maven:
2525</dependency >
2626```
2727
28- Start talking to GitHub API.
29-
30- ``` java
31- final GitHubClient github = GitHubClient . create(URI . create(" https://api.github.com/" ));
32- final IssueApi issueClient = github. createRepositoryClient(" my-org" , " my-repo" ). createIssueClient();
33- issueClient. listComments(ISSUE_ID ). get(). forEach(comment - > log. info(comment. body()));
34- ```
35-
3628## Authenticating
3729
3830### Simple access token
3931
4032``` java
41- final GitHubClient github = GitHubClient . create(URI . create(" https://api.github.com/" ), " my-access-token" );
42- // Do the requests
43- github. createRepositoryClient(" my-org" , " my-repo" ). getCommit(" sha" );
33+ final GitHubClient githubClient = GitHubClient . create(URI . create(" https://api.github.com/" ), " my-access-token" );
4434```
4535
4636### Private key
4737
4838To authenticate as a GitHub App, you must provide a private key and the App ID, together with the API URL.
4939
5040``` java
51- final GitHubClient github =
41+ final GitHubClient githubClient =
5242 GitHubClient . create(
5343 URI . create(" https://api.github.com/" ),
5444 new File (" /path-to-the/private-key.pem" ),
@@ -60,9 +50,7 @@ The client will manage the generation of JWT tokens, as well as requesting and c
6050from GitHub.
6151
6252``` java
63- final GitHubClient scoped = GitHubClient . scopeForInstallationId(github, INSTALLATION_ID );
64- // Do the requests now using the scoped client.
65- scoped. createRepositoryClient(" my-org" , " my-repo" ). getCommit(" sha" );
53+ final GitHubClient scopedClient = GitHubClient . scopeForInstallationId(githubClient, INSTALLATION_ID );
6654```
6755
6856It is also possible to provide the installation to the root client.
@@ -75,23 +63,19 @@ This library attempts to mirror the structure of GitHub API endpoints. As an exa
7563the ` GET /repos/:owner/:repo/commits ` API call, under the ` repos ` API. Therefore, the ` getCommit ` method lives in the RepositoryClient.
7664
7765``` java
78- final GitHubClient github = GitHubClient . create( URI . create( " https://api.github.com/ " ) , " my-access-token " );
79- github . createRepositoryClient( " my-org " , " my-repo " ) . getCommit(" sha" );
66+ final RepositoryClient repositoryClient = githubClient . createRepositoryClient( " my-org " , " my-repo " );
67+ log . info(repositoryClient . getCommit(" sha" ) . get() . htmlUrl() );
8068```
8169
8270Some APIs, such as Checks API are nested in the Repository API. Endpoints such as ` POST /repos/:owner/:repo/check-runs ` live in the ChecksClient:
8371
8472``` java
85- final GitHubClient github =
86- GitHubClient . create(
87- URI . create(" https://api.github.com/" ),
88- new File (" /path-to-the/private-key.der" ),
89- APP_ID );
90- // Checks API need to be used by GitHub Apps
91- GitHubClient . scopeForInstallationId(github, INSTALLATION_ID )
92- .createRepositoryClient(" my-org" , " my-repo" )
93- .createChecksApiClient()
94- .createCheckRun(CHECK_RUN_REQUEST );
73+ final ChecksClient checksClient = repositoryClient. createChecksApiClient();
74+ checksClient. createCheckRun(CHECK_RUN_REQUEST );
75+
76+ final IssueClient issueClient = repositoryClient. createIssueClient();
77+ issueClient. createComment(ISSUE_ID , " comment body" )
78+ .thenAccept(comment - > log. info(" created comment " + comment. htmlUrl()));
9579```
9680
9781## Contributing
0 commit comments