Skip to content
This repository was archived by the owner on Jul 31, 2025. It is now read-only.

Commit 8835b2c

Browse files
committed
added a method to mark all the notifications as read
1 parent 74fda40 commit 8835b2c

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/main/java/org/kohsuke/github/GHNotificationStream.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,5 +189,19 @@ public void remove() {
189189
};
190190
}
191191

192+
public void markAsRead() throws IOException {
193+
markAsRead(-1);
194+
}
195+
196+
/**
197+
* Marks all the notifications as read.
198+
*/
199+
public void markAsRead(long timestamp) throws IOException {
200+
final Requester req = new Requester(root).method("PUT");
201+
if (timestamp>=0)
202+
req.with("last_read_at", GitHub.printDate(new Date(timestamp)));
203+
req.asHttpStatusCode(apiUrl);
204+
}
205+
192206
private static final GHThread[] EMPTY_ARRAY = new GHThread[0];
193207
}

src/test/java/org/kohsuke/github/AppTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -810,7 +810,7 @@ public void searchContent() throws Exception {
810810
@Test
811811
public void notifications() throws Exception {
812812
boolean found=false;
813-
for (GHThread t : gitHub.listNotifications().nonBlocking(true)) {
813+
for (GHThread t : gitHub.listNotifications().nonBlocking(true).read(true)) {
814814
found = true;
815815
assertNotNull(t.getTitle());
816816
assertNotNull(t.getReason());
@@ -821,6 +821,7 @@ public void notifications() throws Exception {
821821
System.out.println();
822822
}
823823
assertTrue(found);
824+
gitHub.listNotifications().markAsRead();
824825
}
825826

826827
private void kohsuke() {

0 commit comments

Comments
 (0)