Compare commits
No commits in common. "master" and "pdfDataService" have entirely different histories.
master
...
pdfDataSer
24
.github/workflows/dotnet.yml
vendored
24
.github/workflows/dotnet.yml
vendored
@ -1,24 +0,0 @@
|
|||||||
# This workflow will build a .NET project
|
|
||||||
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net
|
|
||||||
|
|
||||||
name: .NET build
|
|
||||||
|
|
||||||
on: [push]
|
|
||||||
|
|
||||||
jobs:
|
|
||||||
build:
|
|
||||||
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
- name: Setup .NET
|
|
||||||
uses: actions/setup-dotnet@v3
|
|
||||||
with:
|
|
||||||
dotnet-version: 6.0.x
|
|
||||||
- name: Restore dependencies
|
|
||||||
run: dotnet restore
|
|
||||||
- name: Build
|
|
||||||
run: dotnet build --no-restore
|
|
||||||
- name: Test
|
|
||||||
run: dotnet test --no-build --verbosity normal
|
|
@ -5,17 +5,13 @@ 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? _outputOption;
|
|
||||||
private string? _branchOption;
|
|
||||||
private string? _tagOption;
|
|
||||||
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; }
|
||||||
@ -28,28 +24,16 @@ public class CommitDetail
|
|||||||
set { _currentBranch = value; }
|
set { _currentBranch = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public string? SelectedDir
|
public CommitDetail()
|
||||||
{
|
{
|
||||||
get { return _selectedDir; }
|
|
||||||
set { _selectedDir = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public CommitDetail(string? dir)
|
|
||||||
{
|
|
||||||
_selectedDir = !String.IsNullOrEmpty(dir) ? dir : Directory.GetCurrentDirectory();
|
|
||||||
_authors = new List<string>();
|
_authors = new List<string>();
|
||||||
_commitDetails = new SortedList<string, int>();
|
_commitDetails = new SortedList<string, int>();
|
||||||
_currentBranch = GetCurrentBranch();
|
_currentBranch = GetCurrentBranch();
|
||||||
|
|
||||||
// unused, might be used later for a refactor
|
|
||||||
_outputOption = null;
|
|
||||||
_branchOption = null;
|
|
||||||
_tagOption = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetCurrentCommitsByName()
|
public void GetCurrentCommitsByName()
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(_selectedDir))
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
||||||
{
|
{
|
||||||
foreach (var c in repo.Commits)
|
foreach (var c in repo.Commits)
|
||||||
{
|
{
|
||||||
@ -58,7 +42,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();
|
||||||
@ -69,7 +53,7 @@ public class CommitDetail
|
|||||||
|
|
||||||
public void GetCurrentCommitsByEmail()
|
public void GetCurrentCommitsByEmail()
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(_selectedDir))
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
||||||
{
|
{
|
||||||
foreach (var c in repo.Commits)
|
foreach (var c in repo.Commits)
|
||||||
{
|
{
|
||||||
@ -78,7 +62,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();
|
||||||
@ -89,7 +73,7 @@ public class CommitDetail
|
|||||||
|
|
||||||
public int GetCommitTotal()
|
public int GetCommitTotal()
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(_selectedDir))
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
||||||
{
|
{
|
||||||
return repo.Commits.Count();
|
return repo.Commits.Count();
|
||||||
}
|
}
|
||||||
@ -97,7 +81,7 @@ public class CommitDetail
|
|||||||
|
|
||||||
public string GetCurrentBranch()
|
public string GetCurrentBranch()
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(_selectedDir))
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
||||||
{
|
{
|
||||||
return repo.Head.Reference.TargetIdentifier;
|
return repo.Head.Reference.TargetIdentifier;
|
||||||
}
|
}
|
||||||
@ -105,23 +89,15 @@ public class CommitDetail
|
|||||||
|
|
||||||
public void GetCommitsByBranch(string branchName)
|
public void GetCommitsByBranch(string branchName)
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(_selectedDir))
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
||||||
{
|
{
|
||||||
var branchResult = repo.Branches[branchName];
|
var branchResult = repo.Branches[branchName];
|
||||||
|
|
||||||
try
|
if (branchResult == null)
|
||||||
{
|
{
|
||||||
if (branchResult == null)
|
branchResult = repo.Branches[$"origin/{branchName}"];
|
||||||
{
|
var remoteBranch = repo.CreateBranch(branchName, branchResult.Tip);
|
||||||
branchResult = repo.Branches[$"origin/{branchName}"];
|
repo.Branches.Update(remoteBranch, b => b.UpstreamBranch = $"refs/heads/{branchName}");
|
||||||
var remoteBranch = repo.CreateBranch(branchName, branchResult.Tip);
|
|
||||||
repo.Branches.Update(remoteBranch, b => b.UpstreamBranch = $"refs/heads/{branchName}");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (System.Exception)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Cannot fetch {branchName} branch.");
|
|
||||||
Environment.Exit(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var c in branchResult.Commits)
|
foreach (var c in branchResult.Commits)
|
||||||
@ -131,7 +107,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();
|
||||||
@ -139,41 +115,13 @@ public class CommitDetail
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void GetCommitsByTag(string tagName)
|
public void GetCommitsByTag(string tagName)
|
||||||
{
|
{
|
||||||
using (var repo = new Repository(_selectedDir))
|
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
||||||
{
|
{
|
||||||
try
|
var tagResult = repo.Tags[tagName];
|
||||||
{
|
System.Console.WriteLine(tagResult);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (System.Exception)
|
|
||||||
{
|
|
||||||
Console.WriteLine($"Cannot find the tag {tagName}");
|
|
||||||
Environment.Exit(3);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,6 @@
|
|||||||
<ImplicitUsings>enable</ImplicitUsings>
|
<ImplicitUsings>enable</ImplicitUsings>
|
||||||
<Nullable>enable</Nullable>
|
<Nullable>enable</Nullable>
|
||||||
<AssemblyName>drillsergeant</AssemblyName>
|
<AssemblyName>drillsergeant</AssemblyName>
|
||||||
<Version>1.2.0</Version>
|
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
195
Program.cs
195
Program.cs
@ -16,147 +16,88 @@ static class Program
|
|||||||
);
|
);
|
||||||
branchOption.AddAlias("-b");
|
branchOption.AddAlias("-b");
|
||||||
|
|
||||||
var tagOption = new Option<string>(
|
|
||||||
"--tag",
|
|
||||||
"Specify the tag to filter by"
|
|
||||||
);
|
|
||||||
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,
|
|
||||||
dirOption,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
rootCommand.SetHandler((outputOptionValue, branchOptionValue, tagOptionValue, dirOptionValue) =>
|
rootCommand.SetHandler((outputOptionValue, branchOptionValue) => {
|
||||||
{
|
CommitDetail commits = new CommitDetail();
|
||||||
CommitDetail commits = new CommitDetail(dirOptionValue);
|
|
||||||
|
switch (outputOptionValue)
|
||||||
|
{
|
||||||
|
case "stdout":
|
||||||
|
StdOutDataService outDataService = new StdOutDataService();
|
||||||
|
DataAccess dataAccess = new DataAccess(outDataService);
|
||||||
|
|
||||||
switch (outputOptionValue)
|
switch (branchOptionValue)
|
||||||
{
|
{
|
||||||
case "stdout":
|
case null:
|
||||||
StdOutDataService outDataService = new StdOutDataService();
|
commits.GetCurrentCommitsByName();
|
||||||
DataAccess dataAccess = new DataAccess(outDataService);
|
dataAccess.WriteData(commits.CommitDetails);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
commits.GetCommitsByBranch(branchOptionValue);
|
||||||
|
dataAccess.WriteData(commits.CommitDetails);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "xlsx":
|
||||||
|
ExcelDataService excelDataService = new ExcelDataService();
|
||||||
|
DataAccess dataAccessExcelCase = new DataAccess(excelDataService);
|
||||||
|
|
||||||
if (branchOptionValue != null && tagOptionValue != null)
|
switch (branchOptionValue)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Please specify either a branch or a tag");
|
case null:
|
||||||
Environment.Exit(2);
|
commits.GetCurrentCommitsByName();
|
||||||
}
|
dataAccessExcelCase.WriteData(commits.CommitDetails);
|
||||||
else if (branchOptionValue != null && tagOptionValue == null)
|
break;
|
||||||
{
|
default:
|
||||||
switch (branchOptionValue)
|
commits.GetCommitsByBranch(branchOptionValue);
|
||||||
{
|
dataAccessExcelCase.WriteData(commits.CommitDetails);
|
||||||
case null:
|
break;
|
||||||
commits.GetCurrentCommitsByName();
|
}
|
||||||
dataAccess.WriteData(commits.CommitDetails);
|
break;
|
||||||
break;
|
case "pdf":
|
||||||
default:
|
PdfDataService pdfDataService = new PdfDataService();
|
||||||
commits.GetCommitsByBranch(branchOptionValue);
|
DataAccess dataAccessPdfCase = new DataAccess(pdfDataService);
|
||||||
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)
|
switch (branchOptionValue)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Please specify either a branch or a tag.");
|
case null:
|
||||||
Environment.Exit(2);
|
commits.GetCurrentCommitsByName();
|
||||||
}
|
dataAccessPdfCase.WriteData(commits.CommitDetails);
|
||||||
else if (branchOptionValue != null && tagOptionValue == null)
|
break;
|
||||||
{
|
default:
|
||||||
switch (branchOptionValue)
|
commits.GetCommitsByBranch(branchOptionValue);
|
||||||
{
|
dataAccessPdfCase.WriteData(commits.CommitDetails);
|
||||||
case null:
|
break;
|
||||||
commits.GetCurrentCommitsByName();
|
}
|
||||||
dataAccessExcelCase.WriteData(commits.CommitDetails);
|
break;
|
||||||
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:
|
case null:
|
||||||
commits.GetCurrentCommitsByName();
|
StdOutDataService stdOutDataService = new StdOutDataService();
|
||||||
dataAccessPdfCase.WriteData(commits.CommitDetails);
|
DataAccess dataAccessNullCase = new DataAccess(stdOutDataService);
|
||||||
|
|
||||||
|
switch (branchOptionValue)
|
||||||
|
{
|
||||||
|
case null:
|
||||||
|
commits.GetCurrentCommitsByName();
|
||||||
|
dataAccessNullCase.WriteData(commits.CommitDetails);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
commits.GetCommitsByBranch(branchOptionValue);
|
||||||
|
dataAccessNullCase.WriteData(commits.CommitDetails);
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
commits.GetCommitsByBranch(branchOptionValue);
|
System.Console.WriteLine("This should not happen...");
|
||||||
dataAccessPdfCase.WriteData(commits.CommitDetails);
|
Environment.Exit(90);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
},
|
||||||
case null:
|
outputOption, branchOption);
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
11
README.md
11
README.md
@ -37,7 +37,6 @@ To use this command-line application, you must be in a git project. Otherwise, a
|
|||||||
-o, --output <pdf|stdout|xlsx> Specify the output given to the user
|
-o, --output <pdf|stdout|xlsx> Specify the output given to the user
|
||||||
-b, --branch <branch> Specify the branch to filter by
|
-b, --branch <branch> Specify the branch to filter by
|
||||||
-t, --tag <tag> Specify the tag to filter by
|
-t, --tag <tag> Specify the tag to filter by
|
||||||
-f, --file <file> Specify a git directory
|
|
||||||
```
|
```
|
||||||
|
|
||||||
Throw the `-h` flag for quick assistance. Throw the `--version` flag for version information.
|
Throw the `-h` flag for quick assistance. Throw the `--version` flag for version information.
|
||||||
@ -74,14 +73,6 @@ To get a commit report to a PDF file filtered by the `devel` branch:
|
|||||||
drillsergeant -o pdf -b devel
|
drillsergeant -o pdf -b devel
|
||||||
```
|
```
|
||||||
|
|
||||||
To get a tally based on a directory:
|
|
||||||
|
|
||||||
```bash
|
|
||||||
drillsergeant -f /home/user/drillsergeant
|
|
||||||
```
|
|
||||||
|
|
||||||
This also works on enviroment variables too!
|
|
||||||
|
|
||||||
Got too many contributors to fit onto your terminal? Run this by installing [bat](https://github.com/sharkdp/bat):
|
Got too many contributors to fit onto your terminal? Run this by installing [bat](https://github.com/sharkdp/bat):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
@ -151,7 +142,7 @@ Then, you can find the binary in the `publish/` directory. You can move this exe
|
|||||||
|
|
||||||
## Known Issues
|
## Known Issues
|
||||||
|
|
||||||
- A user must be in the root of a git project in order for this program to run (unless the user runs the `-f` flag when invoking `drillsergeant`).
|
- A user must be in the root of a git project in order for this program to run.
|
||||||
|
|
||||||
## Next Steps/Contributing
|
## Next Steps/Contributing
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user