From 101c86a5357c2bd7a50f760136547735b4748427 Mon Sep 17 00:00:00 2001
From: Marc Wrobel <marc.wrobel@gmail.com>
Date: Fri, 30 Dec 2022 12:21:45 +0100
Subject: [PATCH] Adapt GitHubClient to the new API versioning (closes #113)

---
 CHANGELOG.md                                  |  1 +
 .../bot/github/GitHubClient.java              | 22 ++++++-------------
 2 files changed, 8 insertions(+), 15 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index a8e9204..6e28fc5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
 
diff --git a/src/main/java/com/lescastcodeurs/bot/github/GitHubClient.java b/src/main/java/com/lescastcodeurs/bot/github/GitHubClient.java
index a290304..b7a3e0a 100644
--- a/src/main/java/com/lescastcodeurs/bot/github/GitHubClient.java
+++ b/src/main/java/com/lescastcodeurs/bot/github/GitHubClient.java
@@ -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";
 
@@ -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,
@@ -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,