-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit.ts
64 lines (53 loc) · 1.43 KB
/
git.ts
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
import { bash, parseRepo } from "./deps.ts";
export const ROOT = Symbol();
interface LogOptions {
grep: string;
since: string | typeof ROOT;
}
export default {
latestRemoteTag(): Promise<string> {
return bash(
"git ls-remote --tags --sort=-v:refname origin | head -n 1 | cut -d/ -f3",
);
},
log({ grep, since }: LogOptions): Promise<string[]> {
return bash(
`git log ${
since === ROOT ? "" : `${since}..HEAD`
} --pretty=format:'%s %h' --abbrev-commit --grep=${grep}`,
).then((commit) => {
if (!commit) {
return [];
}
const commits = commit.split("\n").map((commit) => {
const trimmed = commit.replace(grep, "");
if (trimmed.startsWith(" ")) {
return trimmed.slice(1);
}
return trimmed;
});
return commits;
});
},
tag(tag: string): Promise<string> {
return bash(`git tag ${tag}`);
},
pushTag(tag: string): Promise<string> {
return bash(`git push origin ${tag}`);
},
deleteLocalTag(tag: string): Promise<string> {
return bash(`git tag -d ${tag}`);
},
deleteRemoteTag(tag: string): Promise<string> {
return bash(`git push --delete origin ${tag}`);
},
async repoInfo(): Promise<{ repo: string; owner: string }> {
const { project: repo, owner } = parseRepo(
await bash("git remote get-url origin"),
);
return {
repo,
owner: owner ?? "",
};
},
};