【发布时间】: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 错误?