Skip to content

Commit

Permalink
Adapt GitHubClient to the new API versioning (closes #113)
Browse files Browse the repository at this point in the history
  • Loading branch information
marcwrobel committed Dec 30, 2022
1 parent dbfafcb commit 101c86a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Changed

- Filter out past conferences in the _Conférences_ section (#109).
- Adapt GitHubClient to the new API versioning (#113).

### Fixed

Expand Down
22 changes: 7 additions & 15 deletions src/main/java/com/lescastcodeurs/bot/github/GitHubClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
@ApplicationScoped
public class GitHubClient {

private static final String API_VERSION = "2022-11-28";
private static final String API_MEDIA_TYPE = "application/vnd.github+json";

private static final String GITHUB_URL = "https://github.com";
private static final String GITHUB_API_URL = "https://api.github.com";

Expand Down Expand Up @@ -69,8 +72,9 @@ public String createOrUpdateFile(String repository, String filename, String cont

send(
HttpRequest.newBuilder(URI.create(gitHubApiUrl(repository, filename)))
.header("Accept", "application/vnd.github.v3+json")
.header("Accept", API_MEDIA_TYPE)
.header("Authorization", "token " + token)
.header("X-GitHub-Api-Version", API_VERSION)
.PUT(HttpRequest.BodyPublishers.ofString(body))
.build(),
200,
Expand All @@ -79,27 +83,15 @@ public String createOrUpdateFile(String repository, String filename, String cont
return gitHubUrl(repository, filename);
}

public String getContent(String repository, String filename) throws InterruptedException {
HttpResponse<String> response =
send(
HttpRequest.newBuilder(URI.create(gitHubApiUrl(repository, filename)))
.header("Accept", "application/vnd.github.v3.raw")
.header("Authorization", "token " + token)
.GET()
.build(),
200);

return response.body();
}

private Optional<String> getSha(String repository, String filename) throws InterruptedException {
String sha = null;

HttpResponse<String> response =
send(
HttpRequest.newBuilder(URI.create(gitHubApiUrl(repository, filename)))
.header("Accept", "application/vnd.github.v3+json")
.header("Accept", API_MEDIA_TYPE)
.header("Authorization", "token " + token)
.header("X-GitHub-Api-Version", API_VERSION)
.GET()
.build(),
200,
Expand Down

0 comments on commit 101c86a

Please sign in to comment.