mirror of
https://github.com/status-im/PyGithub.git
synced 2026-09-02 11:51:10 +00:00
Jump from notifications to related PRs/issues. (#1168)
* Jump from notifications to related PRs/issues. * Add test case for jumping to related PRs/issues. Also another method to get notifications scoped to a repository, otherwise it's hard to keep out sensitive information from the test cases.
This commit is contained in:
committed by
Steve Kowalik
parent
b84d9b1928
commit
020fbebcaf
@@ -125,6 +125,20 @@ class Notification(github.GithubObject.CompletableGithubObject):
|
||||
self.url,
|
||||
)
|
||||
|
||||
def get_pull_request(self):
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
self.subject.url
|
||||
)
|
||||
return github.PullRequest.PullRequest(self._requester, headers, data, completed=True)
|
||||
|
||||
def get_issue(self):
|
||||
headers, data = self._requester.requestJsonAndCheck(
|
||||
"GET",
|
||||
self.subject.url
|
||||
)
|
||||
return github.Issue.Issue(self._requester, headers, data, completed=True)
|
||||
|
||||
def _initAttributes(self):
|
||||
self._id = github.GithubObject.NotSet
|
||||
self._last_read_at = github.GithubObject.NotSet
|
||||
|
||||
@@ -2616,6 +2616,38 @@ class Repository(github.GithubObject.CompletableGithubObject):
|
||||
for element in data["issues"]
|
||||
]
|
||||
|
||||
def get_notifications(self, all=github.GithubObject.NotSet, participating=github.GithubObject.NotSet, since=github.GithubObject.NotSet, before=github.GithubObject.NotSet):
|
||||
"""
|
||||
:calls: `GET /repos/:owner/:repo/notifications <http://developer.github.com/v3/activity/notifications>`_
|
||||
:param all: bool
|
||||
:param participating: bool
|
||||
:param since: datetime.datetime
|
||||
:param before: datetime.datetime
|
||||
:rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.Notification.Notification`
|
||||
"""
|
||||
|
||||
assert all is github.GithubObject.NotSet or isinstance(all, bool), all
|
||||
assert participating is github.GithubObject.NotSet or isinstance(participating, bool), participating
|
||||
assert since is github.GithubObject.NotSet or isinstance(since, datetime.datetime), since
|
||||
assert before is github.GithubObject.NotSet or isinstance(before, datetime.datetime), before
|
||||
|
||||
params = dict()
|
||||
if all is not github.GithubObject.NotSet:
|
||||
params["all"] = all
|
||||
if participating is not github.GithubObject.NotSet:
|
||||
params["participating"] = participating
|
||||
if since is not github.GithubObject.NotSet:
|
||||
params["since"] = since.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
if before is not github.GithubObject.NotSet:
|
||||
params["before"] = before.strftime("%Y-%m-%dT%H:%M:%SZ")
|
||||
|
||||
return github.PaginatedList.PaginatedList(
|
||||
github.Notification.Notification,
|
||||
self._requester,
|
||||
self.url + "/notifications",
|
||||
params
|
||||
)
|
||||
|
||||
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>`_
|
||||
|
||||
@@ -129,4 +129,5 @@ from .Issue937 import *
|
||||
from .Issue945 import *
|
||||
from .Issue823 import *
|
||||
|
||||
from .PullRequest1168 import *
|
||||
from .PullRequest1169 import *
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
############################ Copyrights and license ############################
|
||||
# #
|
||||
# Copyright 2019 Olof-Joachim Frahm <olof@macrolet.net> #
|
||||
# #
|
||||
# This file is part of PyGithub. #
|
||||
# http://pygithub.readthedocs.io/ #
|
||||
# #
|
||||
# PyGithub is free software: you can redistribute it and/or modify it under #
|
||||
# the terms of the GNU Lesser General Public License as published by the Free #
|
||||
# Software Foundation, either version 3 of the License, or (at your option) #
|
||||
# any later version. #
|
||||
# #
|
||||
# PyGithub is distributed in the hope that it will be useful, but WITHOUT ANY #
|
||||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS #
|
||||
# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more #
|
||||
# details. #
|
||||
# #
|
||||
# You should have received a copy of the GNU Lesser General Public License #
|
||||
# along with PyGithub. If not, see <http://www.gnu.org/licenses/>. #
|
||||
# #
|
||||
################################################################################
|
||||
|
||||
from __future__ import absolute_import
|
||||
from . import Framework
|
||||
|
||||
|
||||
class PullRequest1168(Framework.TestCase):
|
||||
def setUp(self):
|
||||
Framework.TestCase.setUp(self)
|
||||
self.notifications = self.g.get_repo("PyGithub/PyGithub").get_notifications(all=True)
|
||||
|
||||
def testGetPullRequest(self):
|
||||
p = self.notifications[0].get_pull_request()
|
||||
self.assertEqual(p.id, 297582636)
|
||||
self.assertEqual(p.number, 1171)
|
||||
self.assertEqual(p.title, "Fix small issues for Python 3 compatibility.")
|
||||
|
||||
def testGetIssue(self):
|
||||
i = self.notifications[0].get_issue()
|
||||
self.assertEqual(i.id, 297582636)
|
||||
self.assertEqual(i.number, 1171)
|
||||
self.assertEqual(i.title, "Fix small issues for Python 3 compatibility.")
|
||||
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user