Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can now specify assignee as a string #218

Merged
merged 3 commits into from Dec 24, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions github/Issue.py
Expand Up @@ -262,15 +262,15 @@ def edit(self, title=github.GithubObject.NotSet, body=github.GithubObject.NotSet
:calls: `PATCH /repos/:owner/:repo/issues/:number <http://developer.github.com/v3/issues>`_
:param title: string
:param body: string
:param assignee: :class:`github.NamedUser.NamedUser` or None
:param assignee: string or :class:`github.NamedUser.NamedUser` or None
:param state: string
:param milestone: :class:`github.Milestone.Milestone` or None
:param labels: list of string
:rtype: None
"""
assert title is github.GithubObject.NotSet or isinstance(title, (str, unicode)), title
assert body is github.GithubObject.NotSet or isinstance(body, (str, unicode)), body
assert assignee is github.GithubObject.NotSet or assignee is None or isinstance(assignee, github.NamedUser.NamedUser), assignee
assert assignee is github.GithubObject.NotSet or assignee is None or isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, (str, unicode)), assignee
assert state is github.GithubObject.NotSet or isinstance(state, (str, unicode)), state
assert milestone is github.GithubObject.NotSet or milestone is None or isinstance(milestone, github.Milestone.Milestone), milestone
assert labels is github.GithubObject.NotSet or all(isinstance(element, (str, unicode)) for element in labels), labels
Expand All @@ -280,7 +280,10 @@ def edit(self, title=github.GithubObject.NotSet, body=github.GithubObject.NotSet
if body is not github.GithubObject.NotSet:
post_parameters["body"] = body
if assignee is not github.GithubObject.NotSet:
post_parameters["assignee"] = assignee._identity if assignee else ''
if isinstance(assignee, (str, unicode)):
post_parameters["assignee"] = assignee
else:
post_parameters["assignee"] = assignee._identity if assignee else ''
if state is not github.GithubObject.NotSet:
post_parameters["state"] = state
if milestone is not github.GithubObject.NotSet:
Expand Down
53 changes: 36 additions & 17 deletions github/Repository.py
Expand Up @@ -636,13 +636,17 @@ def watchers_count(self):
def add_to_collaborators(self, collaborator):
"""
:calls: `PUT /repos/:owner/:repo/collaborators/:user <http://developer.github.com/v3/repos/collaborators>`_
:param collaborator: :class:`github.NamedUser.NamedUser`
:param collaborator: string or :class:`github.NamedUser.NamedUser`
:rtype: None
"""
assert isinstance(collaborator, github.NamedUser.NamedUser), collaborator
assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, (str, unicode)), collaborator

if isinstance(collaborator, github.NamedUser.NamedUser):
collaborator = collaborator._identity

headers, data = self._requester.requestJsonAndCheck(
"PUT",
self.url + "/collaborators/" + collaborator._identity
self.url + "/collaborators/" + collaborator
)

def compare(self, base, head):
Expand Down Expand Up @@ -815,14 +819,14 @@ def create_issue(self, title, body=github.GithubObject.NotSet, assignee=github.G
:calls: `POST /repos/:owner/:repo/issues <http://developer.github.com/v3/issues>`_
:param title: string
:param body: string
:param assignee: :class:`github.NamedUser.NamedUser`
:param assignee: string or :class:`github.NamedUser.NamedUser`
:param milestone: :class:`github.Milestone.Milestone`
:param labels: list of :class:`github.Label.Label`
:rtype: :class:`github.Issue.Issue`
"""
assert isinstance(title, (str, unicode)), title
assert body is github.GithubObject.NotSet or isinstance(body, (str, unicode)), body
assert assignee is github.GithubObject.NotSet or isinstance(assignee, github.NamedUser.NamedUser), assignee
assert assignee is github.GithubObject.NotSet or isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, (str, unicode)), assignee
assert milestone is github.GithubObject.NotSet or isinstance(milestone, github.Milestone.Milestone), milestone
assert labels is github.GithubObject.NotSet or all(isinstance(element, github.Label.Label) for element in labels), labels
post_parameters = {
Expand All @@ -831,7 +835,10 @@ def create_issue(self, title, body=github.GithubObject.NotSet, assignee=github.G
if body is not github.GithubObject.NotSet:
post_parameters["body"] = body
if assignee is not github.GithubObject.NotSet:
post_parameters["assignee"] = assignee._identity
if isinstance(assignee, (str, unicode)):
post_parameters["assignee"] = assignee
else:
post_parameters["assignee"] = assignee._identity
if milestone is not github.GithubObject.NotSet:
post_parameters["milestone"] = milestone._identity
if labels is not github.GithubObject.NotSet:
Expand Down Expand Up @@ -1394,7 +1401,7 @@ def get_issues(self, milestone=github.GithubObject.NotSet, state=github.GithubOb
:calls: `GET /repos/:owner/:repo/issues <http://developer.github.com/v3/issues>`_
:param milestone: :class:`github.Milestone.Milestone` or "none" or "*"
:param state: string
:param assignee: :class:`github.NamedUser.NamedUser` or "none" or "*"
:param assignee: string or :class:`github.NamedUser.NamedUser` or "none" or "*"
:param mentioned: :class:`github.NamedUser.NamedUser`
:param labels: list of :class:`github.Label.Label`
:param sort: string
Expand All @@ -1404,7 +1411,7 @@ def get_issues(self, milestone=github.GithubObject.NotSet, state=github.GithubOb
"""
assert milestone is github.GithubObject.NotSet or milestone == "*" or milestone == "none" or isinstance(milestone, github.Milestone.Milestone), milestone
assert state is github.GithubObject.NotSet or isinstance(state, (str, unicode)), state
assert assignee is github.GithubObject.NotSet or assignee == "*" or assignee == "none" or isinstance(assignee, github.NamedUser.NamedUser), assignee
assert assignee is github.GithubObject.NotSet or isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, (str, unicode)), assignee
assert mentioned is github.GithubObject.NotSet or isinstance(mentioned, github.NamedUser.NamedUser), mentioned
assert labels is github.GithubObject.NotSet or all(isinstance(element, github.Label.Label) for element in labels), labels
assert sort is github.GithubObject.NotSet or isinstance(sort, (str, unicode)), sort
Expand Down Expand Up @@ -1825,26 +1832,34 @@ def get_watchers(self):
def has_in_assignees(self, assignee):
"""
:calls: `GET /repos/:owner/:repo/assignees/:assignee <http://developer.github.com/v3/issues/assignees>`_
:param assignee: :class:`github.NamedUser.NamedUser`
:param assignee: string or :class:`github.NamedUser.NamedUser`
:rtype: bool
"""
assert isinstance(assignee, github.NamedUser.NamedUser), assignee
assert isinstance(assignee, github.NamedUser.NamedUser) or isinstance(assignee, (str, unicode)), assignee

if isinstance(assignee, github.NamedUser.NamedUser):
assignee = assignee._identity

status, headers, data = self._requester.requestJson(
"GET",
self.url + "/assignees/" + assignee._identity
self.url + "/assignees/" + assignee
)
return status == 204

def has_in_collaborators(self, collaborator):
"""
:calls: `GET /repos/:owner/:repo/collaborators/:user <http://developer.github.com/v3/repos/collaborators>`_
:param collaborator: :class:`github.NamedUser.NamedUser`
:param collaborator: string or :class:`github.NamedUser.NamedUser`
:rtype: bool
"""
assert isinstance(collaborator, github.NamedUser.NamedUser), collaborator
assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, (str, unicode)), collaborator

if isinstance(collaborator, github.NamedUser.NamedUser):
collaborator = collaborator._identity

status, headers, data = self._requester.requestJson(
"GET",
self.url + "/collaborators/" + collaborator._identity
self.url + "/collaborators/" + collaborator
)
return status == 204

Expand Down Expand Up @@ -1896,13 +1911,17 @@ def merge(self, base, head, commit_message=github.GithubObject.NotSet):
def remove_from_collaborators(self, collaborator):
"""
:calls: `DELETE /repos/:owner/:repo/collaborators/:user <http://developer.github.com/v3/repos/collaborators>`_
:param collaborator: :class:`github.NamedUser.NamedUser`
:param collaborator: string or :class:`github.NamedUser.NamedUser`
:rtype: None
"""
assert isinstance(collaborator, github.NamedUser.NamedUser), collaborator
assert isinstance(collaborator, github.NamedUser.NamedUser) or isinstance(collaborator, (str, unicode)), collaborator

if isinstance(collaborator, github.NamedUser.NamedUser):
collaborator = collaborator._identity

headers, data = self._requester.requestJsonAndCheck(
"DELETE",
self.url + "/collaborators/" + collaborator._identity
self.url + "/collaborators/" + collaborator
)

def subscribe_to_hub(self, event, callback, secret=github.GithubObject.NotSet):
Expand Down
1 change: 1 addition & 0 deletions github/tests/AllTests.py
Expand Up @@ -86,3 +86,4 @@
from Issue142 import *
from Issue158 import *
from Issue174 import *
from Issue214 import *
69 changes: 69 additions & 0 deletions github/tests/Issue214.py
@@ -0,0 +1,69 @@
# -*- coding: utf-8 -*-

############################ Copyrights and license ############################
# #
# Copyright 2012 Vincent Jacques <vincent@vincent-jacques.net> #
# Copyright 2012 Zearin <zearin@gonk.net> #
# Copyright 2013 Vincent Jacques <vincent@vincent-jacques.net> #
# #
# This file is part of PyGithub. http://jacquev6.github.com/PyGithub/ #
# #
# 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/>. #
# #
################################################################################

import github

import Framework


class Issue214(Framework.TestCase): # https://github.com/jacquev6/PyGithub/issues/214
def setUp(self):
Framework.TestCase.setUp(self)
self.repo = self.g.get_user().get_repo("PyGithub")
self.issue = self.repo.get_issue(1)

def testAssignees(self):
self.assertTrue(self.repo.has_in_assignees('farrd'))
self.assertFalse(self.repo.has_in_assignees('fake'))

def testCollaborators(self):
self.assertTrue(self.repo.has_in_collaborators('farrd'))
self.assertFalse(self.repo.has_in_collaborators('fake'))

self.assertFalse(self.repo.has_in_collaborators('marcmenges'))
self.repo.add_to_collaborators('marcmenges')
self.assertTrue(self.repo.has_in_collaborators('marcmenges'))

self.repo.remove_from_collaborators('marcmenges')
self.assertFalse(self.repo.has_in_collaborators('marcmenges'))

def testEditIssue(self):
self.assertEqual(self.issue.assignee, None)

self.issue.edit(assignee='farrd')
self.assertEqual(self.issue.assignee.login, 'farrd')

self.issue.edit(assignee=None)
self.assertEqual(self.issue.assignee, None)

def testCreateIssue(self):
issue = self.repo.create_issue("Issue created by PyGithub", assignee='farrd')
self.assertEqual(issue.assignee.login, 'farrd')

def testGetIssues(self):
issues = self.repo.get_issues(assignee='farrd')

for issue in issues:
self.assertEqual(issue.assignee.login, 'farrd')
33 changes: 33 additions & 0 deletions github/tests/ReplayData/Issue214.setUp.txt

Large diffs are not rendered by default.

22 changes: 22 additions & 0 deletions github/tests/ReplayData/Issue214.testAssignees.txt
@@ -0,0 +1,22 @@
https
GET
api.github.com
None
/repos/farrd/PyGithub/assignees/farrd
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
null
204
[('status', '204 No Content'), ('x-ratelimit-remaining', '4838'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('access-control-expose-headers', 'ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval'), ('x-github-request-id', 'A99159CE:043C:7376C18:52AF9217'), ('vary', 'Accept-Encoding'), ('server', 'GitHub.com'), ('x-ratelimit-limit', '5000'), ('access-control-allow-credentials', 'true'), ('date', 'Mon, 16 Dec 2013 23:51:51 GMT'), ('access-control-allow-origin', '*'), ('x-ratelimit-reset', '1387240227')]


https
GET
api.github.com
None
/repos/farrd/PyGithub/assignees/fake
{'Authorization': 'Basic login_and_password_removed', 'User-Agent': 'PyGithub/Python'}
null
404
[('status', '404 Not Found'), ('x-ratelimit-remaining', '4837'), ('x-github-media-type', 'github.beta; format=json'), ('x-content-type-options', 'nosniff'), ('access-control-expose-headers', 'ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval'), ('x-github-request-id', 'A99159CE:0438:2A76207:52AF9218'), ('content-length', '76'), ('server', 'GitHub.com'), ('x-ratelimit-limit', '5000'), ('access-control-allow-credentials', 'true'), ('date', 'Mon, 16 Dec 2013 23:51:52 GMT'), ('access-control-allow-origin', '*'), ('content-type', 'application/json; charset=utf-8'), ('x-ratelimit-reset', '1387240227')]
{"message":"Not Found","documentation_url":"http://developer.github.com/v3"}