From f77bfa82dc5af1e186c75a928ed5ad6d994ad7bc Mon Sep 17 00:00:00 2001 From: Miha Zupan Date: Sat, 15 Jun 2024 18:46:06 +0200 Subject: [PATCH] Support merge as well --- Runner/RebaseJob.cs | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/Runner/RebaseJob.cs b/Runner/RebaseJob.cs index ab42c6e..516d691 100644 --- a/Runner/RebaseJob.cs +++ b/Runner/RebaseJob.cs @@ -9,11 +9,11 @@ public RebaseJob(HttpClient client, Dictionary 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 @@ -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, "", StringComparison.OrdinalIgnoreCase)); - await RunProcessAsync(ScriptName, string.Empty, - processLogs: line => line.Replace(pushToken, "", StringComparison.OrdinalIgnoreCase)); + await RunBatchScriptAsync("push.bat", $"git push pr {(isRebase ? "-f" : "")}"); + } + + private async Task RunBatchScriptAsync(string name, string script, Func? processLogs = null) + { + File.WriteAllText(name, script); + await RunProcessAsync(name, string.Empty, processLogs: processLogs); } }