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 async Task <IActionResult> Update([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 || sync.Deleted || (sync.Title == hook.ChangeLog.Items.FirstOrDefault(ch => ch.Field == "summary")?.Tostring&& sync.Description == JFStringer.ToCommonFormat(hook.ChangeLog.Items.FirstOrDefault(ch => ch.Field == "description")?.Tostring) && sync.Priority == Priority.ToTfsPriority(_context, hook.ChangeLog.Items.FirstOrDefault(ch => ch.Field == "priority")?.Tostring))) { return(Ok($"Not found")); } // Update WorkItem workItem = new WorkItem(); foreach (var changelogItem in hook.ChangeLog.Items) { switch (changelogItem.Field) { case "description": workItem.ReproSteps = JFStringer.ToTfsFormat(changelogItem.Tostring); sync.Description = changelogItem.Tostring; break; case "summary": workItem.Title = changelogItem.Tostring; sync.Title = changelogItem.Tostring; break; case "priority": workItem.Priority = Priority.ToTfsPriority(_context, changelogItem.Tostring); sync.Priority = workItem.Priority; break; } } var result = await WorkItems.UpdateBug(workItem.ToParameterListNotEmptyFields(sync.Rev), config, sync.TfsId); // TODO: Check if succeeded Resource tfsResponse = Newtonsoft.Json.JsonConvert.DeserializeObject <Resource>(result); // Sync sync.Rev = tfsResponse.Rev; await _context.SaveChangesAsync(); return(Ok("Updated")); }
public async Task <IActionResult> Create([FromBody] TfsHook <Resource> hook) { // Get configs int priority = int.Parse(hook.Resource.Fields.Priority); Config config = await Config.GetConfig(_context, priority); // Validate Sync sync = _context.Sync.FirstOrDefault(s => s.TfsId == hook.Resource.Id); if (config == null || sync != null || config.TfsConfig.Priority != priority) { return(Ok("Can't create issue")); } var issue = _jira.CreateIssue(config.JiraConfig.Project); issue.Type = hook.Resource.Fields.WorkItemType; issue.Priority = Priority.ToJiraPriority(_context, priority); issue.Summary = hook.Resource.Fields.Title; issue.Description = JFStringer.ToCommonFormat(hook.Resource.Fields.ReproSteps); var result = await issue.SaveChangesAsync(); // Sync sync = new Sync { JiraKey = result.Key.Value, TfsId = hook.Resource.Id, Rev = hook.Resource.Rev, Title = issue.Summary, Description = issue.Description, Priority = Priority.ToTfsPriority(_context, issue.Priority.Name) }; await _context.AddAsync(sync); await _context.SaveChangesAsync(); return(Ok("Created")); }
public async Task <IActionResult> Update([FromBody] TfsHook <UpdatedResource> hook) { int priority = int.Parse(hook.Resource.Revision.Fields.Priority); // Get configs Config config = await Config.GetConfig(_context, priority); // Validate Sync sync = _context.Sync.FirstOrDefault(s => s.TfsId == hook.Resource.Revision.Id); if (sync == null || sync.Deleted || config.TfsConfig.Priority != priority || sync.Rev == hook.Resource.Revision.Rev || (sync.Title == hook.Resource.Fields.Title?.NewValue && sync.Description == JFStringer.ToCommonFormat(hook.Resource.Fields.ReproSteps?.NewValue) && sync.Priority == int.Parse(hook.Resource.Fields.Priority?.NewValue))) { return(Ok($"Not found")); } // Update var issue = await _jira.Issues.GetIssueAsync(sync.JiraKey); issue.Summary = hook.Resource.Fields.Title != null ? hook.Resource.Fields.Title.NewValue : issue.Summary; issue.Description = hook.Resource.Fields.ReproSteps != null?JFStringer.ToCommonFormat(hook.Resource.Fields.ReproSteps.NewValue) : issue.Description; issue.Priority = hook.Resource.Fields.Priority != null ? Priority.ToJiraPriority(_context, hook.Resource.Fields.Priority.NewValue) : issue.Priority; // Sync sync.Rev = hook.Resource.Revision.Rev; sync.Title = issue.Summary; sync.Description = issue.Description; sync.Priority = Priority.ToTfsPriority(_context, issue.Priority.Name); var result = await issue.SaveChangesAsync(); await _context.SaveChangesAsync(); return(Ok("Updated")); }