【发布时间】:2019-02-15 23:41:59
【问题描述】:
我想使用包含指定工作项的 TFS git client libraries 创建推送。
代码基本上是:
public static async Task<GitPush> CreatePush(
this GitHttpClient git,
GitRepository repo,
GitRefUpdate branchUpdateRef,
GitChange change,
String comment,
IEnumerable<Int32> workitems = null)
{
workitems = (workitems ?? Enumerable.Empty<Int32>()).ToList();
var commit = new GitCommitRef
{
Comment = comment,
Changes = new[]
{
change
},
WorkItems = workitems
.Select(wi => new ResourceRef
{
Id = wi.ToString()
// Perhaps one should also set an URL of some kind
})
.ToList()
};
var push = new GitPush
{
Commits = new[]
{
commit
},
RefUpdates = new[]
{
branchUpdateRef
},
Repository = repo
};
return await git.CreatePushAsync(
push,
project: repo.ProjectReference.Id,
repositoryId: repo.Id);
}
推送已成功创建,但创建的提交上没有工作项链接。
我试过了
- 将 URL 设置为来自 https://docs.microsoft.com/en-us/rest/api/vsts/wit/work%20items/get%20work%20item?view=vsts-rest-4.1#workitem 的 URL。
- 将其设置为在
GitCommitRef.WorkItemsResourceRef中为具有相关工作项的提交实际返回的略有不同的工作项 URL。
但无济于事。
我其实可以通过
达到想要的最终结果- 将
$"#{workitemId}"附加到提交注释字符串 - 或者通过将提交链接添加到相关工作项
不过,这两种解决方案都有一些我希望避免的小缺点(1 - 更改提交消息,2 - 可能与 CI 的竞争条件等)。
基本上,有没有办法在单个操作中创建带有关联工作项的GitPush,还是我必须使用上述解决方法?
【问题讨论】:
标签: c# git tfs git-commit tfs-sdk