Skip to content

Commit

Permalink
Add create/list commit comment func (#39)
Browse files Browse the repository at this point in the history
* Add create/list commit comment func

* Bump version

Co-authored-by: wangqiang <[email protected]>
  • Loading branch information
dispensable and wangqiang authored Nov 9, 2020
1 parent 831b1cc commit 4351c09
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
18 changes: 17 additions & 1 deletion sa_tools_core/libs/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@

logger = logging.getLogger(__name__)

github_secret_func = lambda: get_config('github')

def github_secret_func():
return get_config('github')


class GithubRepo:
def __init__(self, org, repo, entrypoint=None,
Expand Down Expand Up @@ -192,6 +195,18 @@ def add_collaborator(self, username, permission=None):
def remove_collaborator(self, username):
self.make_request('DELETE', f"/repos/{self.org}/{self.repo}/collaborators/{username}")

def create_commit_comment(self, commit_sha, comment_content, path=None, position=None):
comment = {'body': comment_content}
if path:
comment['path'] = path
if position:
comment['position'] = position
return self.make_request('POST', f"/repos/{self.org}/{self.repo}/commits/{commit_sha}/comments",
data=json.dumps(comment))

def list_commit_comments(self, commit_sha):
return self.make_request('GET', f"/repos/{self.org}/{self.repo}/commits/{commit_sha}/comments")

# high level api starts here
def add(self, files, base_reference):
"""add files to the tree, generate a tree , store the tree_sha to self.head_tree"""
Expand Down Expand Up @@ -311,6 +326,7 @@ def ensure_collaborator(self, username, permission=None):
self.remove_collaborator(username)
self.add_collaborator(username, permission=permission)


def commit_github(org, repo, branch, files, message, retry=2):
"""update files of a repo on a branch head.
::params:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from io import open
from setuptools import setup, find_packages

version = '0.3.3'
version = '0.3.4'

requirements = [
'setuptools',
Expand Down

0 comments on commit 4351c09

Please sign in to comment.