Skip to content

Commit fd56be1

Browse files
committed
Add API to get commit properties or check if sha is associated with a commit
1 parent dfb8c83 commit fd56be1

3 files changed

Lines changed: 49 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@ Next Release
44
Features (CLI and Python API)
55
-----------------------------
66

7-
87
* ``release`` command:
98

109
* ``edit``:
1110

1211
* Add ``--publish`` flag having opposite effect of ``--draft``
1312
* Add ``--release`` flag having opposite effect of ``--prerelease``
1413

14+
Python API
15+
----------
16+
17+
* Add ``gh_commit_get`` allowing to commit properties or check if a commit exists.
1518

1619
1.5.6
1720
=====

github_release.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,25 @@ def gh_ref_delete(repo_name, pattern, keep_pattern=None, tags=False,
10251025
return len(removed_refs) > 0
10261026

10271027

1028+
#
1029+
# Commits
1030+
#
1031+
1032+
def gh_commit_get(repo_name, sha):
1033+
try:
1034+
response = _request(
1035+
'GET',
1036+
GITHUB_API + '/repos/{0}/git/commits/{1}'.format(repo_name, sha))
1037+
response.raise_for_status()
1038+
return response.json()
1039+
except requests.exceptions.HTTPError as exc_info:
1040+
response = exc_info.response
1041+
if response.status_code == 404:
1042+
return None
1043+
else:
1044+
raise
1045+
1046+
10281047
#
10291048
# Script entry point
10301049
#

tests/test_integration_commit.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
from . import (
3+
do_commit,
4+
github_token_required,
5+
git_user_email_required,
6+
git_user_name_required,
7+
integration_test_repo_name_required,
8+
push_dir,
9+
REPO_NAME
10+
)
11+
12+
import github_release as ghr
13+
14+
15+
@git_user_email_required
16+
@git_user_name_required
17+
@github_token_required
18+
@integration_test_repo_name_required
19+
def test_get(gh_src_dir):
20+
with push_dir(gh_src_dir):
21+
expected_sha = do_commit(push=True)
22+
response = ghr.gh_commit_get(REPO_NAME, expected_sha)
23+
assert 'sha' in response
24+
assert response['sha'] == expected_sha
25+
26+
assert ghr.gh_commit_get(REPO_NAME, "invalid") is None

0 commit comments

Comments
 (0)