feat(scripts/git-clone-list): handle pagination
This commit is contained in:
parent
9216fb2131
commit
22dacc57db
1 changed files with 23 additions and 6 deletions
|
|
@ -7,6 +7,8 @@ pkgs.writeShellScriptBin "git-clone-list" ''
|
||||||
red="\e[31m"
|
red="\e[31m"
|
||||||
green="\e[32m"
|
green="\e[32m"
|
||||||
|
|
||||||
|
XPATH='//*[@id="user-list-repositories"]//a[not(@class)]/@href'
|
||||||
|
|
||||||
function help_screen {
|
function help_screen {
|
||||||
echo
|
echo
|
||||||
echo -e "''${bold}''${underline}Usage:''${reset} ''${bold}$0''${reset} <USER> <LIST>"
|
echo -e "''${bold}''${underline}Usage:''${reset} ''${bold}$0''${reset} <USER> <LIST>"
|
||||||
|
|
@ -33,15 +35,30 @@ pkgs.writeShellScriptBin "git-clone-list" ''
|
||||||
USER=$1
|
USER=$1
|
||||||
LIST=$2
|
LIST=$2
|
||||||
|
|
||||||
echo -e "''${green}>>> Fetching list https://github.com/stars/$USER/lists/$LIST ...''${reset}"
|
NOT_VISITED=("/stars/$USER/lists/$LIST?page=1")
|
||||||
REPOS=$(${pkgs.xidel}/bin/xidel https://github.com/stars/$USER/lists/$LIST --xpath '//*[@id="user-list-repositories"]//a[not(@class)]/@href')
|
VISITED=()
|
||||||
|
REPOS=()
|
||||||
|
|
||||||
|
while [[ "''${#NOT_VISITED[@]}" != 0 ]]; do
|
||||||
|
echo -e "''${green}>>> Fetching https://github.com''${NOT_VISITED[0]} ...''${reset}"
|
||||||
|
while IFS= read -r line; do
|
||||||
|
VISITED+=("''${NOT_VISITED[0]}")
|
||||||
|
unset NOT_VISITED[0]
|
||||||
|
if [[ "$line" == "/stars/$USER/lists/$LIST"* ]]; then
|
||||||
|
if [[ ! "''${VISITED[@]}" =~ "''${line}" ]]; then
|
||||||
|
NOT_VISITED+=("$line")
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
REPOS+=("$line")
|
||||||
|
fi
|
||||||
|
done < <(xidel "https://github.com''${NOT_VISITED[0]}" --xpath $XPATH)
|
||||||
|
done
|
||||||
|
|
||||||
NUM_REPOS=$(echo $REPOS | wc -w)
|
|
||||||
IT=1
|
IT=1
|
||||||
|
|
||||||
for repo in $REPOS; do
|
for repo in "''${REPOS[@]}"; do
|
||||||
echo -e "''${green}>>> [$IT/$NUM_REPOS] Cloning: https://github.com$repo.git ...''${reset}"
|
echo -e "''${green}>>> [$IT/''${#REPOS[@]}] Cloning https://github.com$repo.git ...''${reset}"
|
||||||
${pkgs.git}/bin/git clone "https://github.com$repo.git" "''${repo:1}"
|
git clone "https://github.com$repo.git" "''${repo:1}"
|
||||||
IT=$((IT + 1))
|
IT=$((IT + 1))
|
||||||
done
|
done
|
||||||
''
|
''
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue