🎨 Format Python code with Black
This commit is contained in:
committed by
github-actions[bot]
parent
318a1f6a93
commit
1e969d51a9
@ -7,7 +7,9 @@ import sys
|
||||
|
||||
import requests
|
||||
|
||||
catalog = requests.get("https://raw.githubusercontent.com/YunoHost/apps/master/apps.json").json()
|
||||
catalog = requests.get(
|
||||
"https://raw.githubusercontent.com/YunoHost/apps/master/apps.json"
|
||||
).json()
|
||||
|
||||
my_env = os.environ.copy()
|
||||
my_env["GIT_TERMINAL_PROMPT"] = "0"
|
||||
@ -44,15 +46,19 @@ def git(cmd, in_folder=None):
|
||||
def progressbar(it, prefix="", size=60, file=sys.stdout):
|
||||
it = list(it)
|
||||
count = len(it)
|
||||
|
||||
def show(j, name=""):
|
||||
name += " "
|
||||
x = int(size*j/count)
|
||||
file.write("%s[%s%s] %i/%i %s\r" % (prefix, "#"*x, "."*(size-x), j, count, name))
|
||||
x = int(size * j / count)
|
||||
file.write(
|
||||
"%s[%s%s] %i/%i %s\r" % (prefix, "#" * x, "." * (size - x), j, count, name)
|
||||
)
|
||||
file.flush()
|
||||
|
||||
show(0)
|
||||
for i, item in enumerate(it):
|
||||
yield item
|
||||
show(i+1, item["id"])
|
||||
show(i + 1, item["id"])
|
||||
file.write("\n")
|
||||
file.flush()
|
||||
|
||||
@ -63,7 +69,10 @@ def build_cache():
|
||||
folder = os.path.join(".apps_cache", app["id"])
|
||||
reponame = app["url"].rsplit("/", 1)[-1]
|
||||
git(f"clone --quiet --depth 1 --single-branch {app['url']} {folder}")
|
||||
git(f"remote add fork https://{login}:{token}@github.com/{login}/{reponame}", in_folder=folder)
|
||||
git(
|
||||
f"remote add fork https://{login}:{token}@github.com/{login}/{reponame}",
|
||||
in_folder=folder,
|
||||
)
|
||||
|
||||
|
||||
def apply(patch):
|
||||
@ -81,7 +90,11 @@ def diff():
|
||||
|
||||
for app in apps():
|
||||
folder = os.path.join(".apps_cache", app["id"])
|
||||
if bool(subprocess.check_output(f"cd {folder} && git diff", shell=True).strip().decode("utf-8")):
|
||||
if bool(
|
||||
subprocess.check_output(f"cd {folder} && git diff", shell=True)
|
||||
.strip()
|
||||
.decode("utf-8")
|
||||
):
|
||||
print("\n\n\n")
|
||||
print("=================================")
|
||||
print("Changes in : " + app["id"])
|
||||
@ -92,35 +105,50 @@ def diff():
|
||||
|
||||
def push(patch):
|
||||
|
||||
title = "[autopatch] " + open(os.path.join("patches", patch, "pr_title.md")).read().strip()
|
||||
title = (
|
||||
"[autopatch] "
|
||||
+ open(os.path.join("patches", patch, "pr_title.md")).read().strip()
|
||||
)
|
||||
|
||||
def diff_not_empty(app):
|
||||
folder = os.path.join(".apps_cache", app["id"])
|
||||
return bool(subprocess.check_output(f"cd {folder} && git diff", shell=True).strip().decode("utf-8"))
|
||||
return bool(
|
||||
subprocess.check_output(f"cd {folder} && git diff", shell=True)
|
||||
.strip()
|
||||
.decode("utf-8")
|
||||
)
|
||||
|
||||
def app_is_on_github(app):
|
||||
return "github.com" in app["url"]
|
||||
|
||||
apps_to_push = [app for app in apps() if diff_not_empty(app) and app_is_on_github(app)]
|
||||
apps_to_push = [
|
||||
app for app in apps() if diff_not_empty(app) and app_is_on_github(app)
|
||||
]
|
||||
|
||||
with requests.Session() as s:
|
||||
s.headers.update({"Authorization": f"token {token}"})
|
||||
for app in progressbar(apps_to_push, "Forking: ", 40):
|
||||
app["repo"] = app["url"][len("https://github.com/"):].strip("/")
|
||||
app["repo"] = app["url"][len("https://github.com/") :].strip("/")
|
||||
fork_if_needed(app["repo"], s)
|
||||
|
||||
for app in progressbar(apps_to_push, "Pushing: ", 40):
|
||||
app["repo"] = app["url"][len("https://github.com/"):].strip("/")
|
||||
app["repo"] = app["url"][len("https://github.com/") :].strip("/")
|
||||
app_repo_name = app["url"].rsplit("/", 1)[-1]
|
||||
folder = os.path.join(".apps_cache", app["id"])
|
||||
current_branch = git(f"symbolic-ref --short HEAD", in_folder=folder)
|
||||
git(f"reset origin/{current_branch}", in_folder=folder)
|
||||
git(["commit", "-a", "-m", title, "--author='Yunohost-Bot <>'"], in_folder=folder)
|
||||
git(
|
||||
["commit", "-a", "-m", title, "--author='Yunohost-Bot <>'"],
|
||||
in_folder=folder,
|
||||
)
|
||||
try:
|
||||
git(f"remote remove fork", in_folder=folder)
|
||||
except Exception:
|
||||
pass
|
||||
git(f"remote add fork https://{login}:{token}@github.com/{login}/{app_repo_name}", in_folder=folder)
|
||||
git(
|
||||
f"remote add fork https://{login}:{token}@github.com/{login}/{app_repo_name}",
|
||||
in_folder=folder,
|
||||
)
|
||||
git(f"push fork {current_branch}:{patch} --quiet --force", in_folder=folder)
|
||||
create_pull_request(app["repo"], patch, current_branch, s)
|
||||
|
||||
@ -141,11 +169,15 @@ def fork_if_needed(repo, s):
|
||||
|
||||
def create_pull_request(repo, patch, base_branch, s):
|
||||
|
||||
PR = {"title": "[autopatch] " + open(os.path.join("patches", patch, "pr_title.md")).read().strip(),
|
||||
"body": "This is an automatic PR\n\n" + open(os.path.join("patches", patch, "pr_body.md")).read().strip(),
|
||||
"head": login + ":" + patch,
|
||||
"base": base_branch,
|
||||
"maintainer_can_modify": True}
|
||||
PR = {
|
||||
"title": "[autopatch] "
|
||||
+ open(os.path.join("patches", patch, "pr_title.md")).read().strip(),
|
||||
"body": "This is an automatic PR\n\n"
|
||||
+ open(os.path.join("patches", patch, "pr_body.md")).read().strip(),
|
||||
"head": login + ":" + patch,
|
||||
"base": base_branch,
|
||||
"maintainer_can_modify": True,
|
||||
}
|
||||
|
||||
r = s.post(github_api + f"/repos/{repo}/pulls", json.dumps(PR))
|
||||
|
||||
@ -159,7 +191,8 @@ def main():
|
||||
|
||||
action = sys.argv[1]
|
||||
if action == "--help":
|
||||
print("""
|
||||
print(
|
||||
"""
|
||||
Example usage:
|
||||
|
||||
# Init local git clone for all apps
|
||||
@ -173,7 +206,8 @@ def main():
|
||||
|
||||
# Push and create pull requests on all apps with non-empty diff
|
||||
./autopatch.py --push explicit-php-version-in-deps
|
||||
""")
|
||||
"""
|
||||
)
|
||||
|
||||
elif action == "--build-cache":
|
||||
build_cache()
|
||||
|
Reference in New Issue
Block a user