2023-08-30 17:00:29 +00:00
|
|
|
import subprocess
|
|
|
|
from argparse import Namespace, ArgumentParser
|
|
|
|
|
|
|
|
from ryujinx_mako._const import NAME, GH_BOT_SUFFIX, GH_EMAIL_TEMPLATE
|
|
|
|
from ryujinx_mako.commands._subcommand import GithubSubcommand
|
|
|
|
|
|
|
|
|
|
|
|
class SetupGit(GithubSubcommand):
|
|
|
|
@staticmethod
|
|
|
|
def name() -> str:
|
|
|
|
return "setup-git"
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def description() -> str:
|
2024-01-27 19:49:49 +00:00
|
|
|
return f"Configure git identity for {NAME}"
|
2023-08-30 17:00:29 +00:00
|
|
|
|
|
|
|
def __init__(self, parser: ArgumentParser):
|
|
|
|
parser.add_argument(
|
|
|
|
"-l",
|
|
|
|
"--local",
|
|
|
|
action="store_true",
|
2024-01-27 19:49:49 +00:00
|
|
|
help="configure the git identity only for the current repository",
|
2023-08-30 17:00:29 +00:00
|
|
|
)
|
|
|
|
super().__init__(parser)
|
|
|
|
|
|
|
|
def run(self, args: Namespace):
|
|
|
|
base_command = ["git", "config"]
|
|
|
|
gh_username = f"{NAME}{GH_BOT_SUFFIX}"
|
|
|
|
|
|
|
|
self.logger.debug(f"Getting GitHub user for: {gh_username}")
|
|
|
|
user = self.github.get_user(gh_username)
|
2024-01-27 19:49:49 +00:00
|
|
|
email = GH_EMAIL_TEMPLATE.format(user_id=user.id, username=user.login)
|
2023-08-30 17:00:29 +00:00
|
|
|
|
|
|
|
if args.local:
|
|
|
|
self.logger.debug("Setting git identity for local repo...")
|
|
|
|
else:
|
|
|
|
self.logger.debug("Setting git identity globally...")
|
|
|
|
base_command.append("--global")
|
|
|
|
|
2024-01-27 19:49:49 +00:00
|
|
|
config = {"user.name": user.login, "user.email": email}
|
2023-08-30 17:00:29 +00:00
|
|
|
for option, value in config.items():
|
|
|
|
self.logger.info(f"Setting git {option} to: {value}")
|
|
|
|
command = base_command.copy()
|
|
|
|
command.extend([option, value])
|
|
|
|
process = subprocess.run(
|
|
|
|
command, stdout=subprocess.PIPE, stderr=subprocess.PIPE
|
|
|
|
)
|
|
|
|
process.check_returncode()
|
|
|
|
self.logger.info("Success!")
|