private void AddIssueOrPullRequest(GitHubEventRepository repository, GitHubEventIssueOrPullRequest issueOrPullRequest)
            {
                var index = _indexService.Index;

                if (index is null)
                {
                    return;
                }

                var crawledRepo = index.Repos.SingleOrDefault(r => r.Id == repository.Id);

                if (crawledRepo is null)
                {
                    return;
                }

                var crawledIssue = new CrawledIssue();

                crawledIssue.Id            = issueOrPullRequest.Id;
                crawledIssue.Repo          = crawledRepo;
                crawledIssue.Number        = issueOrPullRequest.Number;
                crawledIssue.CreatedAt     = issueOrPullRequest.CreatedAt;
                crawledIssue.CreatedBy     = issueOrPullRequest.User.Login;
                crawledIssue.IsPullRequest = issueOrPullRequest is GitHubEventPullRequest;

                UpdateIssueOrPullRequest(repository, issueOrPullRequest, crawledIssue);

                crawledRepo.Issues[crawledIssue.Number] = crawledIssue;

                AddTrieTerms(crawledIssue, crawledIssue.GetTrieTerms());

                _indexService.NotifyIndexChanged();
            }
            private void RemoveIssue(CrawledRepo crawledRepo, CrawledIssue crawledIssue)
            {
                var oldTrieTerms = crawledIssue.GetTrieTerms();

                crawledRepo.Issues.Remove(crawledIssue.Number);

                RemoveTrieTerms(crawledIssue, oldTrieTerms);
            }
            private void RemoveTrieTerms(CrawledIssue issue, IEnumerable <string> terms)
            {
                var trie = _indexService.Index?.Trie;

                if (trie is null)
                {
                    return;
                }

                foreach (var term in terms)
                {
                    trie.Remove(term, issue);
                }
            }
            private void UpdateTrie(CrawledIssue issue, IEnumerable <string> oldTerms)
            {
                var trie = _indexService.Index?.Trie;

                if (trie is null)
                {
                    return;
                }

                var newTerms = issue.GetTrieTerms();

                var removedTerms = oldTerms.Where(t => !newTerms.Contains(t));
                var addedTerms   = newTerms.Where(t => !oldTerms.Contains(t));

                RemoveTrieTerms(issue, removedTerms);
                AddTrieTerms(issue, addedTerms);
            }
Пример #5
0
 static string GetState(CrawledIssue issue)
 {
     if (issue.IsPullRequest && issue.IsMerged)
     {
         return("merged");
     }
     else if (issue.IsPullRequest && !issue.IsOpen)
     {
         return("unmerged");
     }
     else if (issue.IsOpen)
     {
         return("open");
     }
     else
     {
         return("closed");
     }
 }
            private void UpdateIssueOrPullRequest(GitHubEventRepository repository, GitHubEventIssueOrPullRequest issueOrPullRequest, CrawledIssue crawledIssue)
            {
                crawledIssue.IsOpen    = issueOrPullRequest.State == "open";
                crawledIssue.Title     = issueOrPullRequest.Title;
                crawledIssue.IsLocked  = issueOrPullRequest.Locked;
                crawledIssue.UpdatedAt = issueOrPullRequest.UpdatedAt; // TODO: Non-atomic write
                crawledIssue.ClosedAt  = issueOrPullRequest.ClosedAt;  // TODO: Non-atomic write
                crawledIssue.Assignees = issueOrPullRequest.Assignees.Select(a => a.Login).ToArray();
                crawledIssue.Labels    = issueOrPullRequest.Labels.Select(l => GetOrCreateLabel(repository, l)).ToArray();
                crawledIssue.Milestone = GetOrCreateMilestone(repository, issueOrPullRequest.Milestone);

                if (issueOrPullRequest is GitHubEventPullRequest pullRequest)
                {
                    crawledIssue.IsMerged = pullRequest.Merged;
                    crawledIssue.IsDraft  = pullRequest.Draft;
                }
            }