-
Notifications
You must be signed in to change notification settings - Fork 665
Expand file tree
/
Copy pathVersionCalculatorBase.cs
More file actions
39 lines (33 loc) · 1.53 KB
/
VersionCalculatorBase.cs
File metadata and controls
39 lines (33 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
using GitVersion.Common;
using GitVersion.Extensions;
using GitVersion.Git;
using GitVersion.Logging;
namespace GitVersion.VersionCalculation;
internal abstract class VersionCalculatorBase(
ILog log, IRepositoryStore repositoryStore, Lazy<GitVersionContext> versionContext)
{
protected readonly ILog log = log.NotNull();
protected readonly IRepositoryStore repositoryStore = repositoryStore.NotNull();
private readonly Lazy<GitVersionContext> versionContext = versionContext.NotNull();
protected GitVersionContext Context => this.versionContext.Value;
protected SemanticVersionBuildMetaData CreateVersionBuildMetaData(ICommit? baseVersionSource)
{
var commitLogs = this.repositoryStore.GetCommitLog(
baseVersionSource: baseVersionSource,
currentCommit: Context.CurrentCommit,
ignore: Context.Configuration.Ignore
);
var commitsSinceTag = commitLogs.Count;
this.log.Info($"{commitsSinceTag} commits found between {baseVersionSource} and {Context.CurrentCommit}");
var shortSha = Context.CurrentCommit.Id.ToString(7);
return new SemanticVersionBuildMetaData(
versionSourceSha: baseVersionSource?.Sha,
commitsSinceTag: commitsSinceTag,
branch: Context.CurrentBranch.Name.Friendly,
commitSha: Context.CurrentCommit.Sha,
commitShortSha: shortSha,
commitDate: Context.CurrentCommit.When,
numberOfUnCommittedChanges: Context.NumberOfUncommittedChanges
);
}
}