public async Task Run() { var jiraResponse = await _lazyGitLogic.GetJiraTickets(); if (!jiraResponse.Issues.Any()) { Log.Debug("No Jira tickets to process, terminating application."); return; } var ticketList = (await _lazyGitLogic.GetPullRequestInfoForJiraTickets(jiraResponse.Issues.Select(i => i.Key))) .ToList(); if (!ticketList.Any()) { Log.Debug("No pull requests found for Jira tickets, terminating application."); return; } foreach (var ticket in ticketList) { ticket.Summary = jiraResponse.Issues .First(jt => jt.Key == ticket.JiraKey).Fields.Summary ?? string.Empty; if (ticket.PullRequestId == 0) { continue; } var rebaseResult = _lazyGitLogic.RebaseTicket(ticket); ticket.RebaseStatus = rebaseResult.Status; ticket.JiraUrl = _baseTicketUrl + ticket.JiraKey; if (!rebaseResult.RebaseSuccess) { continue; } // Don't delete the branch or update the Jira ticket if the merge failed if (!_lazyGitLogic.MergePullRequest(ticket.PullRequestId)) { continue; } _lazyGitLogic.DeleteBranch(rebaseResult.SourceBranch); var updateSuccess = await _lazyGitLogic.UpdateJiraTicket(ticket.JiraKey); if (!updateSuccess) { Log.Warning("Failed to update Jira ticket with key: {JiraKey}", ticket.JiraKey); } } _lazyGitLogic.ProcessEmails(ticketList); }
public void ProcessEmails_DoesNotCall_SendMergeConflictEmails() { // Set ticket status' to Success to ensure MergeConflict emails aren't sent var tickets = GetTicketInformation(); tickets = tickets.Select(t => { t.RebaseStatus = RebaseStatus.Success; return(t); }); _emailService.Setup(e => e.SendEmailReport(It.IsAny <IEnumerable <TicketInformation> >())); _lazyGitLogic.ProcessEmails(tickets.ToList()); _emailService.Verify(e => e.SendEmailReport(It.IsAny <IEnumerable <TicketInformation> >()), Times.Once); _emailService.Verify(e => e.SendMergeConflictEmails(It.IsAny <IEnumerable <TicketInformation> >()), Times.Never); }