Exemplo n.º 1
0
        private static void MaybeShowStale(Repository repo, List <Tag> allTags, ApiMetadata api)
        {
            string expectedTagName = $"{api.Id}-{api.Version}";
            var    latestRelease   = allTags.FirstOrDefault(tag => tag.FriendlyName == expectedTagName);

            // If we don't have any releases for the API (or couldn't find the tag), skip it.
            if (latestRelease is null)
            {
                return;
            }

            var laterCommits    = repo.Commits.TakeWhile(commit => commit.Sha != latestRelease.Target.Sha);
            var relevantCommits = laterCommits
                                  .Where(GitHelpers.CreateCommitPredicate(repo, api.Id))
                                  .Where(commit => !CommitOverrides.IsSkipped(commit))
                                  .ToList();

            // No changes
            if (relevantCommits.Count == 0)
            {
                return;
            }

            string changes = relevantCommits.Count == 1 ? "change" : "changes";

            Console.WriteLine($"{api.Id,-50} {latestRelease.GetDate():yyyy-MM-dd}: {api.Version} + {relevantCommits.Count} {changes}");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets the set of pending changes for each API. Note that the release in the dictionary value
        /// has the current version and date, but the pending changes (not the list of changes *in* that release).
        /// </summary>
        internal static Dictionary <ApiMetadata, Release> GetPendingChangesByApi(Repository repo, ApiCatalog catalog)
        {
            var allTags = repo.Tags.OrderByDescending(GetDate).ToList();

            return(catalog.Apis.ToDictionary(api => api, api => GetPendingChanges(api)));

            Release GetPendingChanges(ApiMetadata api)
            {
                string expectedTagName = $"{api.Id}-{api.Version}";
                var    latestRelease   = allTags.FirstOrDefault(tag => tag.FriendlyName == expectedTagName);

                if (latestRelease is null)
                {
                    // TODO: Work out what to do for unreleased APIs.
                    // We should potentially go back to "the commit that first added the API" but that
                    // may be tricky to work out.
                    return(new Release(api.StructuredVersion, tag: null, new GitCommit[0]));
                }

                var laterCommits    = repo.Commits.TakeWhile(commit => commit.Sha != latestRelease?.Target.Sha);
                var relevantCommits = laterCommits
                                      .Where(CreateCommitPredicate(repo, catalog, api))
                                      .Where(commit => !CommitOverrides.IsSkipped(commit))
                                      .Select(commit => new GitCommit(commit))
                                      .ToList();

                return(new Release(api.StructuredVersion, latestRelease, relevantCommits));
            }
        }