From 4351c09553da394fb8638568918a43e2b024f5b0 Mon Sep 17 00:00:00 2001 From: dispensable Date: Mon, 9 Nov 2020 18:22:45 +0800 Subject: [PATCH] Add create/list commit comment func (#39) * Add create/list commit comment func * Bump version Co-authored-by: wangqiang --- sa_tools_core/libs/github.py | 18 +++++++++++++++++- setup.py | 2 +- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sa_tools_core/libs/github.py b/sa_tools_core/libs/github.py index 56549b3..c739168 100644 --- a/sa_tools_core/libs/github.py +++ b/sa_tools_core/libs/github.py @@ -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, @@ -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""" @@ -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: diff --git a/setup.py b/setup.py index 00dc611..60eab7f 100644 --- a/setup.py +++ b/setup.py @@ -3,7 +3,7 @@ from io import open from setuptools import setup, find_packages -version = '0.3.3' +version = '0.3.4' requirements = [ 'setuptools',