8000 Add add_assignees method · cs-shadow/github3.py@acc328a · GitHub
[go: up one dir, main page]

Skip to content

Commit acc328a

Browse files
committed
Add add_assignees method
Add a convenience method to assign a list of users to an issue.
1 parent 87af5a1 commit acc328a

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

src/github3/issues/issue.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,27 @@ def _repr(self):
6767
n=self.number, class_name=self.class_name,
6868
)
6969

70+
@requires_auth
71+
def add_assignees(self, users):
72+
"""Assign ``users`` to this issue.
73+
74+
This is a shortcut for :meth:`~github3.issues.issue.Issue.edit`.
75+
76+
:param users:
77+
users or usernames to assign this issue to
78+
:type users:
79+
list of :class:`~github3.users.User`
80+
:type users:
81+
list of str
82+
:returns:
83+
True if successful, False otherwise
84+
:rtype:
85+
bool
86+
"""
87+
usernames = {getattr(user, 'login', user) for user in users}
88+
assignees = list({a.login for a in self.assignees} | usernames)
89+
return self.edit(assignees=assignees)
90+
7091
@requires_auth
7192
def add_labels(self, *args):
7293
"""Add labels to this issue.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": ["gzip, deflate"], "Accept": ["application/vnd.github.v3.full+json"], "User-Agent": ["github3.py/1.1.0"], "Accept-Charset": ["utf-8"], "Connection": ["keep-alive"], "Content-Type": ["application/json"], "Authorization": ["token <AUTH_TOKEN>"]}, "method": "GET", "uri": "https://api.github.com/repos/sigmavirus24/github3.py/issues/711"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA8VW/W/iNhj+V7xIm7aqISSkcGSBatPupP1Au9Poelo5IScx4GtiR/6Apaj/+147gQNEez2u0yQiiP2+j5/36zFrR4vciZyFUqWMPA+XtDWnaqGTVsoLT5CSS0/SeYGXVGgZhF6922mVlUel1ER6Pd93zh1rShUX1fR0SMDJcUJ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bubVsUbxjVfmslElV6/Xjv5qtd9IADAAA", "encoding": "utf-8"}, "headers": {"X-XSS-Protection": ["1; mode=block"], "Content-Security-Policy": ["default-src 'none'"], "Access-Control-Expose-Headers": ["ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"], "Transfer-Encoding": ["chunked"], "Last-Modified": ["Thu, 02 Aug 2018 23:09:19 GMT"], "Access-Control-Allow-Origin": ["*"], "X-Frame-Options": ["deny"], "Status": ["200 OK"], "X-GitHub-Request-Id": ["A2E6:3FAE:2C29574:52316EC:5B6404DA"], "ETag": ["W/\"5b4dd8dd9fd32bdbfc73353b8813f599\""], "Date": ["Fri, 03 Aug 2018 07:31:38 GMT"], "X-RateLimit-Remaining": ["4999"], "Strict-Transport-Security": ["max-age=31536000; includeSubdomains; preload"], "Server": ["GitHub.com"], "X-OAuth-Scopes": ["public_repo, read:user"], "X-GitHub-Media-Type": ["github.v3; param=full; format=json"], "X-Content-Type-Options": ["nosniff"], "Content-Encoding": ["gzip"], "X-Runtime-rack": ["0.104248"], "Vary": ["Accept, Authorization, Cookie, X-GitHub-OTP"], "X-RateLimit-Limit": ["5000"], "Cache-Control": ["private, max-age=60, s-maxage=60"], "Referrer-Policy": ["origin-when-cross-origin, strict-origin-when-cross-origin"], "Content-Type": ["application/json; charset=utf-8"], "X-Accepted-OAuth-Scopes": ["repo"], "X-RateLimit-Reset": ["1533285098"]}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/issues/711"}, & 8000 quot;recorded_at": "2018-08-03T07:31:38"}, {"request": {"body": {"string": "{\"assignees\": [\"jacquerie\"]}", "encoding": "utf-8"}, "headers": {"Content-Length": ["28"], "Accept-Encoding": ["gzip, deflate"], "Accept": ["application/vnd.github.v3.full+json"], "User-Agent": ["github3.py/1.1.0"], "Accept-Charset": ["utf-8"], "Connection": ["keep-alive"], "Content-Type": ["application/json"], "Authorization": ["token <AUTH_TOKEN>"]}, "method": "PATCH", "uri": "https://api.github.com/repos/sigmavirus24/github3.py/issues/711"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA+1YbW/iRhD+K66lVm0UY4wdSCgQXdWrdB8gdyppTg0ntLYX2MTe9e0L1EH57zdr82IsSMJL1Q89CQSsZ559dnae2R3mpuKR2TQnUiaiadsoIZUxkRPlVwIW2xwnTNiCjGM0JVyJmmfnT91KktpECIWF3XAc89zMTIlkPB0eDgk4EfJxJI7AKNCyc7C5TVGMnwEc1hRjKk8Fv4QDZDw9IW4OBqgTGUelUBR25037QkKzWXMvLq4878o5NykL8VCPmd3fb+t/fu49hXe3affp1rnpf6re9N+3YVqqYh9zswk7e25KIiMM9j1mzFBqSGYoigTMTQ1EjSwHwEUJ7TA3IzYmFKxjjGWM6Fg9khTBcz1lo16rXrjuJolP9b8+96LgIah1H9453aeuJoCmSCJeToJsUFQXCapnDBiVEPcsV5W9wL+etj3AGPMFSrZaTfGlTNdowi6zfjn+ZesRiyI2A5wy8U1RbZnKXrkCz/w7oeNDYcB1bjM5wRBBWJZO/DERr2X9NlqZ2xw0LyQkjQYSsAUch/tTWzgCsRkFTvOstmSIyhcBJ4kkjB4QuQ13gGN8jCh5QgfCgbsAlKya7b/IzA3c31INtsU795vbCSdTFKQ6PBwHmEwh4odilgAAUqaJFvStlizEn0g8RGGsZTtCkcDPyyJsNu+/ZDsutTlLMAXziAWPGBSVmYJSs0qAwWCt/QcUfFWYE10XtPjcS6d2Wd0u+67X7X/wuu/ar8m+tlP2OfwRqi/yfVnxRcu91L5yPFzpZYhjVL7GOkrha5jTqbuAWSwMhyh7DbWvqtee+yt67XsaNRe5bJSCNyl5qU8BYv6u0K2X3LwQl+UFxzgEeK+zuAzxXaG7O4ty0P+vCoUDNiYRFpJROEOpiqJ1lwIXd/jBMZy/4RBJCGat6jSsat1y3L5z0aw1mp7zN2SpSsINm0urCi+3X200XafpXmmbIGJiAZPPgpScMD6EAsECkl2XYILeTe89GPssTIf6KIShVtLpw1USGwLjWOj7v4/1zX/RA4wUDbTzueEraVAm9bNVhxBjmCQ0RowbH3Sn0LKTzoAOaGvC4ROg7xCVGSYKHg05ISLvKK6NlpCc0XGnhYwJx6P2YNWjzmazis8Ulalgigc4u/0velGv7jSuXM+zKLOgW7Eks5ZcLEStzOpayXgYoDhBcHNpJ5GCjuUn+PlrNp53FG3JgRDmP9b+cC5dr9FYGcQ4JCpu5/OtRnMm7bw5G5gGxxEwpiyvHwOz85EJiIyR8zYYNE7yh5aNOi17sU7jDqIaBDiRuRHBwpgSZLxx/f/Jon4r7IJeTKXlZ9sKm7xMIon/0Yl7ugzS2TOgO9NmW5x3hbZIv7IgfFquHLjCu1VMVyvPuI5+oN+WZemPnSs6O7vftqgvPy//s/lX9PCiFvTDTR3okQ0N/HJ2tivs98W4v7KMrWl9NLdKtin2tl1ZV0o/zevx8zchJQr2JBMAAA==", "encoding": "utf-8"}, "headers": {"X-XSS-Protection": ["1; mode=block"], "Content-Security-Policy": ["default-src 'none'"], "Access-Control-Expose-Headers": ["ETag, Link, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval"], "Transfer-Encoding": ["chunked"], "Access-Control-Allow-Origin": ["*"], "X-Frame-Options": ["deny"], "Status": ["200 OK"], "X-GitHub-Request-Id": ["A2E6:3FAE:2C295A6:5231732:5B6404DA"], "ETag": ["W/\"b4505c5c6261cbcfd05fc36ec2685139\""], "Date": ["Fri, 03 Aug 2018 07:31:39 GMT"], "X-RateLimit-Remaining": ["4998"], "Strict-Transport-Security": ["max-age=31536000; includeSubdomains; preload"], "Server": ["GitHub.com"], "X-OAuth-Scopes": ["public_repo, read:user"], "X-GitHub-Media-Type": ["github.v3; param=full; format=json"], "X-Content-Type-Options": ["nosniff"], "Content-Encoding": ["gzip"], "X-Runtime-rack": ["0.706423"], "Vary": ["Accept, Authorization, Cookie, X-GitHub-OTP"], "X-RateLimit-Limit": ["5000"], "Cache-Control": ["private, max-age=60, s-maxage=60"], "Referrer-Policy": ["origin-when-cross-origin, strict-origin-when-cross-origin"], "Content-Type": ["application/json; charset=utf-8"], "X-Accepted-OAuth-Scopes": [""], "X-RateLimit-Reset": ["1533285098"]}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/issues/711"}, "recorded_at": "2018-08-03T07:31:39"}], "recorded_with": "betamax/0.8.1"}

tests/integration/test_issue.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,18 @@ class TestIssue(IntegrationHelper):
1111

1212
"""Integration tests for methods on the Issue class."""
1313

14+
def test_add_assignees(self):
15+
"""Test the ability to add assignees to an issue."""
16+
self.auto_login()
17+
cassette_name = self.cassette_name('add_assignees')
18+
with self.recorder.use_cassette(cassette_name):
19+
issue = self.gh.issue(username='sigmavirus24',
20+
repository='github3.py',
21+
number=711)
22+
assigned = issue.add_assignees(['jacquerie'])
23+
24+< 8000 div class="diff-text-inner"> assert assigned is True
25+
1426
def test_add_labels(self):
1527
"""Test the ability to add a label to an issue."""
1628
self.auto_login()

tests/unit/test_issues_issue.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ class TestIssueRequiresAuth(helper.UnitRequiresAuthenticationHelper):
4444
def after_setup(self):
4545
self.session.has_auth.return_value = False
4646

47+
def test_add_assignees(self):
48+
"""Verify that adding assignees requires authentication."""
49+
self.assert_requires_auth(self.instance.add_assignees)
50+
4751
def test_add_labels(self):
4852
"""Verify that adding a label requires authentication."""
4953
self.assert_requires_auth(self.instance.add_labels, 'enhancement')
@@ -92,6 +96,15 @@ class TestIssue(helper.UnitHelper):
9296
described_class = github3.issues.Issue
9397
example_data = get_issue_example_data()
9498

99+
def test_add_assignees(self):
100+
"""Verify the request for adding assignees to an issue."""
101+
self.instance.add_assignees(['jacquerie'])
102+
103+
self.session.patch.assert_called_with(
104+
url_for(),
105+
data='{"assignees": ["jacquerie"]}'
106+
)
107+
95108
def test_add_labels(self):
96109
"""Verify the request for adding a label."""
97110
self.instance.add_labels('enhancement')

0 commit comments

Comments
 (0)
0