protected override void ExecuteImpl(string[] args) { var root = DirectoryLayout.DetermineRootDirectory(); var catalog = ApiCatalog.Load(); using var repo = new Repository(root); var pendingChangesByApi = GitHelpers.GetPendingChangesByApi(repo, catalog); // TODO: Work out what to do with unreleased APIs. Do we want to show them or not? foreach (var api in catalog.Apis) { var release = pendingChangesByApi[api]; var commits = release.Commits; if (commits.Count == 0) { continue; } string changes = commits.Count == 1 ? "change" : "changes"; Console.WriteLine($"{api.Id,-50} {release.ReleaseDate:yyyy-MM-dd}: {release.Version} + {commits.Count} {changes}"); } }
private static IEnumerable <Release> LoadReleases(Repository repo, ApiCatalog catalog, ApiMetadata api) { var id = api.Id; var commitPredicate = GitHelpers.CreateCommitPredicate(repo, catalog, api); List <Release> releases = new List <Release>(); StructuredVersion currentVersion = StructuredVersion.FromString(api.Version); Commit currentTagCommit = null; // "Pending" as in "haven't been yielded in a release yet" List <GitCommit> pendingCommits = new List <GitCommit>(); var tagPrefix = $"{id}-"; var versionsCommitId = repo.Tags .Where(tag => tag.FriendlyName.StartsWith(tagPrefix)) .ToDictionary(tag => tag.Target.Id, tag => tag.FriendlyName.Substring(tagPrefix.Length)); foreach (var commit in repo.Head.Commits) { if (commitPredicate(commit)) { pendingCommits.Add(new GitCommit(commit)); } if (versionsCommitId.TryGetValue(commit.Id, out string version) && !version.StartsWith("0.")) { yield return(new Release(currentVersion, currentTagCommit, pendingCommits)); // Release constructor clones the list, so we're safe to clear it. pendingCommits.Clear(); currentTagCommit = commit; currentVersion = StructuredVersion.FromString(version); } } if (pendingCommits.Count != 0) { yield return(new Release(currentVersion, currentTagCommit, pendingCommits)); } }
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)).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}"); }