如何使用 REST API 在具有作者姓名的目录中克隆存储库? [英] How to clone repos inside a directory with their author name with REST API?
问题描述
我正在使用 this bash
&jq
脚本:
UserName=CHANGEME;\curl -s https://api.github.com/users/$UserName/repos?per_page=1000 |\jq -r '.[]|.clone_url' |\xargs -L1 git 克隆
它将使用 REST API 参数 name
(repo.name) 将存储库克隆到目录中.(默认行为)
我希望它使用 REST API 参数 full_name
将 repos 克隆到一个目录中(因为它由 repo.owner
和 repo.name代码>),我该怎么做?
这是在我的目录中创建的内容:
repo.name1repo.name2
这是我想要的目录:
repo.owner1\repo.name1repo.owner2\repo.name2
- 理想情况下,xargs 读取的各个参数应该引用.
- xargs 需要使用两个单独的参数调用 git clone:存储库 URL 和将其克隆到的目标目录.
jq -r '.[] |.html_url, .full_name'
->jq -r '.[] |[ .html_url, .full_name ]'
- 添加
@sh
操作符,将每个这样的数组输出为一行 shell 引用的单词
jq -r '.[] |[ .html_url, .full_name ]'
->jq -r '.[] |[ .html_url, .full_name ] |@sh'
<块引用>
- 添加
-n 2
以便 xargs 将一次从其输入流中使用两个参数调用该实用程序
xargs git clone
>xargs -n 2 git clone
<块引用>
- 一起:
curl -s "https://api.github.com/users/$UserName/repos?per_page=1000";|jq -r '.[] |[ .html_url, .full_name ] |@sh' |xargs -n 2 git 克隆
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
- 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
@sh
operator 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 2
so 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
这篇关于如何使用 REST API 在具有作者姓名的目录中克隆存储库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!