Skip to content

Commit 77d8d88

Browse files
authored
Merge pull request #7 from openrails/feature/set-commit-author
feat: Set commit author name and email
2 parents 673c46c + 9cef431 commit 77d8d88

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Git/Project.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,17 +86,21 @@ public string Describe(string options)
8686
throw new ApplicationException("Unable to describe commit");
8787
}
8888

89-
public string CommitTree(string treeRef, IEnumerable<string> parentRefs, string message)
89+
public string CommitTree(string authorName, string authorEmail, string treeRef, IEnumerable<string> parentRefs, string message)
9090
{
9191
var tempFile = Path.GetTempFileName();
9292
File.WriteAllText(tempFile, message);
9393
try {
94+
Environment.SetEnvironmentVariable("GIT_AUTHOR_NAME", authorName);
95+
Environment.SetEnvironmentVariable("GIT_AUTHOR_EMAIL", authorEmail);
96+
Environment.SetEnvironmentVariable("GIT_COMMITTER_NAME", authorName);
97+
Environment.SetEnvironmentVariable("GIT_COMMITTER_EMAIL", authorEmail);
9498
var parents = String.Join(" ", parentRefs.Select(parentRef => $"-p {parentRef}"));
9599
foreach (var line in GetCommandOutput($"commit-tree {treeRef} {parents} -F {tempFile}"))
96100
{
97101
return line;
98102
}
99-
throw new ApplicationException("Unable to describe commit");
103+
throw new ApplicationException("Unable to commit tree");
100104
}
101105
finally
102106
{
@@ -113,7 +117,7 @@ public DateTimeOffset GetCommitDate(string reference)
113117
return DateTimeOffset.FromUnixTimeSeconds(long.Parse(line.Split("> ")[1].Split(" ")[0]));
114118
}
115119
}
116-
throw new ApplicationException("Unable to describe commit");
120+
throw new ApplicationException("Unable to get commit date");
117121
}
118122

119123
public void SetBranchRef(string branch, string reference)

Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ static async Task AsyncMain(IConfigurationRoot config)
142142
git.GetAbbreviatedCommit($"pull/{pr.Number}/head")
143143
)))
144144
);
145-
var newMergeBranchCommit = git.CommitTree($"{autoMergeCommit}^{{tree}}", mergeBranchParents, newMergeBranchMessage);
145+
var newMergeBranchCommit = git.CommitTree(gitHubConfig["mergeAuthorName"], gitHubConfig["mergeAuthorEmail"], $"{autoMergeCommit}^{{tree}}", mergeBranchParents, newMergeBranchMessage);
146146
git.SetBranchRef(gitHubConfig["mergeBranch"], newMergeBranchCommit);
147147
git.Checkout(gitHubConfig["mergeBranch"]);
148148
var newMergeBranchVersion = String.Format(

0 commit comments

Comments
 (0)