public async Task GetPullRequestInfo_ReturnTicketInfoList()
        {
            var mockResponse = GetJiraIssueResponse();
            var issueKeys    = mockResponse.Issues.Select(m => m.Key);

            _bitbucketService.Setup(b => b.GetPullRequestInfoForIssueKeys(It.IsAny <IEnumerable <string> >()))
            .ReturnsAsync(GetTicketInformation);

            var result = await _lazyGitLogic.GetPullRequestInfoForJiraTickets(issueKeys);

            Assert.Equal(3, result.Count());
        }
Exemple #2
0
        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);
        }