Пример #1
0
        public static async Task <string> BuildAsync
        (
            string repositoryFolderPath,
            string githubApiToken,
            string githubApiProduct,
            Func <Octokit.Issue, string> issueFormatter
        )
        {
            GithubRepoInfo repoInfo = GithubRepoInfo.FromRepositoryFolderPath(repositoryFolderPath);
            IReadOnlyCollection <string> commitMessages = GetCommitMessagesSinceLastTag(repositoryFolderPath);

            IReadOnlyList <Octokit.Issue> allIssues = await GetIssuesAsync(githubApiToken, githubApiProduct, repoInfo).ConfigureAwait(false);

            Dictionary <int, Octokit.Issue> issuesByNumber = allIssues.ToDictionary(i => i.Number);

            IReadOnlyList <Octokit.PullRequest> allPullRequests = await GetPullRequestsAsync(githubApiToken, githubApiProduct, repoInfo).ConfigureAwait(false);

            Dictionary <int, Octokit.PullRequest> pullRequestsByNumber = allPullRequests.ToDictionary(pr => pr.Number);

            return(commitMessages
                   .SelectMany(commitMessage => ParseIssueOrPrNumbers(commitMessage))
                   .SelectMany(issueOrPrNumber => EnumerateIssueNumbers(issueOrPrNumber))
                   .Distinct()
                   .Select(issueNumber => issuesByNumber[issueNumber])
                   .Select(issueFormatter)
                   .Aggregate
                   (
                       new StringBuilder(),
                       (builder, issueText) => builder.AppendLine(issueText),
                       builder => builder.ToString()
                   ));

            IEnumerable <int> EnumerateIssueNumbers(int issueOrPrNumber)
            => pullRequestsByNumber.TryGetValue(issueOrPrNumber, out Octokit.PullRequest pr) ? ParseIssueOrPrNumbers(pr.Body)
                                : issuesByNumber.TryGetValue(issueOrPrNumber, out Octokit.Issue issue) ? new[] { issue.Number }
                                : Enumerable.Empty <int>();
        }
Пример #2
0
 private static Task <IReadOnlyList <Octokit.Issue> > GetIssuesAsync(string githubApiToken, string githubApiProduct, GithubRepoInfo repoInfo)
 => CreateGithubClient(githubApiToken, githubApiProduct)
 .Issue
 .GetAllForRepository
 (
     repoInfo.Owner,
     repoInfo.Repository,
     new Octokit.RepositoryIssueRequest()
 {
     State = Octokit.ItemStateFilter.All
 }
 );