-
Notifications
You must be signed in to change notification settings - Fork 116
Expand file tree
/
Copy pathmail-commit-mapping.ts
More file actions
60 lines (54 loc) · 2.01 KB
/
mail-commit-mapping.ts
File metadata and controls
60 lines (54 loc) · 2.01 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
import { git } from "./git.js";
import { GitNotes } from "./git-notes.js";
import { IConfig } from "./project-config.js";
export class MailCommitMapping {
public readonly config: IConfig;
public readonly workDir?: string;
public readonly mail2CommitNotes: GitNotes;
public constructor(config: IConfig, workDir?: string) {
this.config = config;
this.workDir = workDir;
this.mail2CommitNotes = new GitNotes(workDir, "refs/notes/mail-to-commit");
}
public async getGitGitCommitForMessageId(messageID: string): Promise<string | undefined> {
return await this.mail2CommitNotes.getString(messageID);
}
public async updateMail2CommitAndBranches(): Promise<void> {
return await this.update(true, true, true);
}
public async updateMail2CommitRef(): Promise<void> {
return await this.update(true);
}
private async update(
includeNotesRef?: boolean,
includeUpstreamBranches?: boolean,
includeGitsterBranches?: boolean,
): Promise<void> {
const refs: string[] = [];
if (includeNotesRef) {
refs.push("refs/notes/mail-to-commit:refs/notes/mail-to-commit");
}
if (includeUpstreamBranches) {
for (const ref of this.config.repo.trackingBranches) {
refs.push(`+refs/heads/${ref}:refs/remotes/upstream/${ref}`);
}
}
if (includeGitsterBranches && this.config.repo.maintainerBranch) {
refs.push(`+refs/heads/*:refs/remotes/${this.config.repo.maintainerBranch}/*`);
}
if (refs.length) {
console.log(`Updating mail-to-commit/refs: ${refs.join(", ")}`);
await git(
[
"fetch",
"--no-tags",
`https://github.com/${this.config.repo.owner}/${this.config.repo.name}`,
...refs,
],
{
workDir: this.workDir,
},
);
}
}
}