-
Notifications
You must be signed in to change notification settings - Fork 121
Expand file tree
/
Copy pathproject-options.ts
More file actions
124 lines (113 loc) · 4.46 KB
/
project-options.ts
File metadata and controls
124 lines (113 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import { commitExists, git, revParse } from "./git.js";
import { IConfig, projectInfo } from "./project-config.js";
// For now, only the Git, Cygwin and BusyBox projects are supported
export class ProjectOptions {
public static async get(
config: IConfig,
workDir: string,
branchName: string,
cc: string[],
basedOn?: string,
publishToRemote?: string,
baseCommit?: string,
): Promise<ProjectOptions> {
let upstreamBranch: string;
let to: string;
let midUrlPrefix = " Message-ID: ";
if (Object.prototype.hasOwnProperty.call(config, "project")) {
const project = config.project as projectInfo;
to = `--to=${project.to}`;
upstreamBranch = project.branch;
midUrlPrefix = project.urlPrefix;
for (const user of project.cc) {
cc.push(user);
}
} else if ((await revParse(`${baseCommit}:git-gui.sh`, workDir)) !== undefined) {
// Git GUI
to = "--to=git@vger.kernel.org";
cc.push("Johannes Sixt <j6t@kdbg.org>");
upstreamBranch = "git-gui/master";
} else if (
(await revParse(`${baseCommit}:git.c`, workDir)) !== undefined ||
// gitster/git's `todo` branch, see https://github.com/git/git/pull/2209
((await revParse(`${baseCommit}:README.cooking`, workDir)) !== undefined &&
(await revParse(`${baseCommit}:jc.png`, workDir)) !== undefined)
) {
// Git
to = "--to=git@vger.kernel.org";
// Do *not* Cc: Junio Hamano by default
upstreamBranch = "upstream/seen";
if (await git(["rev-list", branchName + ".." + upstreamBranch], { workDir })) {
upstreamBranch = "upstream/next";
}
if (await git(["rev-list", branchName + ".." + upstreamBranch], { workDir })) {
upstreamBranch = "upstream/master";
}
midUrlPrefix = "https://lore.kernel.org/git/";
} else if ((await revParse(`${baseCommit}:winsup`, workDir)) !== undefined) {
// Cygwin
to = "--to=cygwin-patches@cygwin.com";
upstreamBranch = "cygwin/master";
midUrlPrefix = "https://www.mail-archive.com/search?l=cygwin-patches@cygwin.com&q=";
} else if ((await revParse(`${baseCommit}:include/busybox.h`, workDir)) !== undefined) {
// BusyBox
to = "--to=busybox@busybox.net";
upstreamBranch = "busybox/master";
midUrlPrefix = "https://www.mail-archive.com/search?l=busybox@busybox.net&q=";
} else if (await commitExists("7ccd18012de2e6c47e5", workDir)) {
// We're running in the test suite!
to = "--to=reviewer@example.com";
upstreamBranch = "master";
midUrlPrefix = "https://dummy.com/?mid=";
} else {
throw new Error("Unrecognized project");
}
if (basedOn) {
upstreamBranch = basedOn;
}
if (!baseCommit && (await git(["rev-list", branchName + ".." + upstreamBranch], { workDir }))) {
throw new Error(`Branch ${branchName} is not rebased to ${upstreamBranch}`);
}
return new ProjectOptions(
branchName,
upstreamBranch,
basedOn,
publishToRemote,
to,
cc,
midUrlPrefix,
workDir,
baseCommit,
);
}
public readonly branchName: string;
public readonly upstreamBranch: string;
public readonly baseCommit: string;
public readonly basedOn?: string;
public readonly publishToRemote?: string;
public readonly workDir: string;
public readonly to: string;
public readonly cc: string[];
public readonly midUrlPrefix: string;
protected constructor(
branchName: string,
upstreamBranch: string,
basedOn: string | undefined,
publishToRemote: string | undefined,
to: string,
cc: string[],
midUrlPrefix: string,
workDir: string,
baseCommit?: string,
) {
this.branchName = branchName;
this.upstreamBranch = upstreamBranch;
this.baseCommit = baseCommit || upstreamBranch;
this.basedOn = basedOn;
this.publishToRemote = publishToRemote;
this.workDir = workDir;
this.to = to;
this.cc = cc;
this.midUrlPrefix = midUrlPrefix;
}
}