diff options
author | Matěj Cepl <mcepl@cepl.eu> | 2024-02-26 19:30:45 +0100 |
---|---|---|
committer | Matěj Cepl <mcepl@cepl.eu> | 2024-03-01 00:51:48 +0100 |
commit | 2a88ef71ca39471c14c2879d4c1b273064841707 (patch) | |
tree | 72fd97f103a24a6c44691c1a22092bf9dd75bb0a | |
parent | 5c0772757d60363cd403494da365ea4cb96c22d2 (diff) | |
download | hlupak-2a88ef71ca39471c14c2879d4c1b273064841707.tar.gz |
fix(add-networked-repos): Rewrite the script in BASH.
-rwxr-xr-x | add-networked-repos.py | 45 | ||||
-rwxr-xr-x | add-networked-repos.sh | 29 |
2 files changed, 29 insertions, 45 deletions
diff --git a/add-networked-repos.py b/add-networked-repos.py deleted file mode 100755 index 36c7622..0000000 --- a/add-networked-repos.py +++ /dev/null @@ -1,45 +0,0 @@ -#!/usr/bin/python3 - -import urllib.request -import urllib.error -import urllib.parse -import json -import subprocess -import argparse - -URL = "https://api.github.com/repos/%s/%s/forks" -REPO_URL = "https://github.com/%s/%s" -p = subprocess.Popen(['git', 'config', 'github.user'], - stdout=subprocess.PIPE) -login = p.communicate()[0].strip() -p = subprocess.Popen(['git', 'config', 'github.password'], - stdout=subprocess.PIPE) -passwd = p.communicate()[0].strip() - - -def get_forks(repo): - user, name = repo.split("/", 2) - - repo_url = URL % (user, name) - password_mgr = urllib.request.HTTPPasswordMgrWithDefaultRealm() - password_mgr.add_password(None, repo_url, login, passwd) - auth_handler = urllib.request.HTTPBasicAuthHandler(password_mgr) - opener = urllib.request.build_opener(auth_handler) - urllib.request.install_opener(opener) - response = urllib.request.urlopen(repo_url) - repos = json.load(response) - for repo in repos: - full_name = repo['full_name'] - f_user, f_name = full_name.split("/", 2) - subprocess.call(['git', 'remote', 'add', f_user.lower(), - REPO_URL % (f_user, f_name)]) - subprocess.call(['git', 'fetch', f_user.lower()]) - get_forks(full_name) - - -parser = argparse.ArgumentParser() -parser.add_argument('fname_repo', - help="full name of the repo (e.g., user/name)") -args = parser.parse_args() - -get_forks(args.fname_repo) diff --git a/add-networked-repos.sh b/add-networked-repos.sh new file mode 100755 index 0000000..7a7df48 --- /dev/null +++ b/add-networked-repos.sh @@ -0,0 +1,29 @@ +#!/bin/bash +set -eux +set -o noglob + +API_URL="https://api.github.com/repos/" +REPO_URL="https://github.com/%s/%s" + +if [ $# -ne 1 ] ; then + echo "The only parameter of the script is user/name of the repo" + exit 1 +fi + +# login=$(git config github.user) +# passwd=$(git config github.password) + +get_forks() { + fname="${1}" + repo_url="$API_URL/$fname/forks" + repos="$(curl -s "$repo_url" | jq -r '.[]|.full_name')" + for full_name in $repos ; do + IFS='/' read -a -r names <<< "${full_name}" + l_user="$(echo "${names[0]}"|tr '[:upper:]' '[:lower:]')" + git remote add "${l_user}" "${REPO_URL}/${full_name}" + git fetch "${l_user}" + get_forks "${full_name}" + done +} + +get_forks "${1}" |