VSTS扩展:从新仓库初始化或创建主分支

时间:2018-06-14 01:59:04

标签: azure-devops azure-devops-extensions azure-devops-rest-api

是否可以使用Visual Studio Team Services REST API来初始化新创建的存储库?

1 个答案:

答案 0 :(得分:0)

不能相信我从VSTS REST api文档中错过了这一点,但是这里是您可以在vsts上创建和初始化新的git存储库,以及在TFS 2015上对其进行测试的方法

创建新的存储库:

帖子:http://tfs:8080/tfs/DefaultCollection/_apis/git/repositories?api-version=3.0

身体:

{
  "name": "AnotherRepository",
  "project": {
    "id": "e7154789-27db-4ee5-a192-4d69594c6588"
  }
}

初始化新存储库:

帖子:http://tfs:8080/tfs/DefaultCollection/_apis/git/repositories/4968177d-1f0b-4009-a635-272af892f536/pushes?api-version=3

身体:

{
  "refUpdates": [
    {
      "name": "refs/heads/master",
      "oldObjectId": "0000000000000000000000000000000000000000"
    }
  ],
  "commits": [
    {
      "comment": "Initial commit.",
      "changes": [
        {
          "changeType": "add",
          "item": {
            "path": "/readme.md"
          },
          "newContent": {
            "content": "My first file!",
            "contentType": "rawtext"
          }
        }
      ]
    }
  ]
}

VSTS REST文档: