/// <summary> /// Populate <see cref="PullRequestListBox"/> with <see cref="PullRequestInfo"/> from github and check off ones that are currently merged. Prompts the user to login to GitHub if they hit the rate limit /// </summary> async void LoadPullRequests() { try { Enabled = false; UseWaitCursor = true; try { PullRequestListBox.Items.Clear(); var repo = currentInterface.GetComponent <ITGRepository>(); string error = null; List <PullRequestInfo> pulls = null; //get started on this while we're processing here var pullsRequest = Task.Factory.StartNew(() => pulls = repo.MergedPullRequests(out error)); //Search for open PRs Enabled = false; UseWaitCursor = true; SearchIssuesResult result; try { result = await client.Search.SearchIssues(new SearchIssuesRequest { Repos = new RepositoryCollection { { repoOwner, repoName } }, State = ItemState.Open, Type = IssueTypeQualifier.PullRequest }); } finally { Enabled = true; UseWaitCursor = false; } //now we need to know what's merged await pullsRequest; if (pulls == null) { MessageBox.Show(String.Format(MergedPullsError, error)); } //insert the open pull requests, checking already merged once foreach (var I in result.Items) { bool alreadyMerged = false; var pull = pulls.Where(x => x.Number == I.Number).FirstOrDefault(); if (pull != null) { //we need the full info for this PR alreadyMerged = (await client.PullRequest.Get(repoOwner, repoName, I.Number)).Head.Sha == pull.Sha; if (alreadyMerged) { pulls.Remove(pull); } } InsertPullRequest(I, false, alreadyMerged); } //insert remaining merged pulls foreach (var I in pulls) { InsertItem(String.Format("#{0} - {1} - OUTDATED: {2}", I.Number, I.Title, I.Sha), true, true); } } finally { Enabled = true; UseWaitCursor = false; } } catch (ForbiddenException) { if (client.Credentials.AuthenticationType == AuthenticationType.Anonymous) //assume request limit hit { if (Program.RateLimitPrompt(client)) { LoadPullRequests(); } } else { throw; } } }