Skip to content

Commit eaac2ce

Browse files
authored
Merge pull request #49 from twpol/feature/fix-merge-bot-user
fix: Ensure all `git` commands have author information
2 parents ca74d03 + 6479cd1 commit eaac2ce

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

Git/Project.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@ public Project(string gitPath)
1616
GitPath = gitPath;
1717
}
1818

19-
public void Init(string repository)
19+
public void Init(string repository, string authorName, string authorEmail)
2020
{
2121
if (!Directory.Exists(GitPath)) Directory.CreateDirectory(GitPath);
2222
if (!File.Exists(Path.Join(GitPath, ".git", "config"))) RunCommand($"init");
2323

24+
Environment.SetEnvironmentVariable("GIT_AUTHOR_NAME", authorName);
25+
Environment.SetEnvironmentVariable("GIT_AUTHOR_EMAIL", authorEmail);
26+
Environment.SetEnvironmentVariable("GIT_COMMITTER_NAME", authorName);
27+
Environment.SetEnvironmentVariable("GIT_COMMITTER_EMAIL", authorEmail);
28+
2429
RunCommandIgnoreErrors($"config remove-section remote.origin");
2530
RunCommand($"remote add origin --mirror=fetch {repository}");
2631
}
@@ -97,16 +102,12 @@ public string Describe(string options)
97102
throw new ApplicationException("Unable to describe commit");
98103
}
99104

100-
public string CommitTree(string authorName, string authorEmail, string treeRef, IEnumerable<string> parentRefs, string message)
105+
public string CommitTree(string treeRef, IEnumerable<string> parentRefs, string message)
101106
{
102107
var tempFile = Path.GetTempFileName();
103108
File.WriteAllText(tempFile, message);
104109
try
105110
{
106-
Environment.SetEnvironmentVariable("GIT_AUTHOR_NAME", authorName);
107-
Environment.SetEnvironmentVariable("GIT_AUTHOR_EMAIL", authorEmail);
108-
Environment.SetEnvironmentVariable("GIT_COMMITTER_NAME", authorName);
109-
Environment.SetEnvironmentVariable("GIT_COMMITTER_EMAIL", authorEmail);
110111
var parents = String.Join(" ", parentRefs.Select(parentRef => $"-p {parentRef}"));
111112
foreach (var line in GetCommandOutput($"commit-tree {treeRef} {parents} -F {tempFile}"))
112113
{

Program.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ static async Task AsyncMain(IConfigurationRoot config)
9494

9595
Console.WriteLine("Preparing repository...");
9696
var git = new Git.Project(GetGitPath());
97-
git.Init($"[email protected]:{gitHubConfig["organization"]}/{gitHubConfig["repository"]}.git");
97+
git.Init($"[email protected]:{gitHubConfig["organization"]}/{gitHubConfig["repository"]}.git", gitHubConfig["mergeAuthorName"], gitHubConfig["mergeAuthorEmail"]);
9898
git.Fetch();
9999
git.ResetHard();
100100
git.Clean();
@@ -162,7 +162,7 @@ static async Task AsyncMain(IConfigurationRoot config)
162162
git.GetAbbreviatedCommit($"pull/{pr.Number}/head")
163163
)))
164164
);
165-
var newMergeBranchCommit = git.CommitTree(gitHubConfig["mergeAuthorName"], gitHubConfig["mergeAuthorEmail"], $"{autoMergeCommit}^{{tree}}", mergeBranchParents, newMergeBranchMessage);
165+
var newMergeBranchCommit = git.CommitTree($"{autoMergeCommit}^{{tree}}", mergeBranchParents, newMergeBranchMessage);
166166
git.SetBranchRef(gitHubConfig["mergeBranch"], newMergeBranchCommit);
167167
git.Checkout(gitHubConfig["mergeBranch"]);
168168
var newMergeBranchVersion = String.Format(

0 commit comments

Comments
 (0)