【问题标题】:TFS adding comments to discussionTFS 在讨论中添加评论
【发布时间】:2018-12-23 18:20:49
【问题描述】:

我正在从 LeanKit 迁移卡片,我需要将 cmets 添加到 TFS 卡片的讨论中。 如何以其他用户的身份向 WorkItem 添加编程注释? 可能吗? 我发现仅通过 History 属性添加 cmets,但作为登录用户。

谢谢!

【问题讨论】:

    标签: c# .net tfs comments


    【解决方案1】:

    默认情况下,我们只能通过登录用户添加 cmets。

    但是,您可以使用 REST API 将 cmets 添加到与其他用户的讨论中,以在启用 bypassRules 的情况下更新 System.ChangedBy 字段的值:

    以下示例供您参考:

    Param(
       [string]$baseurl = "http://server:8080/tfs/DefaultCollection",
       [string]$projectName = "ProjectName",
       [string]$workitemID = "26",
       [string]$user = "username",
       [string]$token = "token/Password"
    )
    
    # Base64-encodes the Personal Access Token (PAT) appropriately
    $base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
    write-host $WorkitemType
    
    function CreateJsonBody
    {
    
        $value = @"
    [
      {
        "op": "add",
        "path": "/fields/System.History",
        "value": "Comment here"
      },
      {
        "op": "add",
        "path": "/fields/System.ChangedBy",
        "value": "user@oxxx.com"
      }
    ]
    "@
    
     return $value
    }
    
    $json = CreateJsonBody
    
    $uri = "$baseurl/$($projectName)/_apis/wit/workitems/$($workitemID)?bypassRules=true&api-version=2.2"
    Write-Host $uri
    $result = Invoke-RestMethod -Uri $uri -Method Patch -Body $json -ContentType "application/json-patch+json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
    

    “值”:“user@oxxx.com”可以是其他用户的有效用户ID(guid)或用户电子邮件。

    【讨论】:

      【解决方案2】:

      只有当您使用他的凭据登录时,您才能将 cmet 作为另一个用户添加到讨论中:

      NetworkCredential cred = new NetworkCredential("anotherUserName", "password");
      TfsTeamProjectCollection _tfs = new TfsTeamProjectCollection(new Uri("serverUrl"), cred);
      _tfs.EnsureAuthenticated();
      

      在您像其他用户一样进行身份验证后,您将文本添加到历史记录字段,您将看到讨论中的文本作为另一个登录用户。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2021-08-24
        • 2019-04-03
        • 1970-01-01
        • 2022-01-19
        • 2014-07-06
        • 2022-08-23
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多