コード例 #1
0
        public async Task <JsonResult> SendRequest(DevOpsWorkItem workItem)
        {
            // must have a title
            if (workItem == null || string.IsNullOrWhiteSpace(workItem.Title))
            {
                return(Json(new { success = false }));
            }

            var result = await CreateWorkItem(workItem);

            return(Json(new { success = true, result = result }));
        }
コード例 #2
0
        public JsonPatchDocument Create(string twitchUsername, DevOpsWorkItem workItem)
        {
            var jsonPatchDocument = new JsonPatchDocument();

            jsonPatchDocument
            .AddTitle($"{twitchUsername} - {workItem.Title}")
            .AddAcceptanceCriteria(workItem.AcceptanceCriteria);

            if (workItem.Tags != null && workItem.Tags.Any())
            {
                jsonPatchDocument.AddTags(workItem.Tags);
            }

            return(jsonPatchDocument);
        }
コード例 #3
0
        private async Task <JsonResult> CreateWorkItem(DevOpsWorkItem workItem)
        {
            var organization = Configuration.GetConnectionString("Organization"); // todo add your organization
            var project      = Configuration.GetConnectionString("Project");      // todo add your project
            var devOpsKey    = Configuration.GetConnectionString("DevOpsKey");    // todo add your devOpsKey

            // default type if not defined
            if (string.IsNullOrWhiteSpace(workItem.Type))
            {
                workItem.Type = "feature";
            }
            workItem.CreatedBy = "who created this"; // todo add who created this work item

            string _UrlServiceCreate = $"https://dev.azure.com/{organization}/{project}/_apis/wit/workitems/${workItem.Type}?api-version=5.0";

            var WorkItem = new List <dynamic>()
            {
                new
                {
                    op    = "add",
                    path  = "/fields/System.Title",
                    value = workItem.Title
                }, new
                {
                    op    = "add",
                    path  = "/fields/System.Tags",
                    value = workItem.CreatedBy
                }
            };

            // add description if not empty
            if (!string.IsNullOrWhiteSpace(workItem.Description))
            {
                WorkItem.Add(new
                {
                    op    = "add",
                    path  = "/fields/System.Description",
                    value = workItem.Description
                });
            }

            var WorkItemValue             = new StringContent(JsonConvert.SerializeObject(WorkItem), Encoding.UTF8, "application/json-patch+json");
            var JsonResultWorkItemCreated = await HttpMethod(_UrlServiceCreate, devOpsKey, WorkItemValue, System.Net.Http.HttpMethod.Post);

            return(Json(new { workItem = JsonResultWorkItemCreated }));
        }