void HandlePullRequest(PullRequest pr)
        {
            if (Usernames.Length > 0 && !Usernames.Contains(pr.User.Login))
            {
                return;
            }

            if (pr.State == ItemState.Open)
            {
                if (PullRequests.ContainsKey(pr))
                {
                    return;
                }

                PullRequests.Add(pr, new OpenUrlAction {
                    Url = pr.HtmlUrl.OriginalString,
                    ShortDescription = $"Review {pr.Title}",
                    Tooltip          = $"Review pull request in {Repository.Owner}/{Repository.Name}, created by {pr.User.Login}"
                });
            }
            else
            {
                if (!PullRequests.Remove(pr))
                {
                    return;
                }
            }

            Actions = PullRequests.Values.ToArray();
        }
Exemple #2
0
        async Task GetPullRequestViewsByJiraNumber(ItemState?state, DateRange searchDates, IList <string> repoNames, string jiraIssueNumber)
        {
            try
            {
                var hasNewRequests = false;

                var searchResults = await SearchPullRequests(state, searchDates, repoNames, jiraIssueNumber);

                // Gets general info on each Pull Request.
                var existingRequestIds = PullRequests.Select(r => r.Id).ToList();

                foreach (var request in searchResults.Items)
                {
                    var repositoryName = request.PullRequest.HtmlUrl.Segments[2].TrimEnd('/');

                    var pullRequest = PullRequests.FirstOrDefault(r => r.Id == request.Number);
                    if (null == pullRequest)
                    {
                        pullRequest = GetNewPullRequestView(request);
                        // Get detailed info on each Pull Request.
                        pullRequest = await GetPullRequestDetails(request, pullRequest);

                        PullRequests.Add(pullRequest);
                        if (pullRequest.State == ItemState.Open)
                        {
                            hasNewRequests = true;
                        }
                    }
                    else // already had a copy in our list.. update it
                    {
                        existingRequestIds.Remove(request.Number);
                        if (pullRequest.Updated != request.UpdatedAt.GetValueOrDefault())
                        {
                            pullRequest = await GetPullRequestDetails(request, pullRequest);
                        }
                        if (pullRequest.JiraIssues.Count == 0)
                        {
                            pullRequest = await GetPullRequestDetails(request, pullRequest);
                        }
                    }
                }

                foreach (var requestToRemove in PullRequests.Where(r => existingRequestIds.Contains(r.Id)).ToList())
                {
                    PullRequests.Remove(requestToRemove);
                }

                if (hasNewRequests)
                {
                    OnNewPullRequest();
                }

                OnGetPullRequestsComplete();
            }
            catch (Exception ex)
            {
                ExceptionHandler(ex);
            }
        }