Compare commits

..

16 Commits

Author SHA1 Message Date
a33f28225b runner fix 2023-09-02 22:04:07 -04:00
4aa4e11345 testing runners 2023-09-02 21:53:59 -04:00
922678b223 update readme 2022-12-27 21:50:12 -06:00
e156eef14c Update 'README.md' 2022-12-27 21:25:55 -06:00
d7db51824d Merge pull request 'Directory option' (#4) from dirOption into master
Reviewed-on: #4
2022-12-27 21:20:35 -06:00
434ba07d59 modifications to dirOption 2022-12-24 22:38:53 -05:00
384391add1 working file option 2022-12-24 22:11:12 -05:00
702188bc22 wip: starting work on dir option 2022-12-24 17:46:20 -05:00
73f8e80a23 update version 2022-08-24 19:11:51 -04:00
022f3a8937 Merge pull request 'added PDF output, tag filtering functionality' (#6) from staging into master
Reviewed-on: #6
2022-08-23 18:33:09 -05:00
3582eae47c Merge pull request 'Exception handling' (#7) from exceptionHandling into staging
Reviewed-on: #7
2022-08-23 18:29:05 -05:00
5873bdb2a6 try catch all the things 2022-08-23 19:31:39 -04:00
895f322bd6 Merge branch 'staging' of https://scm.wyattjmiller.com/wymiller/DrillSergeant into staging 2022-08-23 19:13:05 -04:00
7721031d62 added command line arg for tag filtering, added arg logic for tag filtering 2022-08-23 18:57:18 -04:00
e4d8e3f66e added commit filtering by tag 2022-08-23 18:56:56 -04:00
82b8cd5c04 Merge pull request 'Added PDF export functionality' (#4) from pdfDataService into staging
Reviewed-on: #4
2022-08-23 17:55:17 -05:00
5 changed files with 235 additions and 90 deletions

24
.github/workflows/dotnet.yml vendored Normal file
View File

@ -0,0 +1,24 @@
# 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

View File

@ -5,6 +5,10 @@ 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
{ {
@ -24,16 +28,28 @@ public class CommitDetail
set { _currentBranch = value; } set { _currentBranch = value; }
} }
public CommitDetail() public string? SelectedDir
{ {
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(Directory.GetCurrentDirectory())) using (var repo = new Repository(_selectedDir))
{ {
foreach (var c in repo.Commits) foreach (var c in repo.Commits)
{ {
@ -53,7 +69,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)
{ {
@ -73,7 +89,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 +97,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,16 +105,24 @@ 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];
try
{
if (branchResult == null) if (branchResult == null)
{ {
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)
{
Console.WriteLine($"Cannot fetch {branchName} branch.");
Environment.Exit(1);
}
foreach (var c in branchResult.Commits) foreach (var c in branchResult.Commits)
{ {
@ -118,10 +142,38 @@ 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))
{ {
var tagResult = repo.Tags[tagName]; try
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);
}
} }
} }
} }

View File

@ -7,6 +7,7 @@
<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>

View File

@ -16,14 +16,29 @@ 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) => { rootCommand.SetHandler((outputOptionValue, branchOptionValue, tagOptionValue, dirOptionValue) =>
CommitDetail commits = new CommitDetail(); {
CommitDetail commits = new CommitDetail(dirOptionValue);
switch (outputOptionValue) switch (outputOptionValue)
{ {
@ -31,6 +46,13 @@ static class Program
StdOutDataService outDataService = new StdOutDataService(); StdOutDataService outDataService = new StdOutDataService();
DataAccess dataAccess = new DataAccess(outDataService); DataAccess dataAccess = new DataAccess(outDataService);
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) switch (branchOptionValue)
{ {
case null: case null:
@ -42,11 +64,24 @@ static class Program
dataAccess.WriteData(commits.CommitDetails); dataAccess.WriteData(commits.CommitDetails);
break; break;
} }
}
else if (branchOptionValue == null && tagOptionValue != null)
{
commits.GetCommitsByTag(tagOptionValue);
dataAccess.WriteData(commits.CommitDetails);
}
break; break;
case "xlsx": case "xlsx":
ExcelDataService excelDataService = new ExcelDataService(); ExcelDataService excelDataService = new ExcelDataService();
DataAccess dataAccessExcelCase = new DataAccess(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) switch (branchOptionValue)
{ {
case null: case null:
@ -58,6 +93,12 @@ static class Program
dataAccessExcelCase.WriteData(commits.CommitDetails); dataAccessExcelCase.WriteData(commits.CommitDetails);
break; break;
} }
}
else if (branchOptionValue == null && tagOptionValue != null)
{
commits.GetCommitsByTag(tagOptionValue);
dataAccessExcelCase.WriteData(commits.CommitDetails);
}
break; break;
case "pdf": case "pdf":
PdfDataService pdfDataService = new PdfDataService(); PdfDataService pdfDataService = new PdfDataService();
@ -79,6 +120,13 @@ static class Program
StdOutDataService stdOutDataService = new StdOutDataService(); StdOutDataService stdOutDataService = new StdOutDataService();
DataAccess dataAccessNullCase = new DataAccess(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) switch (branchOptionValue)
{ {
case null: case null:
@ -90,14 +138,25 @@ static class Program
dataAccessNullCase.WriteData(commits.CommitDetails); dataAccessNullCase.WriteData(commits.CommitDetails);
break; break;
} }
}
else if (branchOptionValue == null && tagOptionValue != null)
{
commits.GetCommitsByTag(tagOptionValue);
dataAccessNullCase.WriteData(commits.CommitDetails);
}
else
{
commits.GetCurrentCommitsByName();
dataAccessNullCase.WriteData(commits.CommitDetails);
}
break; break;
default: default:
System.Console.WriteLine("This should not happen..."); System.Console.WriteLine("This should not happen...");
Environment.Exit(90); Environment.Exit(4);
break; break;
} }
}, },
outputOption, branchOption); outputOption, branchOption, tagOption, dirOption);
rootCommand.Invoke(args); rootCommand.Invoke(args);
} }

View File

@ -37,6 +37,7 @@ 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.
@ -73,6 +74,14 @@ 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
@ -142,7 +151,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. - 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`).
## Next Steps/Contributing ## Next Steps/Contributing