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 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