Ryujinx-Mako/ryujinx_mako/commands/setup_git.py
TSRBerry 66a1029bd5
Refactor Mako actions, fix setup-git command & add exec-ryujinx-tasks command (#3)
* Create multiple actions to make Mako easier to use

* Add smoke tests for the new actions

* Check if the required env vars aren't empty

* Fix working directory for execute-command

* Fix action_path references

* Fix broken setup_git command

* Add exec-ryujinx-tasks subcommand

* Ensure python and pipx are installed

* Improve help output

* Add required environment variables to README.md

* Add small script to generate subcommand sections automatically

* Adjust help messages for ryujinx tasks as well

* Remove required argument for positionals

* Add exec-ryujinx-tasks to subcommands list

* Apply black formatting

* Fix event name for update-reviewers
2024-01-27 20:49:49 +01:00

49 lines
1.6 KiB
Python

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:
return f"Configure git identity for {NAME}"
def __init__(self, parser: ArgumentParser):
parser.add_argument(
"-l",
"--local",
action="store_true",
help="configure the git identity only for the current repository",
)
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)
email = GH_EMAIL_TEMPLATE.format(user_id=user.id, username=user.login)
if args.local:
self.logger.debug("Setting git identity for local repo...")
else:
self.logger.debug("Setting git identity globally...")
base_command.append("--global")
config = {"user.name": user.login, "user.email": email}
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!")