Mark notification as read (#932)

Wraps the parts of the notification API that allows the user to mark notifications as read.
New methods are : 
 
- Notification.mark_as_read : marks a single notification thread as read
- Repository.mark_notifications_as_read : marks all the notifications for a given repository as read
- AuthenticatedUser.mark_notifications_as_read : marks all the notifications as read

Aims to fix : https://github.com/PyGithub/PyGithub/issues/571 and simply uses the APIs described on this page : https://developer.github.com/enterprise/11.10.340/v3/activity/notifications/

A weird thing I noticed doing this is that Repository.notifications_url doesn't seem to be usable directly. I used Repository.url + "/notifications" instead.
This commit is contained in:
Alice GIRARD
2018-10-19 07:24:45 +08:00
committed by Wan Liuyang
parent 2b2ecfad4d
commit 0a10d7cdf0
12 changed files with 166 additions and 0 deletions
+16
View File
@@ -2473,6 +2473,22 @@ class Repository(github.GithubObject.CompletableGithubObject):
for element in data["issues"]
]
def mark_notifications_as_read(self, last_read_at=datetime.datetime.utcnow()):
"""
:calls: `PUT /repos/:owner/:repo/notifications <https://developer.github.com/v3/activity/notifications>`_
:param last_read_at: datetime
"""
assert isinstance(last_read_at, datetime.datetime)
put_parameters = {
"last_read_at": last_read_at.strftime('%Y-%m-%dT%H:%M:%SZ')
}
headers, data = self._requester.requestJsonAndCheck(
"PUT",
self.url + "/notifications",
input=put_parameters
)
def merge(self, base, head, commit_message=github.GithubObject.NotSet):
"""
:calls: `POST /repos/:owner/:repo/merges <http://developer.github.com/v3/repos/merging>`_