使用jq克隆项目中的所有BitBucket存储库 [英] Clone all BitBucket Repositories From a Project using jq

查看:107
本文介绍了使用jq克隆项目中的所有BitBucket存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我团队的BitBucket项目中克隆所有存储库。

I am trying to clone all repositories in my team's project in BitBucket.

我想从REST调用返回的JSON中提取URL和名称,并使用这些值进行克隆

I want to extract the url and the name from the JSON returned from the REST call and use those values to clone

下面是我所拥有的

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

This works for the url, but what I want to do is also change the name of the directory to the Name attribute, e.g. GitRepository1, GitRepository2 etc., instead of gitrepo1, gitrepo2 that is used automatically when that parameter is not passed

因此,类似于

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命令

I need help with the jq command to select the two attributes and pass to the xargs command

这是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
}

有可能吗?我该怎么做?

Is it possible? How can I do it?

谢谢

推荐答案

下面的命令提供了所需的输出

The command below gives the output needed

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"
]

这篇关于使用jq克隆项目中的所有BitBucket存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆