|
| 1 | +module dlangbot.git; |
| 2 | + |
| 3 | +import std.conv, std.file, std.path, std.string, std.uuid; |
| 4 | +import std.format, std.stdio; |
| 5 | + |
| 6 | +import dlangbot.github; |
| 7 | +import vibe.core.log; |
| 8 | + |
| 9 | +string gitURL = "http://0.0.0.0:9006"; |
| 10 | + |
| 11 | +void rebase(PullRequest* pr) |
| 12 | +{ |
| 13 | + import std.process; |
| 14 | + auto uniqDir = tempDir.buildPath("dlang-bot-git", randomUUID.to!string.replace("-", "")); |
| 15 | + uniqDir.mkdirRecurse; |
| 16 | + scope(exit) uniqDir.rmdirRecurse; |
| 17 | + |
| 18 | + auto targetBranch = pr.base.ref_; |
| 19 | + auto remoteDir = pr.repoURL; |
| 20 | + |
| 21 | + logInfo("[git/%s]: cloning branch %s...", pr.repoSlug, targetBranch); |
| 22 | + auto pid = spawnShell("git clone -b %s %s %s".format(targetBranch, remoteDir, uniqDir)); |
| 23 | + pid.wait; |
| 24 | + |
| 25 | + //auto git = "git -C %s ".format(uniqDir); |
| 26 | + //logInfo("[git/%s]: fetching repo...", pr.repoSlug); |
| 27 | + //pid = spawnShell(git ~ "fetch origin pull/%s/head:pr-%1$s".format(pr.number)); |
| 28 | + //pid.wait; |
| 29 | + //logInfo("[git/%s]: switching to PR branch...", pr.repoSlug); |
| 30 | + //pid = spawnShell(git ~ "checkout pr-%s".format(pr.number)); |
| 31 | + //pid.wait; |
| 32 | + //logInfo("[git/%s]: rebasing...", pr.repoSlug); |
| 33 | + //pid = spawnShell(git ~ "rebase " ~ targetBranch); |
| 34 | + //pid.wait; |
| 35 | + |
| 36 | + import std.net.curl, std.json; |
| 37 | + auto headSlug = pr.head.repo.fullName; |
| 38 | + auto headRef = pr.head.ref_; |
| 39 | + auto sep = gitURL.startsWith("http") ? "/" : ":"; |
| 40 | + logInfo("[git/%s]: pushing... to %s", pr.repoSlug, gitURL); |
| 41 | + |
| 42 | + // TODO: use --force here |
| 43 | + auto cmd = "git push -vv %s%s%s HEAD:%s".format(gitURL, sep, headSlug, headRef); |
| 44 | + writeln("CMD"); |
| 45 | + uniqDir.writeln; |
| 46 | + cmd.writeln; |
| 47 | + writeln("CMD"); |
| 48 | + |
| 49 | + pid = spawnShell(cmd); |
| 50 | + //pid.wait; |
| 51 | + import vibe.core.core; |
| 52 | + import core.time; |
| 53 | + sleep(60.seconds); |
| 54 | + pid.wait; |
| 55 | +} |
0 commit comments