feat: draft version

This commit is contained in:
2021-01-03 15:10:47 +03:00
parent f003ed21cd
commit 884bc0aa97
19 changed files with 494 additions and 0 deletions

45
src/git.py Normal file
View File

@@ -0,0 +1,45 @@
import logging
import subprocess
import os
import shlex
from src.settings import GIT_PRIVATE_KEY_PATH
_logger = logging.getLogger(__name__)
_logger.addHandler(logging.NullHandler())
os.environ['GIT_SSH_COMMAND'] = f"ssh -i {shlex.quote(GIT_PRIVATE_KEY_PATH)} -o IdentitiesOnly=yes"
def _check_preconditions():
assert subprocess.check_call(["git", "--version"]) == 0
def clone_repo(ssh_url: str, path: str):
subprocess.check_call(["git", "clone", ssh_url, path], stdout=subprocess.DEVNULL)
def create_and_open_branch(repo_path: str, branch_name: str):
subprocess.check_call(
["git", "checkout", "-b", branch_name], cwd=repo_path, stdout=subprocess.DEVNULL
)
def commit_and_push(repo_path: str, commit_message: str):
subprocess.check_call(["git", "add", "."], cwd=repo_path, stdout=subprocess.DEVNULL)
subprocess.check_call(
["git", "commit", "-m", commit_message], cwd=repo_path, stdout=subprocess.DEVNULL
)
branches = subprocess.check_output(
["git", "branch"], cwd=repo_path
).decode("utf-8")
current_branch = next(filter(lambda x: x.startswith("*"), branches.splitlines()))[1:].strip()
_logger.info(f"pushing branch {current_branch} in repo {repo_path}")
subprocess.check_call(
["git", "push", "--set-upstream", "origin", current_branch],
cwd=repo_path,
stdout=subprocess.DEVNULL,
)
_check_preconditions()