【问题标题】:How to import existing azure repo (as a template) into newly created azure repo如何将现有 azure repo(作为模板)导入新创建的 azure repo
【发布时间】:2021-11-22 15:56:51
【问题描述】:

我正在尝试制作一个机器人,它允许我公司的程序员快速创建一个新的存储库,该存储库将通过导入使用模板存储库中的相同文件。我目前正在尝试使用 Microsoft.TeamFoundation.Client 和 Microsoft.TeamFoundation.SourceControl.WebApi,但到目前为止没有成功。我不断收到错误请求消息(没有其他可以说明需要更改的内容)。 我的代码目前看起来像这样。

//Creates the new repository
var gitRepoOptions = new GitRepositoryCreateOptions
                {
                    Name = repoName,
                    ProjectReference = teamProjectReference
                };
//Creates VSS connection and GitHttpClient to create repository
var targetRepository = await this._azureConnection.CreateRepositoryAsync(gitRepoOptions);

//Import template Azure git repo   
var gitRepository = new GitRepository
{
    Id = targetRepository.Id
};
var gitImportGitSource = new GitImportGitSource
{
     Url = "https://dev.azure.com/{organization}/{team project}/_git/{repository}" 
     //Or this
     //Url = "https://{organization}@dev.azure.com/{organization}/{team project}/_git/{repository}"
};
var gitImportRequestParameters = new GitImportRequestParameters
{
      GitSource = gitImportGitSource,
      TfvcSource = null
};
var gitImportRequest = new GitImportRequest
{
       Repository = gitRepository,
       Parameters = gitImportRequestParameters
};

//Imports azure git repo (or rather should)
await this._azureConnection.CreateImportRequestAsync(gitImportRequest, teamProjectReference.Id, targetRepository.Id);

【问题讨论】:

  • 您在哪一步收到 Bad Request 错误?

标签: .net azure .net-core


【解决方案1】:

您提供的代码似乎是正确的。您遵循的过程也是正确的。我建议使用以下参考资料 -

  1. Microsoft.TeamFoundation.Client;
  2. Microsoft.TeamFoundation.Core.WebApi;
  3. Microsoft.TeamFoundation.SourceControl.WebApi;
  4. Microsoft.TeamFoundation.WorkItemTracking.Client;

并在目标项目中创建新的存储库,如下所示。

var targetRepository = await this._azureConnection.CreateRepositoryAsync(gitRepositoryCreateOptions).Result;

如果您在 url 中收到错误的请求错误,这是源存储库的路径,那么您需要使用 web 调试代理工具(如 fiddler)检查路径。

还可以查看此 TFVC Repository Migration To GIT Repository 示例和Import repositories from TFVC to Git 文档以获取更多信息。

【讨论】:

    猜你喜欢
    • 2020-08-10
    • 2021-05-02
    • 2020-05-08
    • 2019-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-06-14
    • 2013-09-17
    相关资源
    最近更新 更多