我想使用包含指定工作项的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);
}
虽然在创建的提交上没有工作项链接,但是已成功创建推送。
我试过了
GitCommitRef.WorkItems
ResourceRef
中为具有相关工作项的提交实际返回的略有不同的工作项URL。但无济于事。
我实际上可以达到预期的最终结果
$"#{workitemId}"
附加到提交注释字符串尽管如此,这两种解决方案都有一些小缺点(1 - 改变提交消息,2 - 可能的竞争条件与CI等),我宁愿避免。
基本上,有没有办法在一次操作中创建带有相关工作项的GitPush
,还是我必须使用上述解决方法?
不,没有办法实现这一目标。即使您从TFS Web UI创建提交/推送,TFS仍然首先创建提交/推送,然后更新工作项以链接到推送。