1
0
Fork 0

Use argparse, move github auth logic temporarily in main()

This commit is contained in:
Félix Piédallu 2024-02-10 13:54:36 +01:00
parent 0af4cc2148
commit b5af26a872

View file

@ -1,5 +1,6 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import argparse
import glob import glob
import hashlib import hashlib
import os import os
@ -27,31 +28,12 @@ STRATEGIES = [
"latest_forgejo_commit" "latest_forgejo_commit"
] ]
if "--commit-and-create-PR" not in sys.argv: dry_run = True
dry_run = True
else:
dry_run = False
args = [arg for arg in sys.argv[1:] if arg != "--commit-and-create-PR"] # For github authentication
auth = None
if len(args): github = None
auth = None author = None
else:
GITHUB_LOGIN = (
open(os.path.dirname(__file__) + "/../../.github_login").read().strip()
)
GITHUB_TOKEN = (
open(os.path.dirname(__file__) + "/../../.github_token").read().strip()
)
GITHUB_EMAIL = (
open(os.path.dirname(__file__) + "/../../.github_email").read().strip()
)
from github import Github, InputGitAuthor
auth = (GITHUB_LOGIN, GITHUB_TOKEN)
github = Github(GITHUB_TOKEN)
author = InputGitAuthor(GITHUB_LOGIN, GITHUB_EMAIL)
def apps_to_run_auto_update_for(): def apps_to_run_auto_update_for():
@ -485,11 +467,33 @@ def paste_on_haste(data):
def main() -> None: def main() -> None:
args = [arg for arg in sys.argv[1:] if arg != "--commit-and-create-PR"] parser = argparse.ArgumentParser()
parser.add_argument("app_dir", nargs="?", type=str)
parser.add_argument("--commit-and-create-PR", action="store_true")
args = parser.parse_args()
if len(args): global dry_run, auth, github, author
AppAutoUpdater(args[0], app_id_is_local_app_dir=True).run() dry_run = args.commit_and_create_PR
if args.app_dir:
AppAutoUpdater(args.app_dir, app_id_is_local_app_dir=True).run()
else: else:
GITHUB_LOGIN = (
open(os.path.dirname(__file__) + "/../../.github_login").read().strip()
)
GITHUB_TOKEN = (
open(os.path.dirname(__file__) + "/../../.github_token").read().strip()
)
GITHUB_EMAIL = (
open(os.path.dirname(__file__) + "/../../.github_email").read().strip()
)
from github import Github, InputGitAuthor
auth = (GITHUB_LOGIN, GITHUB_TOKEN)
github = Github(GITHUB_TOKEN)
author = InputGitAuthor(GITHUB_LOGIN, GITHUB_EMAIL)
apps_failed = [] apps_failed = []
apps_failed_details = {} apps_failed_details = {}
apps_updated = [] apps_updated = []