|
29 | 29 | import yaml |
30 | 30 |
|
31 | 31 |
|
32 | | -class GitHub(object): |
| 32 | +class Github(object): |
33 | 33 | """Github service helper class.""" |
34 | 34 |
|
35 | 35 | def __init__(self, config=None, base_url='https://github.com'): |
@@ -484,6 +484,53 @@ def remove_labels(self, repo, issue, *labels): |
484 | 484 | # Each response has all the labels, so only return the last one |
485 | 485 | return response |
486 | 486 |
|
| 487 | + def get_repo_details(self, repo): |
| 488 | + """ |
| 489 | + Retrieve a repository's metadata. |
| 490 | +
|
| 491 | + :param repo: the organization/repository as a string. |
| 492 | +
|
| 493 | + :returns: the repository's metadata details. |
| 494 | + """ |
| 495 | + self.session.headers.update( |
| 496 | + {'Accept': 'application/vnd.github.v3+json'} |
| 497 | + ) |
| 498 | + return self._make_request('get', f'repos/{repo}') |
| 499 | + |
| 500 | + def get_commit_details(self, repo, since): |
| 501 | + """ |
| 502 | + Retrieve a repository's commit details since a given date/time. |
| 503 | +
|
| 504 | + :param repo: the organization/repository as a string. |
| 505 | + :param since: the starting date/time as a datetime. |
| 506 | +
|
| 507 | + :returns: the repository's commit details since a given date/time. |
| 508 | + """ |
| 509 | + self.session.headers.update( |
| 510 | + {'Accept': 'application/vnd.github.v3+json'} |
| 511 | + ) |
| 512 | + return self._make_request( |
| 513 | + 'get', |
| 514 | + f'repos/{repo}/commits', |
| 515 | + params={'since': since.strftime('%Y-%m-%dT%H:%M:%SZ')} |
| 516 | + ) |
| 517 | + |
| 518 | + def get_branch_protection_details(self, repo, branch='master'): |
| 519 | + """ |
| 520 | + Retrieve a repository branch's branch protection details. |
| 521 | +
|
| 522 | + :param repo: the organization/repository as a string. |
| 523 | + :param branch: the branch as a string. |
| 524 | +
|
| 525 | + :returns: the repository branch's branch protection details. |
| 526 | + """ |
| 527 | + self.session.headers.update( |
| 528 | + {'Accept': 'application/vnd.github.luke-cage-preview+json'} |
| 529 | + ) |
| 530 | + return self._make_request( |
| 531 | + 'get', f'repos/{repo}/branches/{branch}/protection' |
| 532 | + ) |
| 533 | + |
487 | 534 | def _make_request(self, method, url, parse=True, **kwargs): |
488 | 535 | r = self.session.request(method, url, **kwargs) |
489 | 536 | r.raise_for_status() |
|
0 commit comments