Add generic git to sdk bot
This commit is contained in:
Родитель
94e560903f
Коммит
47bd423b86
|
@ -71,9 +71,9 @@ def pr_message_for_package(sdk_pr, package_name):
|
|||
|
||||
|
||||
class GithubHandler:
|
||||
def __init__(self):
|
||||
def __init__(self, gh_token=None):
|
||||
# I need a token to do PR. Nothing to do with the bot.
|
||||
self.gh_token = os.environ["GH_TOKEN"]
|
||||
self.gh_token = os.environ["GH_TOKEN"] if not gh_token else gh_token
|
||||
|
||||
@order
|
||||
def install(self, issue):
|
||||
|
@ -112,6 +112,31 @@ class GithubHandler:
|
|||
|
||||
return "Rebase done and pushed to the branch"
|
||||
|
||||
@order
|
||||
def git(self, issue, *git_parameters):
|
||||
if not issue.pull_request:
|
||||
return "Rebase is just supported in PR for now"
|
||||
|
||||
pr_obj = issue.repository.get_pull(issue.number)
|
||||
|
||||
branch_name = pr_obj.head.ref
|
||||
branched_sdk_id = pr_obj.head.repo.full_name+'@'+branch_name
|
||||
|
||||
with tempfile.TemporaryDirectory() as temp_dir, \
|
||||
manage_git_folder(self.gh_token, Path(temp_dir) / Path("sdk"), branched_sdk_id) as sdk_folder:
|
||||
|
||||
sdk_repo = Repo(str(sdk_folder))
|
||||
configure_user(self.gh_token, sdk_repo)
|
||||
|
||||
command = getattr(sdk_repo.git, git_parameters[0])
|
||||
initial_answer = command(*git_parameters[1:])
|
||||
_LOGGER.debug(initial_answer)
|
||||
msg = sdk_repo.git.push(force=True)
|
||||
_LOGGER.debug(msg)
|
||||
|
||||
return initial_answer
|
||||
|
||||
|
||||
@order
|
||||
def rebuild(self, issue, project_pattern):
|
||||
if not issue.pull_request:
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
from swaggertosdk.restapi.sdkbot import GithubHandler
|
||||
|
||||
|
||||
def test_sdk_bot_git(github_client, github_token):
|
||||
handler = GithubHandler(github_token)
|
||||
|
||||
repo = github_client.get_repo("lmazuel/TestingRepo")
|
||||
issue = repo.get_issue(11)
|
||||
|
||||
output = handler.git(issue, "show", "2a0c2f0285117ccb07b6f9c32749d6c50abed70b")
|
||||
assert "commit 2a0c2f0285117ccb07b6f9c32749d6c50abed70b" in output
|
Загрузка…
Ссылка в новой задаче