From 11c65f46215fee9a436a0e25b2f968a883240771 Mon Sep 17 00:00:00 2001 From: Clown <3148835359@qq.com> Date: Tue, 12 Nov 2024 19:27:21 +0800 Subject: [PATCH 1/2] fix GitHub notification interface return "Unable to parse If-Modified-Since request header" --- src/main/java/org/kohsuke/github/GHNotificationStream.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/kohsuke/github/GHNotificationStream.java b/src/main/java/org/kohsuke/github/GHNotificationStream.java index 7e62d7b6c6..f769907125 100644 --- a/src/main/java/org/kohsuke/github/GHNotificationStream.java +++ b/src/main/java/org/kohsuke/github/GHNotificationStream.java @@ -187,7 +187,9 @@ GHThread fetch() { Thread.sleep(waitTime); } - req.setHeader("If-Modified-Since", lastModified); + if (lastModified != null) { + req.setHeader("If-Modified-Since", lastModified); + } Requester requester = req.withUrlPath(apiUrl); GitHubResponse response = ((GitHubPageContentsIterable) requester From c23e3c6b1afd237e1af89b13a788e7f0108192e4 Mon Sep 17 00:00:00 2001 From: Clown <3148835359@qq.com> Date: Wed, 20 Nov 2024 23:44:54 +0800 Subject: [PATCH 2/2] updated test for GHNotificationStream --- src/test/java/org/kohsuke/github/AppTest.java | 1 + .../__files/27-notifications.json | 5 ++ .../mappings/26-notifications.json | 3 +- .../mappings/27-notifications.json | 47 +++++++++++++++++++ 4 files changed, 54 insertions(+), 2 deletions(-) create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/__files/27-notifications.json create mode 100644 src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/27-notifications.json diff --git a/src/test/java/org/kohsuke/github/AppTest.java b/src/test/java/org/kohsuke/github/AppTest.java index 9f73194b15..b271dd7ca8 100755 --- a/src/test/java/org/kohsuke/github/AppTest.java +++ b/src/test/java/org/kohsuke/github/AppTest.java @@ -1709,6 +1709,7 @@ public void notifications() throws Exception { } assertThat(found, is(true)); gitHub.listNotifications().markAsRead(); + gitHub.listNotifications().iterator().next(); } /** diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/__files/27-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/__files/27-notifications.json new file mode 100644 index 0000000000..9527e46df8 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/__files/27-notifications.json @@ -0,0 +1,5 @@ +{ + "message": "Unable to parse If-Modified-Since request header. Please make sure value is in an acceptable format.", + "documentation_url": "https://docs.github.com/rest/activity/notifications#list-notifications-for-the-authenticated-user", + "status": "422" +} \ No newline at end of file diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/26-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/26-notifications.json index 5a7378d124..a120a83569 100644 --- a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/26-notifications.json +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/26-notifications.json @@ -40,8 +40,7 @@ "X-XSS-Protection": "1; mode=block", "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", "Content-Security-Policy": "default-src 'none'", - "X-GitHub-Request-Id": "CB13:833E:A1F759:BFE352:5DB3A151", - "Link": "; rel=\"next\", ; rel=\"last\"" + "X-GitHub-Request-Id": "CB13:833E:A1F759:BFE352:5DB3A151" } }, "uuid": "ac22e3e2-f0d3-4ff1-af23-23e9c79c725c", diff --git a/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/27-notifications.json b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/27-notifications.json new file mode 100644 index 0000000000..f6c602f01a --- /dev/null +++ b/src/test/resources/org/kohsuke/github/AppTest/wiremock/notifications/mappings/27-notifications.json @@ -0,0 +1,47 @@ +{ + "id": "ac22e3e2-f0d3-4ff1-af23-23e9c7915874", + "name": "notifications", + "request": { + "url": "/notifications", + "method": "GET", + "headers": { + "Accept": { + "equalTo": "application/vnd.github+json" + }, + "If-Modified-Since":{ + "equalTo": "null" + } + } + }, + "response": { + "status": 422, + "bodyFileName": "27-notifications.json", + "headers": { + "Date": "Wed, 20 Nov 2024 13:55:23 GMT", + "Content-Type": "application/json; charset=utf-8", + "X-OAuth-Scopes": "repo", + "X-Accepted-OAuth-Scopes": "notifications, repo", + "X-GitHub-Media-Type": "github.v3; format=json", + "x-github-api-version-selected": "2022-11-28", + "X-RateLimit-Limit": "5000", + "X-RateLimit-Remaining": "4992", + "X-RateLimit-Reset": "1732111985", + "X-RateLimit-Used": "8", + "X-RateLimit-Resource": "core", + "Access-Control-Expose-Headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, X-GitHub-SSO, X-GitHub-Request-Id, Deprecation, Sunset", + "Access-Control-Allow-Origin": "*", + "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", + "X-Frame-Options": "deny", + "X-Content-Type-Options": "nosniff", + "X-XSS-Protection": "0", + "Referrer-Policy": "origin-when-cross-origin, strict-origin-when-cross-origin", + "Content-Security-Policy": "default-src 'none'", + "Vary": "Accept-Encoding, Accept, X-Requested-With", + "Server": "github.com", + "X-GitHub-Request-Id": "052F:2E353B:3FE0C:42EBB:673DEA4B" + } + }, + "uuid": "ac22e3e2-f0d3-4ff1-af23-23e9c7915874", + "persistent": true, + "insertionIndex": 26 +} \ No newline at end of file