【问题标题】:Is there a way to create git push/commit with linked workitems through TFS client libraries/API in a single operation?有没有办法通过 TFS 客户端库/API 在单个操作中创建带有链接工作项的 git push/commit?
【发布时间】: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);
}

推送已成功创建,但创建的提交上没有工作项链接。

我试过了

  1. 将 URL 设置为来自 https://docs.microsoft.com/en-us/rest/api/vsts/wit/work%20items/get%20work%20item?view=vsts-rest-4.1#workitem 的 URL。
  2. 将其设置为在 GitCommitRef.WorkItems ResourceRef 中为具有相关工作项的提交实际返回的略有不同的工作项 URL。

但无济于事。

我其实可以通过

达到想要的最终结果
  1. $"#{workitemId}" 附加到提交注释字符串
  2. 或者通过将提交链接添加到相关工作项

不过,这两种解决方案都有一些我希望避免的小缺点(1 - 更改提交消息,2 - 可能与 CI 的竞争条件等)。

基本上,有没有办法在单个操作中创建带有关联工作项的GitPush,还是我必须使用上述解决方法?

【问题讨论】:

    标签: c# git tfs git-commit tfs-sdk


    【解决方案1】:

    不,没有任何方法可以实现这一点。即使您从 TFS Web UI 创建提交/推送,TFS 仍会先创建提交/推送,然后更新工作项以链接到推送。

    【讨论】:

      猜你喜欢
      • 2010-09-19
      • 2023-03-07
      • 2010-10-10
      • 2013-05-10
      • 1970-01-01
      • 2019-01-22
      • 1970-01-01
      • 2010-11-25
      • 2011-01-13
      相关资源
      最近更新 更多