-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
/
Copy pathgit-cliff.ts
194 lines (185 loc) · 4.53 KB
/
git-cliff.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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
const flags: Fig.Option[] = [
{
name: ["--verbose", "-v"],
description: "Increases the logging verbosity",
priority: 1,
},
{
name: ["--init", "-i"],
description: "Writes the default configuration file to cliff.toml",
},
{
name: ["--latest", "-l"],
description: "Processes the commits starting from the latest tag",
exclusiveOn: ["--current", "-u"],
},
{
name: "--current",
description: "Processes the commits that belong to the current tag",
exclusiveOn: ["-l", "-u"],
},
{
name: ["--unreleased", "-u"],
description: "Processes the commits that do not belong to a tag",
exclusiveOn: ["-l", "--current"],
},
{
name: "--date-order",
description: "Sorts the tags chronologically",
},
{
name: "--context",
description: "Prints changelog context as JSON",
},
{
name: ["--help", "-h"],
description: "Prints help information",
priority: 1,
},
{
name: ["--version", "-V"],
description: "Prints version information",
priority: 1,
},
];
const folderPathArg = {
name: "path",
template: "folders",
suggestCurrentToken: true,
} as const;
const patternArg = {
name: "pattern",
isVariadic: true,
optionsCanBreakVariadicArg: true,
} as const;
const filePathArg = {
name: "path",
template: "filepaths",
suggestCurrentToken: true,
} as const;
const options: Fig.Option[] = [
{
name: ["--config", "-c"],
description: "Sets the configuration file",
args: {
name: "path",
template: "filepaths",
suggestCurrentToken: true,
default: "cliff.toml",
},
},
{
name: ["--workdir", "-w"],
description: "Sets the working directory",
args: folderPathArg,
},
{
name: ["--repository", "-r"],
description: "Sets the git repository",
args: folderPathArg,
},
{
name: "--include-path",
description: "Sets the path to include related commits",
args: patternArg,
},
{
name: "--exclude-path",
description: "Sets the path to exclude related commits",
args: patternArg,
},
{
name: "--with-commit",
description: "Sets custom commit messages to include in the changelog",
args: {
name: "msg",
isVariadic: true,
optionsCanBreakVariadicArg: true,
},
},
{
name: ["--prepend", "-p"],
description: "Prepends entries to the given changelog file",
args: filePathArg,
},
{
name: ["--output", "-o"],
description: "Writes output to the given file",
args: filePathArg,
},
{
name: ["--tag", "-t"],
description: "Sets the tag for the latest version",
args: {
name: "tag",
},
},
{
name: ["--body", "-b"],
description: "Sets the template for the changelog body",
args: {
name: "template",
},
},
{
name: ["--strip", "-s"],
description: "Strips the given parts from the changelog",
args: {
name: "part",
suggestions: [{ name: "header" }, { name: "footer" }, { name: "all" }],
},
},
{
name: "--sort",
description: "Sets sorting of the commits inside sections",
args: {
name: "sort",
default: "oldest",
suggestions: [{ name: "oldest" }, { name: "newest" }],
},
},
];
const completionSpec: Fig.Spec = {
name: "git-cliff",
description: "A highly customizable changelog generator ⛰️",
options: [...flags, ...options],
args: {
name: "range",
description: "Sets the commit range to process",
generators: {
trigger: "..",
getQueryTerm: ".",
script: ["git", "rev-list", "--all", "--oneline", "--abbrev-commit"],
postProcess: (out, tokens) => {
if (out.startsWith("fatal:")) {
return [];
}
if (out.startsWith("warning:") || out.startsWith("error:")) {
out = out.slice(out.indexOf("\n") + 1);
}
const token = tokens.pop();
return [
...out.split("\n").map((line) => {
const space = line.indexOf(" ");
const hash = line.slice(0, space);
return {
name: hash,
insertValue: hash + (token?.includes("..") ? "" : ".."),
icon: "fig://icon?type=node",
description: line.slice(space + 1),
priority: 1,
};
}),
{
name: "HEAD",
insertValue: "HEAD" + (token?.includes("..") ? "" : ".."),
icon: "fig://icon?type=node",
description: "The current commit",
priority: 5,
},
];
},
},
},
};
export default completionSpec;