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"
|
||||
green="\e[32m"
|
||||
|
||||
XPATH='//*[@id="user-list-repositories"]//a[not(@class)]/@href'
|
||||
|
||||
function help_screen {
|
||||
echo
|
||||
echo -e "''${bold}''${underline}Usage:''${reset} ''${bold}$0''${reset} <USER> <LIST>"
|
||||
|
|
@ -33,15 +35,30 @@ pkgs.writeShellScriptBin "git-clone-list" ''
|
|||
USER=$1
|
||||
LIST=$2
|
||||
|
||||
echo -e "''${green}>>> Fetching list https://github.com/stars/$USER/lists/$LIST ...''${reset}"
|
||||
REPOS=$(${pkgs.xidel}/bin/xidel https://github.com/stars/$USER/lists/$LIST --xpath '//*[@id="user-list-repositories"]//a[not(@class)]/@href')
|
||||
NOT_VISITED=("/stars/$USER/lists/$LIST?page=1")
|
||||
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
|
||||
|
||||
for repo in $REPOS; do
|
||||
echo -e "''${green}>>> [$IT/$NUM_REPOS] Cloning: https://github.com$repo.git ...''${reset}"
|
||||
${pkgs.git}/bin/git clone "https://github.com$repo.git" "''${repo:1}"
|
||||
for repo in "''${REPOS[@]}"; do
|
||||
echo -e "''${green}>>> [$IT/''${#REPOS[@]}] Cloning https://github.com$repo.git ...''${reset}"
|
||||
git clone "https://github.com$repo.git" "''${repo:1}"
|
||||
IT=$((IT + 1))
|
||||
done
|
||||
''
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue