wip: starting work on dir option
This commit is contained in:
parent
73f8e80a23
commit
702188bc22
@ -5,13 +5,14 @@ public class CommitDetail
|
|||||||
private List<string>? _authors;
|
private List<string>? _authors;
|
||||||
private SortedList<string, int>? _commitDetails;
|
private SortedList<string, int>? _commitDetails;
|
||||||
private string _currentBranch;
|
private string _currentBranch;
|
||||||
|
private string? _selectedDir;
|
||||||
|
|
||||||
public List<string>? Authors
|
public List<string>? Authors
|
||||||
{
|
{
|
||||||
get { return _authors; }
|
get { return _authors; }
|
||||||
set { _authors = value; }
|
set { _authors = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public SortedList<string, int>? CommitDetails
|
public SortedList<string, int>? CommitDetails
|
||||||
{
|
{
|
||||||
get { return _commitDetails; }
|
get { return _commitDetails; }
|
||||||
@ -24,16 +25,23 @@ public class CommitDetail
|
|||||||
set { _currentBranch = value; }
|
set { _currentBranch = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public CommitDetail()
|
public string SelectedDir
|
||||||
|
{
|
||||||
|
get { return _selectedDir; }
|
||||||
|
set { _selectedDir = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public CommitDetail(string dir)
|
||||||
{
|
{
|
||||||
_authors = new List<string>();
|
_authors = new List<string>();
|
||||||
_commitDetails = new SortedList<string, int>();
|
_commitDetails = new SortedList<string, int>();
|
||||||
_currentBranch = GetCurrentBranch();
|
_currentBranch = GetCurrentBranch();
|
||||||
|
_selectedDir = Directory.Exists(dir) ? dir : Directory.GetCurrentDirectory();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetCurrentCommitsByName()
|
public void GetCurrentCommitsByName()
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
using (var repo = new Repository(_selectedDir))
|
||||||
{
|
{
|
||||||
foreach (var c in repo.Commits)
|
foreach (var c in repo.Commits)
|
||||||
{
|
{
|
||||||
@ -42,7 +50,7 @@ public class CommitDetail
|
|||||||
_authors.Add(c.Author.Name);
|
_authors.Add(c.Author.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var a in _authors)
|
foreach (var a in _authors)
|
||||||
{
|
{
|
||||||
int commitCount = repo.Commits.Where(r => r.Author.Name == a).Count();
|
int commitCount = repo.Commits.Where(r => r.Author.Name == a).Count();
|
||||||
@ -53,7 +61,7 @@ public class CommitDetail
|
|||||||
|
|
||||||
public void GetCurrentCommitsByEmail()
|
public void GetCurrentCommitsByEmail()
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
using (var repo = new Repository(_selectedDir))
|
||||||
{
|
{
|
||||||
foreach (var c in repo.Commits)
|
foreach (var c in repo.Commits)
|
||||||
{
|
{
|
||||||
@ -62,7 +70,7 @@ public class CommitDetail
|
|||||||
_authors.Add(c.Author.Email);
|
_authors.Add(c.Author.Email);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var a in _authors)
|
foreach (var a in _authors)
|
||||||
{
|
{
|
||||||
int commitCount = repo.Commits.Where(r => r.Author.Email == a).Count();
|
int commitCount = repo.Commits.Where(r => r.Author.Email == a).Count();
|
||||||
@ -73,7 +81,7 @@ public class CommitDetail
|
|||||||
|
|
||||||
public int GetCommitTotal()
|
public int GetCommitTotal()
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
using (var repo = new Repository(_selectedDir))
|
||||||
{
|
{
|
||||||
return repo.Commits.Count();
|
return repo.Commits.Count();
|
||||||
}
|
}
|
||||||
@ -81,7 +89,7 @@ public class CommitDetail
|
|||||||
|
|
||||||
public string GetCurrentBranch()
|
public string GetCurrentBranch()
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
using (var repo = new Repository(_selectedDir))
|
||||||
{
|
{
|
||||||
return repo.Head.Reference.TargetIdentifier;
|
return repo.Head.Reference.TargetIdentifier;
|
||||||
}
|
}
|
||||||
@ -89,7 +97,7 @@ public class CommitDetail
|
|||||||
|
|
||||||
public void GetCommitsByBranch(string branchName)
|
public void GetCommitsByBranch(string branchName)
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
using (var repo = new Repository(_selectedDir))
|
||||||
{
|
{
|
||||||
var branchResult = repo.Branches[branchName];
|
var branchResult = repo.Branches[branchName];
|
||||||
|
|
||||||
@ -100,7 +108,7 @@ public class CommitDetail
|
|||||||
branchResult = repo.Branches[$"origin/{branchName}"];
|
branchResult = repo.Branches[$"origin/{branchName}"];
|
||||||
var remoteBranch = repo.CreateBranch(branchName, branchResult.Tip);
|
var remoteBranch = repo.CreateBranch(branchName, branchResult.Tip);
|
||||||
repo.Branches.Update(remoteBranch, b => b.UpstreamBranch = $"refs/heads/{branchName}");
|
repo.Branches.Update(remoteBranch, b => b.UpstreamBranch = $"refs/heads/{branchName}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (System.Exception)
|
catch (System.Exception)
|
||||||
{
|
{
|
||||||
@ -115,7 +123,7 @@ public class CommitDetail
|
|||||||
_authors.Add(c.Author.Name);
|
_authors.Add(c.Author.Name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var a in _authors)
|
foreach (var a in _authors)
|
||||||
{
|
{
|
||||||
int commitCount = branchResult.Commits.Where(r => r.Author.Name == a).Count();
|
int commitCount = branchResult.Commits.Where(r => r.Author.Name == a).Count();
|
||||||
@ -123,15 +131,15 @@ public class CommitDetail
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetCommitsByTag(string tagName)
|
public void GetCommitsByTag(string tagName)
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
using (var repo = new Repository(_selectedDir))
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var tagResult = repo.Tags[tagName].Target.Sha;
|
var tagResult = repo.Tags[tagName].Target.Sha;
|
||||||
|
|
||||||
var commitFilter = new CommitFilter
|
var commitFilter = new CommitFilter
|
||||||
{
|
{
|
||||||
IncludeReachableFrom = tagResult,
|
IncludeReachableFrom = tagResult,
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AssemblyName>drillsergeant</AssemblyName>
|
<AssemblyName>drillsergeant</AssemblyName>
|
||||||
<Version>1.1.0</Version>
|
<Version>1.2.0</Version>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
222
Program.cs
222
Program.cs
@ -22,119 +22,141 @@ static class Program
|
|||||||
);
|
);
|
||||||
tagOption.AddAlias("-t");
|
tagOption.AddAlias("-t");
|
||||||
|
|
||||||
|
var dirOption = new Option<string>(
|
||||||
|
"--file",
|
||||||
|
"Specify a git directory"
|
||||||
|
);
|
||||||
|
dirOption.AddAlias("-f");
|
||||||
|
|
||||||
var rootCommand = new RootCommand("Get a tally of contributors' commits")
|
var rootCommand = new RootCommand("Get a tally of contributors' commits")
|
||||||
{
|
{
|
||||||
outputOption,
|
outputOption,
|
||||||
branchOption,
|
branchOption,
|
||||||
tagOption,
|
tagOption,
|
||||||
|
dirOption,
|
||||||
};
|
};
|
||||||
|
|
||||||
rootCommand.SetHandler((outputOptionValue, branchOptionValue, tagOptionValue) => {
|
rootCommand.SetHandler((outputOptionValue, branchOptionValue, tagOptionValue, dirOptionValue) =>
|
||||||
CommitDetail commits = new CommitDetail();
|
{
|
||||||
|
CommitDetail commits = new CommitDetail(dirOptionValue);
|
||||||
switch (outputOptionValue)
|
|
||||||
|
switch (outputOptionValue)
|
||||||
|
{
|
||||||
|
case "stdout":
|
||||||
|
StdOutDataService outDataService = new StdOutDataService();
|
||||||
|
DataAccess dataAccess = new DataAccess(outDataService);
|
||||||
|
|
||||||
|
if (branchOptionValue != null && tagOptionValue != null)
|
||||||
{
|
{
|
||||||
case "stdout":
|
Console.WriteLine("Please specify either a branch or a tag");
|
||||||
StdOutDataService outDataService = new StdOutDataService();
|
Environment.Exit(2);
|
||||||
DataAccess dataAccess = new DataAccess(outDataService);
|
}
|
||||||
|
else if (branchOptionValue != null && tagOptionValue == null)
|
||||||
if (branchOptionValue != null && tagOptionValue != null) {
|
{
|
||||||
Console.WriteLine("Please specify either a branch or a tag");
|
switch (branchOptionValue)
|
||||||
Environment.Exit(2);
|
{
|
||||||
} else if (branchOptionValue != null && tagOptionValue == null) {
|
case null:
|
||||||
switch (branchOptionValue)
|
|
||||||
{
|
|
||||||
case null:
|
|
||||||
commits.GetCurrentCommitsByName();
|
|
||||||
dataAccess.WriteData(commits.CommitDetails);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
commits.GetCommitsByBranch(branchOptionValue);
|
|
||||||
dataAccess.WriteData(commits.CommitDetails);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} else if (branchOptionValue == null && tagOptionValue != null) {
|
|
||||||
commits.GetCommitsByTag(tagOptionValue);
|
|
||||||
dataAccess.WriteData(commits.CommitDetails);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "xlsx":
|
|
||||||
ExcelDataService excelDataService = new ExcelDataService();
|
|
||||||
DataAccess dataAccessExcelCase = new DataAccess(excelDataService);
|
|
||||||
|
|
||||||
if (branchOptionValue != null && tagOptionValue != null) {
|
|
||||||
Console.WriteLine("Please specify either a branch or a tag.");
|
|
||||||
Environment.Exit(2);
|
|
||||||
} else if (branchOptionValue != null && tagOptionValue == null) {
|
|
||||||
switch (branchOptionValue)
|
|
||||||
{
|
|
||||||
case null:
|
|
||||||
commits.GetCurrentCommitsByName();
|
|
||||||
dataAccessExcelCase.WriteData(commits.CommitDetails);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
commits.GetCommitsByBranch(branchOptionValue);
|
|
||||||
dataAccessExcelCase.WriteData(commits.CommitDetails);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} else if (branchOptionValue == null && tagOptionValue != null) {
|
|
||||||
commits.GetCommitsByTag(tagOptionValue);
|
|
||||||
dataAccessExcelCase.WriteData(commits.CommitDetails);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "pdf":
|
|
||||||
PdfDataService pdfDataService = new PdfDataService();
|
|
||||||
DataAccess dataAccessPdfCase = new DataAccess(pdfDataService);
|
|
||||||
|
|
||||||
switch (branchOptionValue)
|
|
||||||
{
|
|
||||||
case null:
|
|
||||||
commits.GetCurrentCommitsByName();
|
|
||||||
dataAccessPdfCase.WriteData(commits.CommitDetails);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
commits.GetCommitsByBranch(branchOptionValue);
|
|
||||||
dataAccessPdfCase.WriteData(commits.CommitDetails);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case null:
|
|
||||||
StdOutDataService stdOutDataService = new StdOutDataService();
|
|
||||||
DataAccess dataAccessNullCase = new DataAccess(stdOutDataService);
|
|
||||||
|
|
||||||
if (branchOptionValue != null && tagOptionValue != null) {
|
|
||||||
Console.WriteLine("Please specify either a branch or a tag.");
|
|
||||||
Environment.Exit(2);
|
|
||||||
} else if (branchOptionValue != null && tagOptionValue == null) {
|
|
||||||
switch (branchOptionValue)
|
|
||||||
{
|
|
||||||
case null:
|
|
||||||
commits.GetCurrentCommitsByName();
|
|
||||||
dataAccessNullCase.WriteData(commits.CommitDetails);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
commits.GetCommitsByBranch(branchOptionValue);
|
|
||||||
dataAccessNullCase.WriteData(commits.CommitDetails);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} else if (branchOptionValue == null && tagOptionValue != null) {
|
|
||||||
commits.GetCommitsByTag(tagOptionValue);
|
|
||||||
dataAccessNullCase.WriteData(commits.CommitDetails);
|
|
||||||
} else {
|
|
||||||
commits.GetCurrentCommitsByName();
|
commits.GetCurrentCommitsByName();
|
||||||
dataAccessNullCase.WriteData(commits.CommitDetails);
|
dataAccess.WriteData(commits.CommitDetails);
|
||||||
}
|
break;
|
||||||
|
default:
|
||||||
|
commits.GetCommitsByBranch(branchOptionValue);
|
||||||
|
dataAccess.WriteData(commits.CommitDetails);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (branchOptionValue == null && tagOptionValue != null)
|
||||||
|
{
|
||||||
|
commits.GetCommitsByTag(tagOptionValue);
|
||||||
|
dataAccess.WriteData(commits.CommitDetails);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "xlsx":
|
||||||
|
ExcelDataService excelDataService = new ExcelDataService();
|
||||||
|
DataAccess dataAccessExcelCase = new DataAccess(excelDataService);
|
||||||
|
|
||||||
|
if (branchOptionValue != null && tagOptionValue != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please specify either a branch or a tag.");
|
||||||
|
Environment.Exit(2);
|
||||||
|
}
|
||||||
|
else if (branchOptionValue != null && tagOptionValue == null)
|
||||||
|
{
|
||||||
|
switch (branchOptionValue)
|
||||||
|
{
|
||||||
|
case null:
|
||||||
|
commits.GetCurrentCommitsByName();
|
||||||
|
dataAccessExcelCase.WriteData(commits.CommitDetails);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
commits.GetCommitsByBranch(branchOptionValue);
|
||||||
|
dataAccessExcelCase.WriteData(commits.CommitDetails);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (branchOptionValue == null && tagOptionValue != null)
|
||||||
|
{
|
||||||
|
commits.GetCommitsByTag(tagOptionValue);
|
||||||
|
dataAccessExcelCase.WriteData(commits.CommitDetails);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "pdf":
|
||||||
|
PdfDataService pdfDataService = new PdfDataService();
|
||||||
|
DataAccess dataAccessPdfCase = new DataAccess(pdfDataService);
|
||||||
|
|
||||||
|
switch (branchOptionValue)
|
||||||
|
{
|
||||||
|
case null:
|
||||||
|
commits.GetCurrentCommitsByName();
|
||||||
|
dataAccessPdfCase.WriteData(commits.CommitDetails);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
System.Console.WriteLine("This should not happen...");
|
commits.GetCommitsByBranch(branchOptionValue);
|
||||||
Environment.Exit(4);
|
dataAccessPdfCase.WriteData(commits.CommitDetails);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
},
|
break;
|
||||||
outputOption, branchOption, tagOption);
|
case null:
|
||||||
|
StdOutDataService stdOutDataService = new StdOutDataService();
|
||||||
|
DataAccess dataAccessNullCase = new DataAccess(stdOutDataService);
|
||||||
|
|
||||||
|
if (branchOptionValue != null && tagOptionValue != null)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Please specify either a branch or a tag.");
|
||||||
|
Environment.Exit(2);
|
||||||
|
}
|
||||||
|
else if (branchOptionValue != null && tagOptionValue == null)
|
||||||
|
{
|
||||||
|
switch (branchOptionValue)
|
||||||
|
{
|
||||||
|
case null:
|
||||||
|
commits.GetCurrentCommitsByName();
|
||||||
|
dataAccessNullCase.WriteData(commits.CommitDetails);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
commits.GetCommitsByBranch(branchOptionValue);
|
||||||
|
dataAccessNullCase.WriteData(commits.CommitDetails);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (branchOptionValue == null && tagOptionValue != null)
|
||||||
|
{
|
||||||
|
commits.GetCommitsByTag(tagOptionValue);
|
||||||
|
dataAccessNullCase.WriteData(commits.CommitDetails);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
commits.GetCurrentCommitsByName();
|
||||||
|
dataAccessNullCase.WriteData(commits.CommitDetails);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
System.Console.WriteLine("This should not happen...");
|
||||||
|
Environment.Exit(4);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
outputOption, branchOption, tagOption, dirOption);
|
||||||
|
|
||||||
rootCommand.Invoke(args);
|
rootCommand.Invoke(args);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user