Compare commits
5 Commits
pdfDataSer
...
exceptionH
Author | SHA1 | Date | |
---|---|---|---|
5873bdb2a6 | |||
895f322bd6 | |||
7721031d62 | |||
e4d8e3f66e | |||
82b8cd5c04 |
@ -93,11 +93,19 @@ public class CommitDetail
|
||||
{
|
||||
var branchResult = repo.Branches[branchName];
|
||||
|
||||
if (branchResult == null)
|
||||
try
|
||||
{
|
||||
branchResult = repo.Branches[$"origin/{branchName}"];
|
||||
var remoteBranch = repo.CreateBranch(branchName, branchResult.Tip);
|
||||
repo.Branches.Update(remoteBranch, b => b.UpstreamBranch = $"refs/heads/{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}");
|
||||
}
|
||||
}
|
||||
catch (System.Exception)
|
||||
{
|
||||
Console.WriteLine($"Cannot fetch {branchName} branch.");
|
||||
Environment.Exit(1);
|
||||
}
|
||||
|
||||
foreach (var c in branchResult.Commits)
|
||||
@ -120,8 +128,36 @@ public class CommitDetail
|
||||
{
|
||||
using (var repo = new Repository(Directory.GetCurrentDirectory()))
|
||||
{
|
||||
var tagResult = repo.Tags[tagName];
|
||||
System.Console.WriteLine(tagResult);
|
||||
try
|
||||
{
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
103
Program.cs
103
Program.cs
@ -16,13 +16,20 @@ static class Program
|
||||
);
|
||||
branchOption.AddAlias("-b");
|
||||
|
||||
var tagOption = new Option<string>(
|
||||
"--tag",
|
||||
"Specify the tag to filter by"
|
||||
);
|
||||
tagOption.AddAlias("-t");
|
||||
|
||||
var rootCommand = new RootCommand("Get a tally of contributors' commits")
|
||||
{
|
||||
outputOption,
|
||||
branchOption,
|
||||
tagOption,
|
||||
};
|
||||
|
||||
rootCommand.SetHandler((outputOptionValue, branchOptionValue) => {
|
||||
rootCommand.SetHandler((outputOptionValue, branchOptionValue, tagOptionValue) => {
|
||||
CommitDetail commits = new CommitDetail();
|
||||
|
||||
switch (outputOptionValue)
|
||||
@ -31,32 +38,50 @@ static class Program
|
||||
StdOutDataService outDataService = new StdOutDataService();
|
||||
DataAccess dataAccess = new DataAccess(outDataService);
|
||||
|
||||
switch (branchOptionValue)
|
||||
{
|
||||
case null:
|
||||
commits.GetCurrentCommitsByName();
|
||||
dataAccess.WriteData(commits.CommitDetails);
|
||||
break;
|
||||
default:
|
||||
commits.GetCommitsByBranch(branchOptionValue);
|
||||
dataAccess.WriteData(commits.CommitDetails);
|
||||
break;
|
||||
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();
|
||||
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);
|
||||
|
||||
switch (branchOptionValue)
|
||||
{
|
||||
case null:
|
||||
commits.GetCurrentCommitsByName();
|
||||
dataAccessExcelCase.WriteData(commits.CommitDetails);
|
||||
break;
|
||||
default:
|
||||
commits.GetCommitsByBranch(branchOptionValue);
|
||||
dataAccessExcelCase.WriteData(commits.CommitDetails);
|
||||
break;
|
||||
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":
|
||||
@ -79,25 +104,37 @@ static class Program
|
||||
StdOutDataService stdOutDataService = new StdOutDataService();
|
||||
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;
|
||||
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();
|
||||
dataAccessNullCase.WriteData(commits.CommitDetails);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
System.Console.WriteLine("This should not happen...");
|
||||
Environment.Exit(90);
|
||||
Environment.Exit(4);
|
||||
break;
|
||||
}
|
||||
},
|
||||
outputOption, branchOption);
|
||||
outputOption, branchOption, tagOption);
|
||||
|
||||
rootCommand.Invoke(args);
|
||||
}
|
||||
|
Reference in New Issue
Block a user