@@ -25,30 +25,20 @@ In Maven:
25
25
</dependency >
26
26
```
27
27
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
-
36
28
## Authenticating
37
29
38
30
### Simple access token
39
31
40
32
``` 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" );
44
34
```
45
35
46
36
### Private key
47
37
48
38
To authenticate as a GitHub App, you must provide a private key and the App ID, together with the API URL.
49
39
50
40
``` java
51
- final GitHubClient github =
41
+ final GitHubClient githubClient =
52
42
GitHubClient . create(
53
43
URI . create(" https://api.github.com/" ),
54
44
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
60
50
from GitHub.
61
51
62
52
``` 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 );
66
54
```
67
55
68
56
It 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
75
63
the ` GET /repos/:owner/:repo/commits ` API call, under the ` repos ` API. Therefore, the ` getCommit ` method lives in the RepositoryClient.
76
64
77
65
``` 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() );
80
68
```
81
69
82
70
Some APIs, such as Checks API are nested in the Repository API. Endpoints such as ` POST /repos/:owner/:repo/check-runs ` live in the ChecksClient:
83
71
84
72
``` 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()));
95
79
```
96
80
97
81
## Contributing
0 commit comments