Skip to content

Commit ea2cb7a

Browse files
rco-abletonsigmavirus24
authored andcommitted
Add project card method to GitHub class
The Projects API allows a user to fetch a project card directly, without reference to an organisation or repository. This commit exposes this ability by adding a `project_card()` method to the `GitHub` class. Callers may obtain any project card to which they have access by calling this method directly: import github3 card = github3.login(token='token').project_card(1234)
1 parent 3507600 commit ea2cb7a

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

github3/github.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from .issues import Issue, issue_params
1919
from .models import GitHubCore
2020
from .orgs import Membership, Organization, Team
21-
from .projects import Project, ProjectColumn
21+
from .projects import Project, ProjectCard, ProjectColumn
2222
from .pulls import PullRequest
2323
from .repos.repo import Repository, repo_issue_params
2424
from .search import (CodeSearchResult, IssueSearchResult,
@@ -961,6 +961,20 @@ def project(self, number):
961961
url, headers=Project.CUSTOM_HEADERS), 200)
962962
return self._instance_or_null(Project, json)
963963

964+
def project_card(self, number):
965+
"""Return the ProjectCard with id ``number``.
966+
967+
:param int number: id of the project card
968+
:returns: :class:`ProjectCard <github3.projects.ProjectCard>`
969+
"""
970+
number = int(number)
971+
json = None
972+
if number > 0:
973+
url = self._build_url('projects', 'columns', 'cards', str(number))
974+
json = self._json(self._get(
975+
url, headers=Project.CUSTOM_HEADERS), 200)
976+
return self._instance_or_null(ProjectCard, json)
977+
964978
def project_column(self, number):
965979
"""Return the ProjectColumn with id ``number``.
966980
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"http_interactions": [{"response": {"headers": {"Cache-Control": "private, max-age=60, s-maxage=60", "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload", "Vary": "Accept, Authorization, Cookie, X-GitHub-OTP", "Access-Control-Allow-Origin": "*", "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-RateLimit-Remaining": "4997", "X-GitHub-Media-Type": "github.inertia-preview; format=json", "X-Frame-Options": "deny", "Transfer-Encoding": "chunked", "X-GitHub-Request-Id": "EEAB:19D9:CCC5BB:FF8C2C:5901BD97", "X-RateLimit-Reset": "1493287993", "Server": "GitHub.com", "X-Content-Type-Options": "nosniff", "X-XSS-Protection": "1; mode=block", "ETag": "W/\"a3a56ae9062bae7ec43db58aec2e350e\"", "X-Served-By": "15bc4ab707db6d6b474783868c7cc828", "Content-Security-Policy": "default-src 'none'", "X-RateLimit-Limit": "5000", "X-Accepted-OAuth-Scopes": "repo", "Content-Type": "application/json; charset=utf-8", "Status": "200 OK", "X-OAuth-Scopes": "repo, user:email", "Content-Encoding": "gzip", "Date": "Thu, 27 Apr 2017 09:44:56 GMT"}, "body": {"string": "", "base64_string": "H4sIAA++AVkC/52TQW6DMBBF7+J1EgcINEGqeol2003kgAOujI3sMRFF3L1jQqOWSqnilSVr3uMz8AfijCQ5qQFam1PKWrGpBNTutCl0Q1ujP3gBlhZaukbhyUxpaZxl6T7NyIpc74+PSbLD/nDYIS1Kks+uFVEaOMmVkxK1hjPQhuQDkboSCuUFU8z0a3aSHLSa4SjZJkkUpSvCOgbMLINMlzae0zjLTaEVcAVTMEe/+ZfuOUFlZWaNdxO8uPteXuc3sshVQyMXOX5Af8bPWkp9QdPx4YfRG3vzCFUFe5AdqIaa4xpxavQLERZCgk3cMB24S2+yuFbDywDXTGK0i8JUAzW81ZPSnWxhRAtCq5CQv3j0aVMxJT5ZqA95r/HxQvCJQ553+H+GCK7ggH0THSv6ccpScNHh2oOlCwM6oW+xp+QNp/1HEMCPrGx8R89MWj7O7UWEAc7F2+hpvd2t4+w1SvIkwcK/+2a15b8zc1fvp57WRq2oGtYJ42y8m+uWbNqeCmsdtzQl4xesaEK26gQAAA==", "encoding": "utf-8"}, "url": "https://api.github.com/projects/columns/cards/2665856", "status": {"message": "OK", "code": 200}}, "request": {"method": "GET", "body": {"string": "", "encoding": "utf-8"}, "headers": {"Accept": "application/vnd.github.inertia-preview+json", "Content-Type": "application/json", "Connection": "keep-alive", "Accept-Encoding": "gzip, deflate", "Accept-Charset": "utf-8", "Authorization": "token <AUTH_TOKEN>", "User-Agent": "github3.py/1.0.0a4"}, "uri": "https://api.github.com/projects/columns/cards/2665856"}, "recorded_at": "2017-04-27T09:44:59"}], "recorded_with": "betamax/0.8.0"}

tests/integration/test_github.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,15 @@ def test_project(self):
368368

369369
assert isinstance(r, github3.projects.Project)
370370

371+
def test_project_card(self):
372+
"""Test the ability to retrieve a project card by its id."""
373+
self.token_login()
374+
cassette_name = self.cassette_name('project_card')
375+
with self.recorder.use_cassette(cassette_name):
376+
r = self.gh.project_card(2665856)
377+
378+
assert isinstance(r, github3.projects.ProjectCard)
379+
371380
def test_project_column(self):
372381
"""Test the ability to retrieve a project column by its id."""
373382
self.token_login()

tests/unit/test_github.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,15 @@ def test_project(self):
407407
headers=Project.CUSTOM_HEADERS
408408
)
409409

410+
def test_project_card(self):
411+
"""Test the ability to retrieve a project card by its id."""
412+
self.instance.project_card(2665856)
413+
414+
self.session.get.assert_called_once_with(
415+
url_for('projects/columns/cards/2665856'),
416+
headers=Project.CUSTOM_HEADERS
417+
)
418+
410419
def test_project_column(self):
411420
"""Test the ability to retrieve a project column by its id."""
412421
self.instance.project_column(957217)

0 commit comments

Comments
 (0)