diff --git a/BLL/CommitDetail.cs b/BLL/CommitDetail.cs index 8585e9e..4681e1d 100644 --- a/BLL/CommitDetail.cs +++ b/BLL/CommitDetail.cs @@ -4,6 +4,7 @@ public class CommitDetail { private List? _authors; private SortedList? _commitDetails; + private string _currentBranch; public List? Authors { @@ -17,13 +18,20 @@ public class CommitDetail set { _commitDetails = value; } } + public string CurrentBranch + { + get { return _currentBranch; } + set { _currentBranch = value; } + } + public CommitDetail() { _authors = new List(); _commitDetails = new SortedList(); + _currentBranch = GetCurrentBranch(); } - public void GetAllCommitsByName() + public void GetCurrentCommitsByName() { using (var repo = new Repository(Directory.GetCurrentDirectory())) { @@ -43,7 +51,7 @@ public class CommitDetail } } - public void GetAllCommitsByEmail() + public void GetCurrentCommitsByEmail() { using (var repo = new Repository(Directory.GetCurrentDirectory())) { @@ -70,4 +78,50 @@ public class CommitDetail return repo.Commits.Count(); } } + + 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())) + { + var tagResult = repo.Tags[tagName]; + System.Console.WriteLine(tagResult); + } + } }