2022-07-31 17:38:23 -05:00
|
|
|
using LibGit2Sharp;
|
|
|
|
|
|
|
|
public class CommitDetail
|
|
|
|
{
|
|
|
|
private List<string>? _authors;
|
|
|
|
private SortedList<string, int>? _commitDetails;
|
2022-08-04 14:53:49 -05:00
|
|
|
private string _currentBranch;
|
2022-07-31 17:38:23 -05:00
|
|
|
|
|
|
|
public List<string>? Authors
|
|
|
|
{
|
|
|
|
get { return _authors; }
|
|
|
|
set { _authors = value; }
|
|
|
|
}
|
|
|
|
|
|
|
|
public SortedList<string, int>? CommitDetails
|
|
|
|
{
|
|
|
|
get { return _commitDetails; }
|
|
|
|
set { _commitDetails = value; }
|
|
|
|
}
|
|
|
|
|
2022-08-04 14:53:49 -05:00
|
|
|
public string CurrentBranch
|
|
|
|
{
|
|
|
|
get { return _currentBranch; }
|
|
|
|
set { _currentBranch = value; }
|
|
|
|
}
|
|
|
|
|
2022-07-31 17:38:23 -05:00
|
|
|
public CommitDetail()
|
|
|
|
{
|
|
|
|
_authors = new List<string>();
|
|
|
|
_commitDetails = new SortedList<string, int>();
|
2022-08-04 14:53:49 -05:00
|
|
|
_currentBranch = GetCurrentBranch();
|
2022-07-31 17:38:23 -05:00
|
|
|
}
|
|
|
|
|
2022-08-04 14:53:49 -05:00
|
|
|
public void GetCurrentCommitsByName()
|
2022-07-31 17:38:23 -05:00
|
|
|
{
|
|
|
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
|
|
|
{
|
|
|
|
foreach (var c in repo.Commits)
|
|
|
|
{
|
|
|
|
if (!_authors.Contains(c.Author.Name))
|
|
|
|
{
|
|
|
|
_authors.Add(c.Author.Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var a in _authors)
|
|
|
|
{
|
|
|
|
int commitCount = repo.Commits.Where(r => r.Author.Name == a).Count();
|
|
|
|
_commitDetails.Add(a, commitCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-08-04 14:53:49 -05:00
|
|
|
public void GetCurrentCommitsByEmail()
|
2022-07-31 17:38:23 -05:00
|
|
|
{
|
|
|
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
|
|
|
{
|
|
|
|
foreach (var c in repo.Commits)
|
|
|
|
{
|
|
|
|
if (!_authors.Contains(c.Author.Email))
|
|
|
|
{
|
|
|
|
_authors.Add(c.Author.Email);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var a in _authors)
|
|
|
|
{
|
|
|
|
int commitCount = repo.Commits.Where(r => r.Author.Email == a).Count();
|
|
|
|
_commitDetails.Add(a, commitCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int GetCommitTotal()
|
|
|
|
{
|
|
|
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
|
|
|
{
|
|
|
|
return repo.Commits.Count();
|
|
|
|
}
|
|
|
|
}
|
2022-08-04 14:53:49 -05:00
|
|
|
|
|
|
|
public string GetCurrentBranch()
|
|
|
|
{
|
|
|
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
|
|
|
{
|
|
|
|
return repo.Head.Reference.TargetIdentifier;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void GetCommitsByBranch(string branchName)
|
|
|
|
{
|
|
|
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
|
|
|
{
|
|
|
|
var branchResult = repo.Branches[branchName];
|
|
|
|
|
|
|
|
if (branchResult == null)
|
|
|
|
{
|
|
|
|
branchResult = repo.Branches[$"origin/{branchName}"];
|
|
|
|
var remoteBranch = repo.CreateBranch(branchName, branchResult.Tip);
|
|
|
|
repo.Branches.Update(remoteBranch, b => b.UpstreamBranch = $"refs/heads/{branchName}");
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var c in branchResult.Commits)
|
|
|
|
{
|
|
|
|
if (!_authors.Contains(c.Author.Name))
|
|
|
|
{
|
|
|
|
_authors.Add(c.Author.Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var a in _authors)
|
|
|
|
{
|
|
|
|
int commitCount = branchResult.Commits.Where(r => r.Author.Name == a).Count();
|
|
|
|
_commitDetails.Add(a, commitCount);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void GetCommitsByTag(string tagName)
|
|
|
|
{
|
|
|
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
|
|
|
{
|
2022-08-23 17:56:56 -05:00
|
|
|
var tagResult = repo.Tags[tagName].Target.Sha;
|
|
|
|
|
|
|
|
var commitFilter = new CommitFilter
|
|
|
|
{
|
|
|
|
IncludeReachableFrom = tagResult,
|
|
|
|
};
|
|
|
|
|
|
|
|
var query = repo.Commits.QueryBy(commitFilter);
|
|
|
|
|
|
|
|
foreach (var c in query)
|
|
|
|
{
|
|
|
|
if (!_authors.Contains(c.Author.Name))
|
|
|
|
{
|
|
|
|
_authors.Add(c.Author.Name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var a in _authors)
|
|
|
|
{
|
|
|
|
int commitCount = query.Where(r => r.Author.Name == a).Count();
|
|
|
|
_commitDetails.Add(a, commitCount);
|
|
|
|
}
|
|
|
|
|
2022-08-04 14:53:49 -05:00
|
|
|
}
|
|
|
|
}
|
2022-07-31 17:38:23 -05:00
|
|
|
}
|