githublogen 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.cjs +3 -3
- package/dist/cli.mjs +3 -3
- package/dist/index.cjs +33 -25
- package/dist/index.mjs +33 -25
- package/package.json +1 -1
package/dist/cli.cjs
CHANGED
|
@@ -13,13 +13,12 @@ function _interopDefaultCompat (e) { return e && typeof e === 'object' && 'defau
|
|
|
13
13
|
const fs__default = /*#__PURE__*/_interopDefaultCompat(fs);
|
|
14
14
|
const cac__default = /*#__PURE__*/_interopDefaultCompat(cac);
|
|
15
15
|
|
|
16
|
-
const version = "0.0.
|
|
16
|
+
const version = "0.0.4";
|
|
17
17
|
|
|
18
18
|
const cli = cac__default("githublogen");
|
|
19
19
|
cli.version(version).option("-t, --token <path>", "GitHub Token").option("--from <ref>", "From tag").option("--to <ref>", "To tag").option("--github <path>", "GitHub Repository, e.g. soybeanjs/githublogen").option("--name <name>", "Name of the release").option("--contributors", "Show contributors section").option("--prerelease", "Mark release as prerelease").option("-d, --draft", "Mark release as draft").option("--output <path>", "Output to file instead of sending to GitHub").option("--capitalize", "Should capitalize for each comment message").option("--emoji", "Use emojis in section titles", { default: true }).option("--group", "Nest commit messages under their scopes").option("--dry", "Dry run").help();
|
|
20
20
|
cli.command("").action(async (args) => {
|
|
21
21
|
args.token = args.token || process.env.GITHUB_TOKEN;
|
|
22
|
-
console.log("args.token: ", args.token);
|
|
23
22
|
try {
|
|
24
23
|
console.log();
|
|
25
24
|
console.log(kolorist.dim(`${kolorist.bold("github")}logen `) + kolorist.dim(`v${version}`));
|
|
@@ -61,8 +60,9 @@ cli.command("").action(async (args) => {
|
|
|
61
60
|
await index.sendRelease(config, md);
|
|
62
61
|
} catch (e) {
|
|
63
62
|
console.error(kolorist.red(String(e)));
|
|
64
|
-
if (e?.stack)
|
|
63
|
+
if (e?.stack) {
|
|
65
64
|
console.error(kolorist.dim(e.stack?.split("\n").slice(1).join("\n")));
|
|
65
|
+
}
|
|
66
66
|
process.exit(1);
|
|
67
67
|
}
|
|
68
68
|
});
|
package/dist/cli.mjs
CHANGED
|
@@ -6,13 +6,12 @@ import { generate, hasTagOnGitHub, isRepoShallow, sendRelease } from './index.mj
|
|
|
6
6
|
import 'ohmyfetch';
|
|
7
7
|
import 'convert-gitmoji';
|
|
8
8
|
|
|
9
|
-
const version = "0.0.
|
|
9
|
+
const version = "0.0.4";
|
|
10
10
|
|
|
11
11
|
const cli = cac("githublogen");
|
|
12
12
|
cli.version(version).option("-t, --token <path>", "GitHub Token").option("--from <ref>", "From tag").option("--to <ref>", "To tag").option("--github <path>", "GitHub Repository, e.g. soybeanjs/githublogen").option("--name <name>", "Name of the release").option("--contributors", "Show contributors section").option("--prerelease", "Mark release as prerelease").option("-d, --draft", "Mark release as draft").option("--output <path>", "Output to file instead of sending to GitHub").option("--capitalize", "Should capitalize for each comment message").option("--emoji", "Use emojis in section titles", { default: true }).option("--group", "Nest commit messages under their scopes").option("--dry", "Dry run").help();
|
|
13
13
|
cli.command("").action(async (args) => {
|
|
14
14
|
args.token = args.token || process.env.GITHUB_TOKEN;
|
|
15
|
-
console.log("args.token: ", args.token);
|
|
16
15
|
try {
|
|
17
16
|
console.log();
|
|
18
17
|
console.log(dim(`${bold("github")}logen `) + dim(`v${version}`));
|
|
@@ -54,8 +53,9 @@ cli.command("").action(async (args) => {
|
|
|
54
53
|
await sendRelease(config, md);
|
|
55
54
|
} catch (e) {
|
|
56
55
|
console.error(red(String(e)));
|
|
57
|
-
if (e?.stack)
|
|
56
|
+
if (e?.stack) {
|
|
58
57
|
console.error(dim(e.stack?.split("\n").slice(1).join("\n")));
|
|
58
|
+
}
|
|
59
59
|
process.exit(1);
|
|
60
60
|
}
|
|
61
61
|
});
|
package/dist/index.cjs
CHANGED
|
@@ -99,24 +99,19 @@ async function resolveAuthorInfo(options, info) {
|
|
|
99
99
|
const data = await ohmyfetch.$fetch(`https://api.github.com/search/users?q=${encodeURIComponent(info.email)}`, {
|
|
100
100
|
headers: getHeaders(options)
|
|
101
101
|
});
|
|
102
|
-
console.log("fetch github user: ", data);
|
|
103
102
|
authorInfo.login = data.items[0].login;
|
|
104
|
-
} catch
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
} catch {
|
|
104
|
+
}
|
|
105
|
+
if (authorInfo.login) {
|
|
106
|
+
return authorInfo;
|
|
107
107
|
}
|
|
108
|
-
if (info.login)
|
|
109
|
-
return info;
|
|
110
108
|
if (info.commits.length) {
|
|
111
109
|
try {
|
|
112
110
|
const data = await ohmyfetch.$fetch(`https://api.github.com/repos/${options.github}/commits/${info.commits[0]}`, {
|
|
113
111
|
headers: getHeaders(options)
|
|
114
112
|
});
|
|
115
|
-
console.log("data: ", data);
|
|
116
113
|
authorInfo.login = data.author.login;
|
|
117
|
-
} catch
|
|
118
|
-
console.log("e: ", e);
|
|
119
|
-
console.log("error fetch github commit");
|
|
114
|
+
} catch {
|
|
120
115
|
}
|
|
121
116
|
}
|
|
122
117
|
return authorInfo;
|
|
@@ -125,8 +120,9 @@ async function resolveAuthors(commits, options) {
|
|
|
125
120
|
const map = /* @__PURE__ */ new Map();
|
|
126
121
|
commits.forEach((commit) => {
|
|
127
122
|
commit.resolvedAuthors = commit.authors.map((a, idx) => {
|
|
128
|
-
if (!a.email || !a.name)
|
|
123
|
+
if (!a.email || !a.name) {
|
|
129
124
|
return null;
|
|
125
|
+
}
|
|
130
126
|
if (!map.has(a.email)) {
|
|
131
127
|
map.set(a.email, {
|
|
132
128
|
commits: [],
|
|
@@ -135,8 +131,9 @@ async function resolveAuthors(commits, options) {
|
|
|
135
131
|
});
|
|
136
132
|
}
|
|
137
133
|
const info = map.get(a.email);
|
|
138
|
-
if (idx === 0)
|
|
134
|
+
if (idx === 0) {
|
|
139
135
|
info.commits.push(commit.shortHash);
|
|
136
|
+
}
|
|
140
137
|
return info;
|
|
141
138
|
}).filter(notNullish);
|
|
142
139
|
});
|
|
@@ -145,13 +142,15 @@ async function resolveAuthors(commits, options) {
|
|
|
145
142
|
const loginSet = /* @__PURE__ */ new Set();
|
|
146
143
|
const nameSet = /* @__PURE__ */ new Set();
|
|
147
144
|
return resolved.sort((a, b) => (a.login || a.name).localeCompare(b.login || b.name)).filter((i) => {
|
|
148
|
-
if (i.login && loginSet.has(i.login))
|
|
145
|
+
if (i.login && loginSet.has(i.login)) {
|
|
149
146
|
return false;
|
|
147
|
+
}
|
|
150
148
|
if (i.login) {
|
|
151
149
|
loginSet.add(i.login);
|
|
152
150
|
} else {
|
|
153
|
-
if (nameSet.has(i.name))
|
|
151
|
+
if (nameSet.has(i.name)) {
|
|
154
152
|
return false;
|
|
153
|
+
}
|
|
155
154
|
nameSet.add(i.name);
|
|
156
155
|
}
|
|
157
156
|
return true;
|
|
@@ -171,8 +170,9 @@ async function hasTagOnGitHub(tag, options) {
|
|
|
171
170
|
async function getGitHubRepo() {
|
|
172
171
|
const url = await execCommand("git", ["config", "--get", "remote.origin.url"]);
|
|
173
172
|
const match = url.match(/github\.com[\/:]([\w\d._-]+?)\/([\w\d._-]+?)(\.git)?$/i);
|
|
174
|
-
if (!match)
|
|
173
|
+
if (!match) {
|
|
175
174
|
throw new Error(`Can not parse GitHub repo from url ${url}`);
|
|
175
|
+
}
|
|
176
176
|
return `${match[1]}/${match[2]}`;
|
|
177
177
|
}
|
|
178
178
|
async function getCurrentGitBranch() {
|
|
@@ -231,19 +231,23 @@ async function getGitDiff(from, to = "HEAD") {
|
|
|
231
231
|
const emojisRE = /([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g;
|
|
232
232
|
function formatReferences(references, github, type) {
|
|
233
233
|
const refs = references.filter((i) => {
|
|
234
|
-
if (type === "issues")
|
|
234
|
+
if (type === "issues") {
|
|
235
235
|
return i.type === "issue" || i.type === "pull-request";
|
|
236
|
+
}
|
|
236
237
|
return i.type === "hash";
|
|
237
238
|
}).map((ref) => {
|
|
238
|
-
if (!github)
|
|
239
|
+
if (!github) {
|
|
239
240
|
return ref.value;
|
|
240
|
-
|
|
241
|
+
}
|
|
242
|
+
if (ref.type === "pull-request" || ref.type === "issue") {
|
|
241
243
|
return `https://github.com/${github}/issues/${ref.value.slice(1)}`;
|
|
244
|
+
}
|
|
242
245
|
return `[<samp>(${ref.value.slice(0, 5)})</samp>](https://github.com/${github}/commit/${ref.value})`;
|
|
243
246
|
});
|
|
244
247
|
const referencesString = join(refs).trim();
|
|
245
|
-
if (type === "issues")
|
|
248
|
+
if (type === "issues") {
|
|
246
249
|
return referencesString && `in ${referencesString}`;
|
|
250
|
+
}
|
|
247
251
|
return referencesString;
|
|
248
252
|
}
|
|
249
253
|
function formatLine(commit, options) {
|
|
@@ -252,11 +256,13 @@ function formatLine(commit, options) {
|
|
|
252
256
|
let authors = join([
|
|
253
257
|
...new Set(commit.resolvedAuthors?.map((i) => i.login ? `@${i.login}` : `**${i.name}**`))
|
|
254
258
|
])?.trim();
|
|
255
|
-
if (authors)
|
|
259
|
+
if (authors) {
|
|
256
260
|
authors = `by ${authors}`;
|
|
261
|
+
}
|
|
257
262
|
let refs = [authors, prRefs, hashRefs].filter((i) => i?.trim()).join(" ");
|
|
258
|
-
if (refs)
|
|
263
|
+
if (refs) {
|
|
259
264
|
refs = ` - ${refs}`;
|
|
265
|
+
}
|
|
260
266
|
const description = options.capitalize ? capitalize(commit.description) : commit.description;
|
|
261
267
|
return [description, refs].filter((i) => i?.trim()).join(" ");
|
|
262
268
|
}
|
|
@@ -268,13 +274,15 @@ function formatTitle(name, options) {
|
|
|
268
274
|
return `### ${formatName}`;
|
|
269
275
|
}
|
|
270
276
|
function formatSection(commits, sectionName, options) {
|
|
271
|
-
if (!commits.length)
|
|
277
|
+
if (!commits.length) {
|
|
272
278
|
return [];
|
|
279
|
+
}
|
|
273
280
|
const lines = ["", formatTitle(sectionName, options), ""];
|
|
274
281
|
const scopes = groupBy(commits, "scope");
|
|
275
282
|
let useScopeGroup = options.group;
|
|
276
|
-
if (!Object.entries(scopes).some(([k, v]) => k && v.length > 1))
|
|
283
|
+
if (!Object.entries(scopes).some(([k, v]) => k && v.length > 1)) {
|
|
277
284
|
useScopeGroup = false;
|
|
285
|
+
}
|
|
278
286
|
Object.keys(scopes).sort().forEach((scope) => {
|
|
279
287
|
let padding = "";
|
|
280
288
|
let prefix = "";
|
|
@@ -346,7 +354,6 @@ async function resolveConfig(options) {
|
|
|
346
354
|
if (config.to === config.from) {
|
|
347
355
|
config.from = await getLastGitTag(-1) || await getFirstGitCommit();
|
|
348
356
|
}
|
|
349
|
-
console.log("resolveConfig => config.token: ", config.token);
|
|
350
357
|
return config;
|
|
351
358
|
}
|
|
352
359
|
|
|
@@ -404,7 +411,8 @@ async function generate(options) {
|
|
|
404
411
|
const rawCommits = await getGitDiff(resolved.from, resolved.to);
|
|
405
412
|
const commits = parseCommits(rawCommits, resolved);
|
|
406
413
|
if (resolved.contributors) {
|
|
407
|
-
await resolveAuthors(commits, resolved);
|
|
414
|
+
const authorInfo = await resolveAuthors(commits, resolved);
|
|
415
|
+
Object.assign(resolved, authorInfo);
|
|
408
416
|
}
|
|
409
417
|
const md = generateMarkdown(commits, resolved);
|
|
410
418
|
return { config: resolved, md, commits };
|
package/dist/index.mjs
CHANGED
|
@@ -97,24 +97,19 @@ async function resolveAuthorInfo(options, info) {
|
|
|
97
97
|
const data = await $fetch(`https://api.github.com/search/users?q=${encodeURIComponent(info.email)}`, {
|
|
98
98
|
headers: getHeaders(options)
|
|
99
99
|
});
|
|
100
|
-
console.log("fetch github user: ", data);
|
|
101
100
|
authorInfo.login = data.items[0].login;
|
|
102
|
-
} catch
|
|
103
|
-
|
|
104
|
-
|
|
101
|
+
} catch {
|
|
102
|
+
}
|
|
103
|
+
if (authorInfo.login) {
|
|
104
|
+
return authorInfo;
|
|
105
105
|
}
|
|
106
|
-
if (info.login)
|
|
107
|
-
return info;
|
|
108
106
|
if (info.commits.length) {
|
|
109
107
|
try {
|
|
110
108
|
const data = await $fetch(`https://api.github.com/repos/${options.github}/commits/${info.commits[0]}`, {
|
|
111
109
|
headers: getHeaders(options)
|
|
112
110
|
});
|
|
113
|
-
console.log("data: ", data);
|
|
114
111
|
authorInfo.login = data.author.login;
|
|
115
|
-
} catch
|
|
116
|
-
console.log("e: ", e);
|
|
117
|
-
console.log("error fetch github commit");
|
|
112
|
+
} catch {
|
|
118
113
|
}
|
|
119
114
|
}
|
|
120
115
|
return authorInfo;
|
|
@@ -123,8 +118,9 @@ async function resolveAuthors(commits, options) {
|
|
|
123
118
|
const map = /* @__PURE__ */ new Map();
|
|
124
119
|
commits.forEach((commit) => {
|
|
125
120
|
commit.resolvedAuthors = commit.authors.map((a, idx) => {
|
|
126
|
-
if (!a.email || !a.name)
|
|
121
|
+
if (!a.email || !a.name) {
|
|
127
122
|
return null;
|
|
123
|
+
}
|
|
128
124
|
if (!map.has(a.email)) {
|
|
129
125
|
map.set(a.email, {
|
|
130
126
|
commits: [],
|
|
@@ -133,8 +129,9 @@ async function resolveAuthors(commits, options) {
|
|
|
133
129
|
});
|
|
134
130
|
}
|
|
135
131
|
const info = map.get(a.email);
|
|
136
|
-
if (idx === 0)
|
|
132
|
+
if (idx === 0) {
|
|
137
133
|
info.commits.push(commit.shortHash);
|
|
134
|
+
}
|
|
138
135
|
return info;
|
|
139
136
|
}).filter(notNullish);
|
|
140
137
|
});
|
|
@@ -143,13 +140,15 @@ async function resolveAuthors(commits, options) {
|
|
|
143
140
|
const loginSet = /* @__PURE__ */ new Set();
|
|
144
141
|
const nameSet = /* @__PURE__ */ new Set();
|
|
145
142
|
return resolved.sort((a, b) => (a.login || a.name).localeCompare(b.login || b.name)).filter((i) => {
|
|
146
|
-
if (i.login && loginSet.has(i.login))
|
|
143
|
+
if (i.login && loginSet.has(i.login)) {
|
|
147
144
|
return false;
|
|
145
|
+
}
|
|
148
146
|
if (i.login) {
|
|
149
147
|
loginSet.add(i.login);
|
|
150
148
|
} else {
|
|
151
|
-
if (nameSet.has(i.name))
|
|
149
|
+
if (nameSet.has(i.name)) {
|
|
152
150
|
return false;
|
|
151
|
+
}
|
|
153
152
|
nameSet.add(i.name);
|
|
154
153
|
}
|
|
155
154
|
return true;
|
|
@@ -169,8 +168,9 @@ async function hasTagOnGitHub(tag, options) {
|
|
|
169
168
|
async function getGitHubRepo() {
|
|
170
169
|
const url = await execCommand("git", ["config", "--get", "remote.origin.url"]);
|
|
171
170
|
const match = url.match(/github\.com[\/:]([\w\d._-]+?)\/([\w\d._-]+?)(\.git)?$/i);
|
|
172
|
-
if (!match)
|
|
171
|
+
if (!match) {
|
|
173
172
|
throw new Error(`Can not parse GitHub repo from url ${url}`);
|
|
173
|
+
}
|
|
174
174
|
return `${match[1]}/${match[2]}`;
|
|
175
175
|
}
|
|
176
176
|
async function getCurrentGitBranch() {
|
|
@@ -229,19 +229,23 @@ async function getGitDiff(from, to = "HEAD") {
|
|
|
229
229
|
const emojisRE = /([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g;
|
|
230
230
|
function formatReferences(references, github, type) {
|
|
231
231
|
const refs = references.filter((i) => {
|
|
232
|
-
if (type === "issues")
|
|
232
|
+
if (type === "issues") {
|
|
233
233
|
return i.type === "issue" || i.type === "pull-request";
|
|
234
|
+
}
|
|
234
235
|
return i.type === "hash";
|
|
235
236
|
}).map((ref) => {
|
|
236
|
-
if (!github)
|
|
237
|
+
if (!github) {
|
|
237
238
|
return ref.value;
|
|
238
|
-
|
|
239
|
+
}
|
|
240
|
+
if (ref.type === "pull-request" || ref.type === "issue") {
|
|
239
241
|
return `https://github.com/${github}/issues/${ref.value.slice(1)}`;
|
|
242
|
+
}
|
|
240
243
|
return `[<samp>(${ref.value.slice(0, 5)})</samp>](https://github.com/${github}/commit/${ref.value})`;
|
|
241
244
|
});
|
|
242
245
|
const referencesString = join(refs).trim();
|
|
243
|
-
if (type === "issues")
|
|
246
|
+
if (type === "issues") {
|
|
244
247
|
return referencesString && `in ${referencesString}`;
|
|
248
|
+
}
|
|
245
249
|
return referencesString;
|
|
246
250
|
}
|
|
247
251
|
function formatLine(commit, options) {
|
|
@@ -250,11 +254,13 @@ function formatLine(commit, options) {
|
|
|
250
254
|
let authors = join([
|
|
251
255
|
...new Set(commit.resolvedAuthors?.map((i) => i.login ? `@${i.login}` : `**${i.name}**`))
|
|
252
256
|
])?.trim();
|
|
253
|
-
if (authors)
|
|
257
|
+
if (authors) {
|
|
254
258
|
authors = `by ${authors}`;
|
|
259
|
+
}
|
|
255
260
|
let refs = [authors, prRefs, hashRefs].filter((i) => i?.trim()).join(" ");
|
|
256
|
-
if (refs)
|
|
261
|
+
if (refs) {
|
|
257
262
|
refs = ` - ${refs}`;
|
|
263
|
+
}
|
|
258
264
|
const description = options.capitalize ? capitalize(commit.description) : commit.description;
|
|
259
265
|
return [description, refs].filter((i) => i?.trim()).join(" ");
|
|
260
266
|
}
|
|
@@ -266,13 +272,15 @@ function formatTitle(name, options) {
|
|
|
266
272
|
return `### ${formatName}`;
|
|
267
273
|
}
|
|
268
274
|
function formatSection(commits, sectionName, options) {
|
|
269
|
-
if (!commits.length)
|
|
275
|
+
if (!commits.length) {
|
|
270
276
|
return [];
|
|
277
|
+
}
|
|
271
278
|
const lines = ["", formatTitle(sectionName, options), ""];
|
|
272
279
|
const scopes = groupBy(commits, "scope");
|
|
273
280
|
let useScopeGroup = options.group;
|
|
274
|
-
if (!Object.entries(scopes).some(([k, v]) => k && v.length > 1))
|
|
281
|
+
if (!Object.entries(scopes).some(([k, v]) => k && v.length > 1)) {
|
|
275
282
|
useScopeGroup = false;
|
|
283
|
+
}
|
|
276
284
|
Object.keys(scopes).sort().forEach((scope) => {
|
|
277
285
|
let padding = "";
|
|
278
286
|
let prefix = "";
|
|
@@ -344,7 +352,6 @@ async function resolveConfig(options) {
|
|
|
344
352
|
if (config.to === config.from) {
|
|
345
353
|
config.from = await getLastGitTag(-1) || await getFirstGitCommit();
|
|
346
354
|
}
|
|
347
|
-
console.log("resolveConfig => config.token: ", config.token);
|
|
348
355
|
return config;
|
|
349
356
|
}
|
|
350
357
|
|
|
@@ -402,7 +409,8 @@ async function generate(options) {
|
|
|
402
409
|
const rawCommits = await getGitDiff(resolved.from, resolved.to);
|
|
403
410
|
const commits = parseCommits(rawCommits, resolved);
|
|
404
411
|
if (resolved.contributors) {
|
|
405
|
-
await resolveAuthors(commits, resolved);
|
|
412
|
+
const authorInfo = await resolveAuthors(commits, resolved);
|
|
413
|
+
Object.assign(resolved, authorInfo);
|
|
406
414
|
}
|
|
407
415
|
const md = generateMarkdown(commits, resolved);
|
|
408
416
|
return { config: resolved, md, commits };
|