• 在TFS中通过程序动态创建Bug并感知Bug解决状态


      为便于跟踪问题解决情况,预警引擎产生的比较严重的预警日志,需要在TFS中登记Bug,通过TFS的状态流转,利用TFS Bug的Web挂钩功能,动态感知Bug解决状态,从而跟踪预警问题的解决状态,

      整体解决方案如下:

    微软提供了很好的文档支持:

    https://www.visualstudio.com/en-us/docs/integrate/api/wit/work-items#create-bug

    创建Bug示例代码如下:

    public void CreateBug()
    {
       string _userName = "userName";
       string _userPwd = "userPwd";
       string _credentials = Convert.ToBase64String(System.Text.ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", _userName , _userPwd)));
    
       Object[] patchDocument = new Object[4];
    
       patchDocument[0] = new { op = "add", path = "/fields/System.Title", value = "Authorization Errors" };
       patchDocument[1] = new { op = "add", path = "/fields/Microsoft.VSTS.TCM.ReproSteps", value = "ReproSteps" };
       patchDocument[2] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Priority", value = "1" };
       patchDocument[3] = new { op = "add", path = "/fields/Microsoft.VSTS.Common.Severity", value = "2 - High" };
    
       //use the httpclient
       using (var client = new HttpClient())
       {
           //set our headers
           client.DefaultRequestHeaders.Accept.Clear();
           client.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
           client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", _credentials);
    
           //serialize the fields array into a json string
           var patchValue = new StringContent(JsonConvert.SerializeObject(patchDocument), Encoding.UTF8, "application/json-patch+json"); 
    
           var method = new HttpMethod("PATCH");
           var request = new HttpRequestMessage(method, "TFS Bug URL") { Content = patchValue };
           var response = client.SendAsync(request).Result;
    
           //if the response is successfull, set the result to the workitem object
           if (response.IsSuccessStatusCode)
           {
               var result = response.Content.ReadAsStringAsync().Result;
           }
       }
    }

    返回的result是一个Json串,形如:

    {
        "id": 58141,
        "rev": 1,
        "fields": {
            "System.AreaPath": "Bugs",
            "System.TeamProject": "Bugs",
            "System.IterationPath": "Bugs",
            "System.WorkItemType": "Bug",
            "System.State": "新建",
            "System.Reason": "新建",
            "System.AssignedTo": "用户 <TELD\\user>",
            "System.CreatedDate": "",
            "System.CreatedBy": "用户 <TELD\\user>",
            "System.ChangedDate": "",
            "System.ChangedBy": "用户 <TELD\\user>",
            "System.Title": "测试新增",
            "System.BoardColumn": "新建",
            "System.BoardColumnDone": false,
            "Microsoft.VSTS.Common.StateChangeDate": "",
            "Microsoft.VSTS.Common.Priority": 2,
            "Microsoft.VSTS.Common.Severity": "3 - 中",
            "Microsoft.VSTS.Common.ValueArea": "业务",
            "Teld.Bug.Source": "预警引入",
            "Teld.Bug.DetectionMode": "集成测试",
            "Teld.Bug.ifCausedByModification": "",
            "Teld.Bug.Type": "程序错误",
            "Teld.Bug.IfAgreeResultState": "初始",
            "Teld.Bug.Client": "WebPC",
            "Teld.Bug.FunctionMenu": "预警中心--预警日志",
            "WEF_794F3BA7F8DF460D97A964BF78CEC582_Kanban.Column": "新建",
            "WEF_794F3BA7F8DF460D97A964BF78CEC582_Kanban.Column.Done": false,
            "Microsoft.VSTS.TCM.ReproSteps": "重现步骤"
        },
        "_links": {
            "self": {
                "href": ""
            },
            "workItemUpdates": {
                "href": ""
            },
            "workItemRevisions": {
                "href": ""
            },
            "workItemHistory": {
                "href": ""
            },
            "html": {
                "href": ""
            },
            "workItemType": {
                "href": ""
            },
            "fields": {
                "href": ""
            }
        },
        "url": ""
    }

     以前只用过Http协议中的Get、Post、Put等,这个Patch方法,还是第一次用。

  • 相关阅读:
    第九届蓝桥杯省赛c/c++真题明码题解答案,另类excel解法思路
    Windows下将Python源代码.py文件封装成exe可执行文件方法
    windows下python自带的pip安装速度过慢解决方案
    解决:Errors were encountered while processing
    ubuntu 安装 caffe 解决://home/xiaojie/anaconda/lib/libpng16.so.16:对‘inflateValidate@ZLIB_1.2.9’未定义的引用
    ubuntu安装caffe 解决:build_release/tools/caffe: error while loading shared libraries: libcudart.so.8.0: cannot open shar
    ubuntu 禁止内核更新
    ubutun 中notebook出现 Permission denied: Untitled.ipynb
    ubuntu下anaconda使用jupyter notebook加载tensorflow、pytorch
    ubuntu下用anaconda快速安装 pytorch
  • 原文地址:https://www.cnblogs.com/liugh/p/6550005.html
Copyright © 2020-2023  润新知