From 6691d26b9d69e2d84350f24b84a90c9c46d2f0b0 Mon Sep 17 00:00:00 2001 From: "Wyatt J. Miller" Date: Sun, 31 Jul 2022 18:38:23 -0400 Subject: [PATCH] added commit logic --- BLL/CommitDetail.cs | 73 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 BLL/CommitDetail.cs diff --git a/BLL/CommitDetail.cs b/BLL/CommitDetail.cs new file mode 100644 index 0000000..8585e9e --- /dev/null +++ b/BLL/CommitDetail.cs @@ -0,0 +1,73 @@ +using LibGit2Sharp; + +public class CommitDetail +{ + private List? _authors; + private SortedList? _commitDetails; + + public List? Authors + { + get { return _authors; } + set { _authors = value; } + } + + public SortedList? CommitDetails + { + get { return _commitDetails; } + set { _commitDetails = value; } + } + + public CommitDetail() + { + _authors = new List(); + _commitDetails = new SortedList(); + } + + public void GetAllCommitsByName() + { + 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); + } + } + } + + public void GetAllCommitsByEmail() + { + 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(); + } + } +}