private async Task GetProjectGitHubDataAsync(IDocument input, IExecutionContext context, ConcurrentDictionary <string, object> metadata) { // Extract the GitHub owner and name if (Uri.TryCreate(input.GetString(SiteKeys.SourceCode), UriKind.Absolute, out Uri sourceCode) && sourceCode.Host.EndsWith("github.com", StringComparison.OrdinalIgnoreCase)) { string owner = sourceCode.Segments[1].Trim('/'); string name = sourceCode.Segments[2].Trim('/'); // Get the repository context.LogInformation($"Getting GitHub project data for {owner}/{name}"); Repository repository = await _gitHub.GetAsync(x => x.Repository.Get(owner, name), context); // Get the metadata metadata.TryAdd(SiteKeys.StargazersCount, repository.StargazersCount); metadata.TryAdd(SiteKeys.ForksCount, repository.ForksCount); metadata.TryAdd(SiteKeys.OpenIssuesCount, repository.OpenIssuesCount); metadata.TryAdd(SiteKeys.PushedAt, repository.PushedAt); metadata.TryAdd(SiteKeys.CreatedAt, repository.CreatedAt); metadata.TryAdd(SiteKeys.Title, repository.Name); metadata.TryAdd(SiteKeys.Description, repository.Description); metadata.TryAdd(SiteKeys.Website, repository.Homepage); if (GitHubManager.MicrosoftOwners.Contains(owner)) { metadata.GetOrAdd(SiteKeys.Microsoft, true); } if (_foundation.IsInFoundation(owner, name)) { metadata.GetOrAdd(SiteKeys.Foundation, true); } // Get the readme (will throw if there's no readme) context.LogInformation($"Getting GitHub readme for {owner}/{name}"); try { string readme = await _gitHub.GetAsync(x => x.Repository.Content.GetReadmeHtml(owner, name), context, false); if (!string.IsNullOrEmpty(readme)) { metadata.TryAdd(SiteKeys.Readme, readme); } } catch (Exception ex) { context.LogInformation($"Could not get GitHub readme for {owner}/{name}: {ex.Message}"); } } }
protected override async Task <IEnumerable <IDocument> > ExecuteInputAsync(IDocument input, IExecutionContext context) { IDocument output = input; // Extract the GitHub owner and name if (Uri.TryCreate(input.GetString("SourceCode"), UriKind.Absolute, out Uri sourceCode) && sourceCode.Host.EndsWith("github.com", StringComparison.OrdinalIgnoreCase)) { string owner = sourceCode.Segments[1].Trim('/'); string name = sourceCode.Segments[2].Trim('/'); // Get issue data context.LogInformation($"Getting GitHub issue data for {owner}/{name}"); IReadOnlyList <Issue> issues = await _gitHub.GetAsync( x => x.Issue.GetAllForRepository( owner, name, new RepositoryIssueRequest { Filter = IssueFilter.All }, new ApiOptions { PageSize = 100 }), context); issues = issues .Where(x => x.PullRequest == null) .ToList(); // Get the metadata and document if (issues.Count > 0) { Models.Issue[] issueData = issues .Select(x => new Models.Issue(x, OneDayAgo)) .OrderByDescending(x => x.CreatedAt) .ToArray(); MetadataItems metadata = new MetadataItems { { "GitHubOwner", owner }, { "GitHubName", name }, { "Issues", issueData }, { "IssuesCount", issueData.Length }, { "RecentIssuesCount", issueData.Count(x => x.Recent) }, { "HelpWantedIssuesCount", issueData.Count(x => x.HelpWanted) } }; if (!input.ContainsKey("Microsoft") && GitHubManager.MicrosoftOwners.Contains(owner, StringComparer.OrdinalIgnoreCase)) { metadata.Add("Microsoft", true); } if (!input.ContainsKey("Foundation") && _foundation.IsInFoundation(owner, name)) { metadata.Add("Foundation", true); } output = input.Clone(metadata); } } return(output.Yield()); }