public SemVer(SemVer lastSemVer, int commitsSince) { _major = lastSemVer.Major; _minor = lastSemVer.Minor; _patch = commitsSince > 0 ? lastSemVer.Patch + 1 : lastSemVer.Patch; _commitsSince = commitsSince; }
protected override void EndProcessing() { using (var repository = new Repository(_directory)) { SemVer semVer; var lastSemVerTag = GetLastSemVerTag(repository); if (lastSemVerTag == null) { semVer = new SemVer(new SemVer(0, 0, 0), repository.Commits.Count()); } else { var commitsSinceTag = repository.Head.Commits.TakeWhile(x => x != lastSemVerTag.Item1.Target).Count(); semVer = new SemVer(lastSemVerTag.Item2, commitsSinceTag); } WriteObject(new VersionInformation(repository.Head.Name, repository.Head.Tip.Sha, semVer)); } }
public VersionInformation(string branch, string commit, SemVer semVer) { _branch = branch; _commit = commit; _semVer = semVer; }
private Tuple <Tag, SemVer> GetLastSemVerTag(IRepository repository) { var relatedTags = repository.Head.Commits.SelectMany(x => repository.Tags.Where(y => y.Target == x)).ToList(); return(relatedTags.Select(x => Tuple.Create(x, SemVer.TryParse(x.Name))).FirstOrDefault(x => x.Item2 != null)); }