public async Task <IActionResult> Create([FromBody] JiraHook hook) { // Get configs Config config = await Config.GetConfig(_context, hook.Issue.Fields.Priority.Name); // Validate Sync sync = _context.Sync.FirstOrDefault(s => s.JiraKey == hook.Issue.Key); if (config == null || sync != null) { return(Ok("Can't create issue")); } // Create WorkItem workItem = new WorkItem { Title = hook.Issue.Fields.Summary, ReproSteps = JFStringer.ToTfsFormat(hook.Issue.Fields.Description), //\n \nOpend At: {hook.Issue.Fields.Created}\nBy: {hook.User.DisplayName}\nEmail: {hook.User.EmailAddress}", CreatedDate = hook.Issue.Fields.Created, AreaPath = config.TfsConfig.Area, TeamProject = config.TfsConfig.TeamProject, IterationPath = config.TfsConfig.Iteration, Priority = Priority.ToTfsPriority(_context, hook.Issue.Fields.Priority.Name), Links = new List <Link> { new Link { rel = "System.LinkTypes.Hierarchy-Reverse", url = $"{Env.TFS_URI}_apis/wit/workItems/{config.TfsConfig.ParentId}", } } }; var result = await WorkItems.CreateBug(workItem.ToParameterList(), config); // TODO: Check if succeeded Resource tfsResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <Resource>(result); // Sync sync = new Sync { JiraKey = hook.Issue.Key, TfsId = tfsResponse.Id, Rev = tfsResponse.Rev, Title = workItem.Title, Description = JFStringer.ToCommonFormat(workItem.ReproSteps), Priority = workItem.Priority }; await _context.AddAsync(sync); await _context.SaveChangesAsync(); return(Ok("Created")); }
public void WorkItemTracking_WorkItems_CreateBug_Success() { // arrange WorkItems request = new WorkItems(_configuration); // act WorkItemPatchResponse.WorkItem response = request.CreateBug(_configuration.Project); // assert Assert.AreEqual(HttpStatusCode.OK, response.HttpStatusCode); request = null; }