Skip to content

Commit

Permalink
Support merge as well
Browse files Browse the repository at this point in the history
  • Loading branch information
MihaZupan committed Jun 15, 2024
1 parent 75507ee commit f77bfa8
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions Runner/RebaseJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ public RebaseJob(HttpClient client, Dictionary<string, string> metadata) : base(

protected override async Task RunJobCoreAsync()
{
const string ScriptName = "clone-rebase.bat";

string pushToken = Metadata["MihuBotPushToken"];

File.WriteAllText(ScriptName,
bool isRebase = CustomArguments.StartsWith("rebase", StringComparison.OrdinalIgnoreCase);

await RunBatchScriptAsync("clone-rebase.bat",
$$"""
git config --system core.longpaths true
git clone --progress https://github.com/dotnet/runtime runtime
Expand All @@ -25,11 +25,16 @@ git config --global user.name MihuBot
git fetch pr {{SourceBranch}}
git checkout {{SourceBranch}}
git log -1
git rebase main
git push pr -f
""");
git {{(isRebase ? "rebase" : "merge")}} main
""",
line => line.Replace(pushToken, "<REDACTED>", StringComparison.OrdinalIgnoreCase));

await RunProcessAsync(ScriptName, string.Empty,
processLogs: line => line.Replace(pushToken, "<REDACTED>", StringComparison.OrdinalIgnoreCase));
await RunBatchScriptAsync("push.bat", $"git push pr {(isRebase ? "-f" : "")}");
}

private async Task RunBatchScriptAsync(string name, string script, Func<string, string>? processLogs = null)
{
File.WriteAllText(name, script);
await RunProcessAsync(name, string.Empty, processLogs: processLogs);
}
}

0 comments on commit f77bfa8

Please sign in to comment.