8000 Added ability to retrieve status of multiple imported issues by itsmemattchung · Pull Request #559 · sigmavirus24/github3.py · GitHub
[go: up one dir, main page]

Skip to content

Added ability to retrieve status of multiple imported issues #559

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

Merged
merged 3 commits into from
Feb 5, 2016
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 32 additions & 3 deletions github3/repos/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,11 +534,11 @@ def commits(self, sha=None, path=None, author=None, number=-1, etag=None,
:param str etag: (optional), ETag from a previous request to the same
endpoint
:param since: (optional), Only commits after this date will
be returned. This can be a `datetime` or an `ISO8601` formatted
be returned. This can be a ``datetime`` or an ``ISO8601`` formatted
date string.
:type since: datetime or string
:param until: (optional), Only commits before this date will
be returned. This can be a `datetime` or an `ISO8601` formatted
be returned. This can be a ``datetime`` or an ``ISO8601`` formatted
date string.
:type until: datetime or string

Expand Down Expand Up @@ -1281,6 +1281,35 @@ def imported_issue(self, imported_issue_id):
json = self._json(data, 200)
return self._instance_or_null(ImportedIssue, json)

@requires_auth
def imported_issues(self, number=-1, since=None, etag=None):
"""Retrieve the collection of imported issues via the API.

See also: https://gist.github.com/jonmagic/5282384165e0f86ef105

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Were we including links to the Gist in other docstrings?

:param int number: (optional), number of imported issues to return.
Default: -1 returns all branches
:param since: (optional), Only imported issues after this date will
be returned. This can be a ``datetime`` instance, ISO8601
formatted date string, or a string formatted like so:
``2016-02-04`` i.e. ``%Y-%m-%d``
:param str etag: (optional), ETag from a previous request to the same
endpoint
:returns: generator of :class:`ImportedIssue <github3.repos.
issue_import.ImportedIssue>`
"""

data = {
'since': timestamp_parameter(since)
}

self._remove_none(data)
url = self._build_url('import/issues', base_url=self._api)

return self._iter(int(number), url, ImportedIssue, etag=etag,
params=data,
headers=ImportedIssue.IMPORT_CUSTOM_HEADERS)

@requires_auth
def import_issue(self, title, body, created_at, assignee=None,
milestone=None, closed=None, labels=None, comments=None):
Expand Down Expand Up @@ -1397,7 +1426,7 @@ def issues(self, milestone=None, state=None, assignee=None, mentioned=None,
('created', 'updated', 'comments', 'created')
:param str direction: (optional), accepted values: ('asc', 'desc')
:param since: (optional), Only issues after this date will
be returned. This can be a `datetime` or an `ISO8601` formatted
be returned. This can be a ``datetime`` or an ``ISO8601`` formatted
date string, e.g., 2012-05-20T23:10:27Z
:type since: datetime or string
:param int number: (optional), Number of issues to return.
Expand Down
1 change: 1 addition & 0 deletions tests/cassettes/Repository_imported_issues.json
Original file line number Diff line number Diff line change
@@ -0,0 +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.0.0a2", "Accept-Charset": "utf-8", "Connection": "keep-alive", "Content-Type": "application/json", "Authorization": "token <AUTH_TOKEN>"}, "method": "GET", "uri": "https://api.github.com/repos/github3py/test_rename1"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA+2Yz46jOBDG34XrZONOMpmdQVrNvMFc9rSXyAEHrAaMbJMojfrd5yubf0ErkrSvLbVaBFw/PpddpqraSKZRvNt93Wxevv1YRRUvRRRHVhh70IJ+baJVdGqK4tA9yqTNm+OuvrLZIHWphI7iNipUJitAhpEg0Fs2f3/fbvbfVhE/c8v1odEFRuXW1iZmzN80a2/VGKETVVlR2XWiStawzvrn+Z8deJnuIASOcGMGq2UH8tagGTbVk9uymAnwj9346ciTKgp1gf1c7+Ir2GBG7nMIWWUfQcCsZcrmAg7DNN5p8tLYJ+U4kxYTw7rKlCAGS6BF+pykzgiCaLHfW6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EsH+9RVcJecAhMDqlpQdGdKNv3Pw/iJ5WbFgAA", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "x-github-media-type": "github.v3; param=full; format=json", "x-oauth-scopes": "admin:public_key, gist, repo, user", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "x-accepted-oauth-scopes": "repo", "etag": "W/\"13a47a4d1a5c47a7a39be7630d80c17c\"", "cache-control": "private, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "4991", "x-served-by": "a6882e5cd2513376cb9481dbcd83f3a2", "access-control-expose-headers": "ETag, Link, 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", "x-github-request-id": "97E45D32:14F4C:367C294:56ACB87A", "access-control-allow-credentials": "true", "last-modified": "Sat, 04 Apr 2015 15:58:51 GMT", "date": "Sat, 30 Jan 2016 13:19:54 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains; preload", "server": "GitHub.com", "x-ratelimit-limit": "5000", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1454161385"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/github3py/test_rename1"}, "recorded_at": "2016-01-30T13:19:55"}, {"request": {"body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.golden-comet-preview+json", "User-Agent": "github3.py/1.0.0a2", "Accept-Charset": "utf-8", "Connection": "keep-alive", "Content-Type": "application/json", "Authorization": "token <AUTH_TOKEN>"}, "method": "GET", "uri": "https://api.github.com/repos/github3py/test_rename1/import/issues?per_page=100"}, "response": {"body": {"string": "", "base64_string": "H4sIAAAAAAAAA9WRuw7CMAxF/8UrpbHb8ki+gw2hKrQRRKI0StwBIf6d0AgYQQgG1ivr2NdnfQbbgiqlXEjMILDmIYAC27nes2khg8EfYrBndkEJoZ3Nd5b3wzZv+k544/ogUlC6k2ATuPbmqDtDIkGEDWEwQaQdEZjiOsX1l/CRO95iufenz6ER03ijY/Nac6xdIM2nSFOqViTVjFRBE0SFeHuMa98bHJt+ftP9gQSXLOmqECXNf6sr7fhXXcsVVaqQivCFrsfg0+uXdBVw2VwBSH+sCl8DAAA=", "encoding": "utf-8"}, "headers": {"vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "x-github-media-type": "github.golden-comet-preview; format=json", "x-oauth-scopes": "admin:public_key, gist, repo, user", "x-xss-protection": "1; mode=block", "x-content-type-options": "nosniff", "x-accepted-oauth-scopes": "", "etag": "W/\"48dbaef3f5b20510df98e3f2cbe50005\"", "cache-control": "private, max-age=60, s-maxage=60", "status": "200 OK", "x-ratelimit-remaining": "4990", "x-served-by": "a7f8a126c9ed3f1c4715a34c0ddc7290", "access-control-expose-headers": "ETag, Link, 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", "x-github-request-id": "97E45D32:14F4C:367 10000 C2C9:56ACB87A", "access-control-allow-credentials": "true", "date": "Sat, 30 Jan 2016 13:19:54 GMT", "access-control-allow-origin": "*", "content-security-policy": "default-src 'none'", "content-encoding": "gzip", "strict-transport-security": "max-age=31536000; includeSubdomains; preload", "server": "GitHub.com", "x-ratelimit-limit": "5000", "x-frame-options": "deny", "content-type": "application/json; charset=utf-8", "x-ratelimit-reset": "1454161385"}, "status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/github3py/test_rename1/import/issues?per_page=100"}, "recorded_at": "2016-01-30T13:19:55"}], "recorded_with": "betamax/0.5.0"}
13 changes: 13 additions & 0 deletions tests/integration/test_repos_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,19 @@ def test_imported_issue(self):
assert isinstance(imported_issue,
github3.repos.issue_import.ImportedIssue)

def test_imported_issues(self):
"""Test the ability to retrieve imported issues."""
self.token_login()
cassette_name = self.cassette_name('imported_issues')
with self.recorder.use_cassette(cassette_name):
repository = self.gh.repository('github3py', 'test_rename1')
imported_issues = list(repository.imported_issues())

assert len(imported_issues) > 0
for imported_issue in imported_issues:
assert isinstance(imported_issue,
github3.repos.issue_import.ImportedIssue)

def test_import_issue(self):
"""Test the ability to import an issue."""
self.token_login()
Expand Down
19 changes: 19 additions & 0 deletions tests/unit/test_repos_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,19 @@ def test_hooks(self):
headers={}
)

def test_imported_issues(self):
"""Verify the request for retreiving imported issues."""
i = self.instance.imported_issues(since='2015-03-15')
self.get_next(i)

self.session.get.assert_called_once_with(
url_for('import/issues'),
params={'per_page': 100, 'since': '2015-03-15'},
headers={
'Accept': 'application/vnd.github.golden-comet-preview+json'
}
)

def test_issue_events(self):
"""Test the ability to iterate over a repository's issue events."""
i = self.instance.issue_events()
Expand Down Expand Up @@ -1504,6 +1517,12 @@ def test_import_issue(self):
body='Foobar body',
created_at='2014-03-16T17:15:42Z')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Take a look at this timestamp for your unit test above. It doesn't have to be this exact one, but it should be in this format.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nevermind :)


def test_imported_issues(self):
"""
Show that a user must be authenticated to retrieve imported issues.
"""
self.assert_requires_auth(self.instance.imported_issues)

def test_imported_issue(self):
"""
Show that a user must be authenticated to retrieve an imported issue.
Expand Down
0