我试图在我的团队的BitBucket项目中克隆所有存储库。
我想从REST调用返回的JSON中提取URL和名称,并使用这些值进行克隆
以下是我所拥有的
curl -s http://bitbucketlocalserver:7990/rest/api/1.0/projects/PROJECT_NAME/repos?per_page=20 ^
-u user:pass | H:\Downloads\Win64\jq-win64.exe -r ".values[] | .links.clone[] | select(.name==\"http\") | .href" ^
H:\Utilities\Git\usr\bin\xargs.exe -L1 git clone -b release/development
这适用于url,但是我还想将目录名称更改为Name属性,例如GitRepository1,GitRepository2等,而不是gitrepo1,gitrepo2(当未传递该参数时会自动使用)
所以,类似
curl -s http://bitbucketlocalserver:7990/rest/api/1.0/projects/PROJECT_NAME/repos?per_page=20 ^
-u user:pass | H:\Downloads\Win64\jq-win64.exe -r ".values[] | .links.clone[] | select(.name==\"http\") | .href" ^
H:\Utilities\Git\usr\bin\xargs.exe -L1 git clone -b release/development git_url dir_name
我需要jq命令的帮助来选择两个属性并传递给xargs命令
这是json结构
{
"size": 25,
"limit": 25,
"isLastPage": false,
"values": [
{
"slug": "gitrepo1",
"id": 2216,
"name": "GitRepository1",
"scmId": "git",
"state": "AVAILABLE",
"statusMessage": "Available",
"forkable": true,
"project": {
"key": "PROJECT_NAME",
"id": 1369,
"name": "PROJECT_NAME",
"description": "ABC Team",
"public": false,
"type": "NORMAL",
"links": {
"self": [
{
"href": "http://bitbucketlocalserver:7990/projects/PROJECT_NAME"
}
]
}
},
"public": false,
"links": {
"clone": [
{
"href": "ssh://git@bitbucketlocalserver:7999/PROJECT_NAME/gitrepo1.git",
"name": "ssh"
},
{
"href": "http://bitbucketlocalserver:7990/scm/PROJECT_NAME/gitrepo1.git",
"name": "http"
}
],
"self": [
{
"href": "http://bitbucketlocalserver:7990/projects/PROJECT_NAME/repos/gitrepo1/browse"
}
]
}
},
{
"slug": "gitrepo2",
"id": 2214,
"name": "GitRepository2",
"scmId": "git",
"state": "AVAILABLE",
"statusMessage": "Available",
"forkable": true,
"project": {
"key": "PROJECT_NAME",
"id": 1369,
"name": "PROJECT_NAME",
"description": "ABC Team",
"public": false,
"type": "NORMAL",
"links": {
"self": [
{
"href": "http://bitbucketlocalserver:7990/projects/PROJECT_NAME"
}
]
}
},
"public": false,
"links": {
"clone": [
{
"href": "ssh://git@bitbucketlocalserver:7999/PROJECT_NAME/gitrepo2.git",
"name": "ssh"
},
{
"href": "http://bitbucketlocalserver:7990/scm/PROJECT_NAME/gitrepo2.git",
"name": "http"
}
],
"self": [
{
"href": "http://bitbucketlocalserver:7990/projects/PROJECT_NAME/repos/gitrepo2/browse"
}
]
}
}
],
"start": 0,
"nextPageStart": 25
}
可能吗?我该怎么做?
谢谢
以下命令提供所需的输出
curl -s http://bitbucketlocalserver:7990/rest/api/1.0/projects/PROJECT_NAME/repos?limit=100 ^
-u user:pass | H:\Downloads\Win64\jq-win64.exe -r "[.values[] | ((.links.clone[] | select(.name==\"http\") | .href) + \" \" + .name)]"
该命令的输出是
[
"http://bitbucketlocalserver:7990/scm/PROJECT_NAME/gitrepo1.git GitRepository1",
"http://bitbucketlocalserver:7990/scm/PROJECT_NAME/gitrepo1.git GitRepository2"
]
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句