I'm using this bash & jq script:
UserName=CHANGEME; \
curl -s https://api.github.com/users/$UserName/repos?per_page=1000 |\
jq -r '.[]|.clone_url' |\
xargs -L1 git clone
It will clone the repos into a directory using the REST API parameter name (repo.name). (Default behavior)
I want it to clone the repos into a directory using the REST API parameter full_name (since it consists of repo.owner and repo.name), how do I get around to do that?
This is what is created inside my directory:
repo.name1
repo.name2
This is what I want inside my directory:
repo.owner1\repo.name1
repo.owner2\repo.name2
CodePudding user response:
- The individual arguments read by xargs should ideally be quoted.
- xargs needs to call git clone with two separate arguments: the repository URL and the destination directory into which to clone it.
jq -r '.[] | .html_url, .full_name' -> jq -r '.[] | [ .html_url, .full_name ]'
- Add the
@shoperator to output a each such array as a line of shell-quoted words
jq -r '.[] | [ .html_url, .full_name ]' -> jq -r '.[] | [ .html_url, .full_name ] | @sh'
- Add
-n 2so that xargs will call the utility with two arguments from its input stream at a time
xargs git clone > xargs -n 2 git clone
- Together:
curl -s "https://api.github.com/users/$UserName/repos?per_page=1000" |
jq -r '.[] | [ .html_url, .full_name ] | @sh' |
xargs -n 2 git clone
