8000 Add fetching and iterating Projects from Repos · pythonthings/github3.py@5623770 · GitHub
[go: up one dir, main page]

Skip to content

Commit 5623770

Browse files
rco-abletonsigmavirus24
authored andcommitted
Add fetching and iterating Projects from Repos
1 parent 94fa475 commit 5623770

File tree

5 files changed

+71
-0
lines changed

5 files changed

+71
-0
lines changed

github3/repos/repo.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1773,6 +1773,35 @@ def pages_builds(self, number=-1, etag=None):
17731773
url = self._build_url('pages', 'builds', base_url=self._api)
17741774
return self._iter(int(number), url, PagesBuild, etag=etag)
17751775

1776+
def project(self, id, etag=None):
1777+
"""Return the organization project with the given ID.
1778+
1779+
:param int id: (required), ID number of the project
1780+
:returns: :class:`Project <github3.projects.Project>` if successful,
1781+
otherwise None
1782+
"""
1783+
url = self._build_url('projects', id, base_url=self._github_url)
1784+
json = self._json(self._get(url, headers=Project.CUSTOM_HEADERS), 200)
1785+
return self._instance_or_null(Project, json)
1786+
1787+
def projects(self, number=-1, etag=None):
1788+
"""Iterate over projects for this organization.
1789+
1790+
:param int number: (optional), number of members to return. Default:
1791+
-1 will return all available.
1792+
:param str etag: (optional), ETag from a previous request to the same
1793+
endpoint
1794+
:returns: generator of :class:`Project <github3.projects.Project>`
1795+
"""
1796+
url = self._build_url('projects', base_url=self._api)
1797+
return self._iter(
1798+
int(number),
1799+
url,
1800+
Project,
1801+
etag=etag,
1802+
headers=Project.CUSTOM_HEADERS
1803+
)
1804+
17761805
def pull_request(self, number):
17771806
"""Get the pull request indicated by ``number``.
17781807
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"recorded_with": "betamax/0.8.0", "http_interactions": [{"recorded_at": "2017-02-21T12:48:01", "response": {"status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py", "headers": {"ETag": "W/\"f2528211d57d91b73858bae183c81d71\"", "Cache-Control": "private, max-age=60, s-maxage=60", "X-OAuth-Scopes": "repo", "X-RateLimit-Remaining": "4984", "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", "X-Frame-Options": "deny", "X-Served-By": "a474937f3b2fa272558fa6dc951018ad", "Content-Security-Policy": "default-src 'none'", "X-Accepted-OAuth-Scopes": "repo", "Server": "GitHub.com", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Content-Encoding": "gzip", "Transfer-Encoding": "chunked", "X-RateLimit-Limit": "5000", "Date": "Tue, 21 Feb 2017 12:47:50 GMT", "X-RateLimit-Reset": "1487683933", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "Status": "200 OK", "X-Content-Type-Options": "nosniff", "X-GitHub-Media-Type": "github.drax-preview; format=json", "Access-Control-Allow-Origin": "*", "Last-Modified": "Tue, 15 Nov 2016 14:09:50 GMT", "Content-Type": "application/json; charset=utf-8", "X-GitHub-Request-Id": "F609:7032:B626E30:E311820:58AC36F6", "X-XSS-Protection": "1; mode=block"}, "body": {"string": "", "base64_string": "H4sIAMo3rFgC/+2YwW7jOAxAfyXwddM4bmaaHQODmf2CvexpLoFsM7ZQWRIkOdlUyL8vJcuOHQzSpuphDwWK1JHFJ4YiKVI2oVWSbzd/Zt+2m+0y4aSFJE9qapqu2KzkKVkm+46xXXihad2SA1WdfvySzmaJIweV5DZhoqb8aiq+d+tkm6cn/MuWCTkQQ9SuUwxnNsZInadpP6hXPbfToErBDXCzKkWbdukg/uPwfYPEWgWKQyc4cEWTNJB6ccTp9EqpxrTsSomJyNXkvWBMHJGyu3OhdJQcKZTX76SgpE2FaQCth3POzhBUm/uV8lLW/0MLOo5GYyqo7iYFOVTL+cDZpgqk8MCu0KWi0lDB71dwJu08TNWE0xfyPhpKO4hT7X5hL4XScEBvvF+8F7OpVPRAytPZ61ECPaCx34m8kkeiOUkXoX9PrOS2gBrYkap1IbknTMN5mXg1DE42qoN7gmAe8RWM24Oify0kIyUs9kItFOGVaBfwrwRFW6ffAkcWWiwEX/kYUM9BnVei1hv+hg6O9IrxbiJSD0DQM5yiOE7eus8QSyUGKymEIkaoKPAMZGdf3ToGSBvF9wCXCoWIs6QHuESvdQdvcuvbPM/RY+zwri36dBePHmOGaJzCAaJoI8SmQ0YuMALKJg47MGx48rtN6rjNJj4JFkwUURx8TD3Eproh/RlkdrHaOapjzKAK9tFQxxihRkXut1dT+f0OSDwADW59FHVgpDZAGeF1R+o46ggJx3tNXkDF6hkoPstxo2jRxSe5C+dSNxSxql4wV8XIB1BlOGBRoKUm8td7xMztPwDr/PQa7b7HZs+BMc3JfdIPbz4g6/9ujdAMRDuaY6T2D0lME0wiiYJIizhEaguCBdZqtbINEF8GtKAiI7gnuLNKlQ1WfDEsOzCw6mmJ8ZX63qlZYeXOBKmiNB0hgz98wPE/3X+JfWgU0gOmxJYy0EbwyB0aKVM2F4buafmWbuU2fgayPzTlJSwJY0t0OUNLin6MPWF/YhTAIo8LR8Cfgd1+36UwIJEH28CwaV8ZVyCZOEVnoQnGBbEC7GiqHTHIe1xnTw9Z9pB9/Sf7kq+/5V/Xv9z1gKxenSM73UymbB/Wj37KY77Z5tn2V8jOvd749KZeyf0odwDp5iL48yKW3xYrGbrW3f3ZsOaBv6e1a0QLEsuGJOcYM66LfMHnbFZDlKLjaKb1MjkSg4XqbGioOwZAQ/Suj+ix68SRS8aYDB7pM51+l758GbrFvuG7LNRSpUS4SOqXEhJ4WGuYlwU5LzF5798M2vuXFexJx8yuL7nRbC3RBpTzDFAtSvm7iNwmoaXu1XRec3lmrH/GTpvRErgerTC9wfi8Kvu8Kvu8Kvu/X5VxMEfMHJOEM+1Nwujm/B8QxoEPRxcAAA==", "encoding": "utf-8"}}, "request": {"body": {"string": "", "encoding": "utf-8"}, "uri": "https://api.github.com/repos/sigmavirus24/github3.py", "headers": {"Connection": "keep-alive", "Authorization": "token <AUTH_TOKEN>", "User-Agent": "github3.py/1.0.0a4", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.drax-preview+json"}, "method": "GET"}}, {"recorded_at": "2017-02-21T12:48:01", "response": {"status": {"message": "OK", "code": 200}, "url": "https://api.github.com/projects/400543", "headers": {"ETag": "W/\"fe4445a06df053c8aa5bf75d885784e1\"", "Cache-Control": "private, max-age=60, s-maxage=60", "X-OAuth-Scopes": "repo", "X-RateLimit-Remaining": "4983", "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", "X-Frame-Options": "deny", "Content-Security-Policy": "default-src 'none'", "X-Accepted-OAuth-Scopes": "repo", "Server": "GitHub.com", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Content-Encoding": "gzip", "Transfer-Encoding": "chunked", "X-RateLimit-Limit": "5000", "Date": "Tue, 21 Feb 2017 12:47:50 GMT", "X-RateLimit-Reset": "1487683933", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "Status": "200 OK", "X-Content-Type-Options": "nosniff", "X-GitHub-Media-Type": "github.inertia-preview; format=json", "Access-Control-Allow-Origin": "*", "X-Served-By": "4537b68c46a1b65b106078b0a2578ee2", "Content-Type": "application/json; charset=utf-8", "X-GitHub-Request-Id": "F609:7032:B626E56:E31184A:58AC36F6", "X-XSS-Protection": "1; mode=block"}, "body": {"string": "", "base64_string": "H4sIAMo3rFgC/52T326DIBTGX2Xhui3+a7qZLHuJ7WY3BpUqCwKBo40zvvsO1DVrl2yxVxr4fh8fh3Mmok+K26K3kuSkBTAup5QZsWsEtH25q3RHLTfaUSeajg3C9i7J6Hk33ZmRbMifsLH6g1fgaBZF+yxFeaVl3ylXrMHoAiEuapKfFzdEsY6jB3AHDwuBilLXI67in+q7klvUb4gDBl6rDVc+hOUMNG5NROpGKNyxld6yUnLQajkmjpNDGj8dNoQNDNivMoVFly65e8fRQgFXEK7Q02/+ZXj2F2/sYuO9yX+F83aOXodqoZM3IX6+05X2qKXUJ/Qo1h1DL+DFRKjmPhMEJ6qh9R2GktkXQThYHSlAU/hg8bwNPqe1vF5rtGAYyrf9PIXeDn596SorDAitVse7gtFM24Yp8cnuMkPYe4ShW8sGCGE+YBOups/UhLMnBlaNc0hRcTFgne9zvMHREEbjp/ANpb7qAnjB6s7P35FJx+dlMhFhgLokig/bKNkm8Wuc5Nk+jx/f/eCY+h/N/AVmEixJ2gQAAA==", "encoding": "utf-8"}}, "request": {"body": {"string": "", "encoding": "utf-8"}, "uri": "https://api.github.com/projects/400543", "headers": {"Connection": "keep-alive", "Authorization": "token <AUTH_TOKEN>", "User-Agent": "github3.py/1.0.0a4", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.inertia-preview+json"}, "method": "GET"}}]}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"recorded_with": "betamax/0.8.0", "http_interactions": [{"recorded_at": "2017-02-21T12:48:01", "response": {"status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py", "headers": {"ETag": "W/\"f2528211d57d91b73858bae183c81d71\"", "Cache-Control": "private, max-age=60, s-maxage=60", "X-OAuth-Scopes": "repo", "X-RateLimit-Remaining": "4982", "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", "X-Frame-Options": "deny", "X-Served-By": "626ed3a9050b8faa02ef5f3c540b508d", "Content-Security-Policy": "default-src 'none'", "X-Accepted-OAuth-Scopes": "repo", "Server": "GitHub.com", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Content-Encoding": "gzip", "Transfer-Encoding": "chunked", "X-RateLimit-Limit": "5000", "Date": "Tue, 21 Feb 2017 12:47:51 GMT", "X-RateLimit-Reset": "1487683933", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "Status": "200 OK", "X-Content-Type-Options": "nosniff", "X-GitHub-Media-Type": "github.drax-preview; format=json", "Access-Control-Allow-Origin": "*", "Last-Modified": "Tue, 15 Nov 2016 14:09:50 GMT", "Content-Type": "application/json; charset=utf-8", "X-GitHub-Request-Id": "F60A:7031:3EC8718:4EEE893:58AC36F7", "X-XSS-Protection": "1; mode=block"}, "body": {"string": "", "base64_string": "H4sIAMo3rFgC/+2YwW7jOAxAfyXwddM4bmaaHQODmf2CvexpLoFsM7ZQWRIkOdlUyL8vJcuOHQzSpuphDwWK1JHFJ4YiKVI2oVWSbzd/Zt+2m+0y4aSFJE9qapqu2KzkKVkm+46xXXihad2SA1WdfvySzmaJIweV5DZhoqb8aiq+d+tkm6cn/MuWCTkQQ9SuUwxnNsZInadpP6hXPbfToErBDXCzKkWbdukg/uPwfYPEWgWKQyc4cEWTNJB6ccTp9EqpxrTsSomJyNXkvWBMHJGyu3OhdJQcKZTX76SgpE2FaQCth3POzhBUm/uV8lLW/0MLOo5GYyqo7iYFOVTL+cDZpgqk8MCu0KWi0lDB71dwJu08TNWE0xfyPhpKO4hT7X5hL4XScEBvvF+8F7OpVPRAytPZ61ECPaCx34m8kkeiOUkXoX9PrOS2gBrYkap1IbknTMN5mXg1DE42qoN7gmAe8RWM24Oify0kIyUs9kItFOGVaBfwrwRFW6ffAkcWWiwEX/kYUM9BnVei1hv+hg6O9IrxbiJSD0DQM5yiOE7eus8QSyUGKymEIkaoKPAMZGdf3ToGSBvF9wCXCoWIs6QHuESvdQdvcuvbPM/RY+zwri36dBePHmOGaJzCAaJoI8SmQ0YuMALKJg47MGx48rtN6rjNJj4JFkwUURx8TD3Eproh/RlkdrHaOapjzKAK9tFQxxihRkXut1dT+f0OSDwADW59FHVgpDZAGeF1R+o46ggJx3tNXkDF6hkoPstxo2jRxSe5C+dSNxSxql4wV8XIB1BlOGBRoKUm8td7xMztPwDr/PQa7b7HZs+BMc3JfdIPbz4g6/9ujdAMRDuaY6T2D0lME0wiiYJIizhEaguCBdZqtbINEF8GtKAiI7gnuLNKlQ1WfDEsOzCw6mmJ8ZX63qlZYeXOBKmiNB0hgz98wPE/3X+JfWgU0gOmxJYy0EbwyB0aKVM2F4buafmWbuU2fgayPzTlJSwJY0t0OUNLin6MPWF/YhTAIo8LR8Cfgd1+36UwIJEH28CwaV8ZVyCZOEVnoQnGBbEC7GiqHTHIe1xnTw9Z9pB9/Sf7kq+/5V/Xv9z1gKxenSM73UymbB/Wj37KY77Z5tn2V8jOvd749KZeyf0odwDp5iL48yKW3xYrGbrW3f3ZsOaBv6e1a0QLEsuGJOcYM66LfMHnbFZDlKLjaKb1MjkSg4XqbGioOwZAQ/Suj+ix68SRS8aYDB7pM51+l758GbrFvuG7LNRSpUS4SOqXEhJ4WGuYlwU5LzF5798M2vuXFexJx8yuL7nRbC3RBpTzDFAtSvm7iNwmoaXu1XRec3lmrH/GTpvRErgerTC9wfi8Kvu8Kvu8Kvu/X5VxMEfMHJOEM+1Nwujm/B8QxoEPRxcAAA==", "encoding": "utf-8"}}, "request": {"body": {"string": "", "encoding": "utf-8"}, "uri": "https://api.github.com/repos/sigmavirus24/github3.py", "headers": {"Connection": "keep-alive", "Authorization": "token <AUTH_TOKEN>", "User-Agent": "github3.py/1.0.0a4", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.drax-preview+json"}, "method": "GET"}}, {"recorded_at": "2017-02-21T12:48:02", "response": {"status": {"message": "OK", "code": 200}, "url": "https://api.github.com/repos/sigmavirus24/github3.py/projects?per_page=100", "headers": {"ETag": "W/\"12abf327f9c5afd7a42b389c5f219d9a\"", "Cache-Control": "private, max-age=60, s-maxage=60", "X-OAuth-Scopes": "repo", "X-RateLimit-Remaining": "4981", "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", "X-Frame-Options": "deny", "Content-Security-Policy": "default-src 'none'", "X-Accepted-OAuth-Scopes": "repo", "Server": "GitHub.com", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Content-Encoding": "gzip", "Transfer-Encoding": "chunked", "X-RateLimit-Limit": "5000", "Date": "Tue, 21 Feb 2017 12:47:51 GMT", "X-RateLimit-Reset": "1487683933", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "Status": "200 OK", "X-Content-Type-Options": "nosniff", "X-GitHub-Media-Type": "github.inertia-preview; format=json", "Access-Control-Allow-Origin": "*", "X-Served-By": "2c18a09f3ac5e4dd1e004af7c5a94769", "Content-Type": "application/json; charset=utf-8", "X-GitHub-Request-Id": "F60A:7031:3EC8720:4EEE898:58AC36F7", "X-XSS-Protection": "1; mode=block"}, "body": {"string": "", "base64_string": "H4sIAMo3rFgC/52T306DMBTGX8X0mq38W6YkxpfQG40hBTqogbZpDyxIeHdPO1zcTDTsCtJ+v69fT895m4g6Sm7y3rQkIw2AthmlTIttLaDpi22pOmq4VpZaUXdsEKa3cUpPu8lWjyQgf8LaqA9egqVpGO7SBOWlavtO2nwNRhcIcVGR7LQYEMk6jh7ALdwtBCoKVY24in+y7wpuUB8QCwycVmkuXQjDGSjcmkiraiFxx5Rqw4qWg5LLMVEU75PoYR8QNjBgv8rkF22y5O4tRwsJXIK/Qk+/+afh0V28NouN8yb/Fc7ZWXoZqoGuvQrx850utAfVtuqIHvm6Y+gZPJsIWd9mguBEFTSuw1AyuyIIC6sjeWjyHyyes8HnNIZXa40WDEO5tp8n39very9saYQGoeTqeBcwmilTMyk+2U1mCDsPP3RrWQ8hzAdswtX0iZpw9sTAynH2KUouBqzzbY5XOBrCqN0UvqDUVV0Az1nVufk7sNbyeZlMRBigLg6j/SaMN3H0HMVZusui+1c3OLr6RzO/fwE0XxgK3AQAAA==", "encoding": "utf-8"}}, "request": {"body": {"string": "", "encoding": "utf-8"}, "uri": "https://api.github.com/repos/sigmavirus24/github3.py/projects?per_page=100", "headers": {"Connection": "keep-alive", "Authorization": "token <AUTH_TOKEN>", "User-Agent": "github3.py/1.0.0a4", "Accept-Charset": "utf-8", "Content-Type": "application/json", "Accept-Encoding": "gzip, deflate", "Accept": "application/vnd.github.inertia-preview+json"}, "method": "GET"}}]}

tests/integration/test_repos_repo.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ def test_branches(self):
5757
for branch in repository.branches():
5858
assert isinstance(branch, github3.repos.branch.Branch)
5959

60+
def test_project(self):
61+
"""Test the ability to retrieve a single repository project."""
62+
self.token_login()
63+
cassette_name = self.cassette_name('project')
64+
with self.recorder.use_cassette(cassette_name):
65+
repository = self.gh.repository('sigmavirus24', 'github3.py')
66+
assert repository is not None
67+
project = repository.project(400543)
68+
assert isinstance(project, github3.projects.Project)
69+
70+
def test_projects(self):
71+
"""Test the ability to retrieve an repository's projects."""
72+
self.token_login()
73+
cassette_name = self.cassette_name('projects')
74+
with self.recorder.use_cassette(cassette_name):
75+
repository = self.gh.repository('sigmavirus24', 'github3.py')
76+
assert repository is not None
77+
for project in repository.projects():
78+
assert isinstance(project, github3.projects.Project)
79+
6080
def test_protected_branches(self):
6181
"""Test the ability to retrieve protected branches in a repository."""
6282
cassette_name = self.cassette_name('branches_protected')

tests/unit/test_repos_repo.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,15 @@ def test_permission(self):
888888
}
889889
assert self.instance.permissions == permissions
890890

891+
def test_project(self):
892+
"""Show that a user can access a single repository project."""
893+
self.instance.project(400435)
894+
895+
self.session.get.assert_called_once_with(
896+
'https://api.github.com/projects/400435',
897+
headers=Project.CUSTOM_HEADERS
898+
)
899+
891900
def test_pull_request(self):
892901
"""Verify the request for retrieving a pull request."""
893902
self.instance.pull_request(1)
@@ -1318,6 +1327,17 @@ def test_pages_builds(self):
13181327
headers={}
13191328
)
13201329

1330+
def test_projects(self):
1331+
"""Show that a user can access all repository projects."""
1332+
i = self.instance.projects()
1333+
self.get_next(i)
1334+
1335+
self.session.get.assert_called_once_with(
1336+
url_for('projects'),
1337+
params={'per_page': 100},
1338+
headers=Project.CUSTOM_HEADERS
1339+
)
1340+
13211341
def test_pull_requests(self):
13221342
"""Test the request for the retrieving pull requests."""
13231343
i = self.instance.pull_requests()

0 commit comments

Comments
 (0)
0