githublogen 0.0.3 → 0.1.0

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 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.3";
16
+ const version = "0.1.0";
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.3";
9
+ const version = "0.1.0";
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
@@ -94,16 +94,12 @@ async function resolveAuthorInfo(options, info) {
94
94
  return info;
95
95
  if (!options.token)
96
96
  return info;
97
- const authorInfo = { ...info };
98
97
  try {
99
98
  const data = await ohmyfetch.$fetch(`https://api.github.com/search/users?q=${encodeURIComponent(info.email)}`, {
100
99
  headers: getHeaders(options)
101
100
  });
102
- console.log("fetch github user: ", data);
103
- authorInfo.login = data.items[0].login;
104
- } catch (error) {
105
- console.log("error: ", error);
106
- console.log("error fetch github user");
101
+ info.login = data.items[0].login;
102
+ } catch {
107
103
  }
108
104
  if (info.login)
109
105
  return info;
@@ -112,21 +108,19 @@ async function resolveAuthorInfo(options, info) {
112
108
  const data = await ohmyfetch.$fetch(`https://api.github.com/repos/${options.github}/commits/${info.commits[0]}`, {
113
109
  headers: getHeaders(options)
114
110
  });
115
- console.log("data: ", data);
116
- authorInfo.login = data.author.login;
111
+ info.login = data.author.login;
117
112
  } catch (e) {
118
- console.log("e: ", e);
119
- console.log("error fetch github commit");
120
113
  }
121
114
  }
122
- return authorInfo;
115
+ return info;
123
116
  }
124
117
  async function resolveAuthors(commits, options) {
125
118
  const map = /* @__PURE__ */ new Map();
126
119
  commits.forEach((commit) => {
127
120
  commit.resolvedAuthors = commit.authors.map((a, idx) => {
128
- if (!a.email || !a.name)
121
+ if (!a.email || !a.name) {
129
122
  return null;
123
+ }
130
124
  if (!map.has(a.email)) {
131
125
  map.set(a.email, {
132
126
  commits: [],
@@ -135,8 +129,9 @@ async function resolveAuthors(commits, options) {
135
129
  });
136
130
  }
137
131
  const info = map.get(a.email);
138
- if (idx === 0)
132
+ if (idx === 0) {
139
133
  info.commits.push(commit.shortHash);
134
+ }
140
135
  return info;
141
136
  }).filter(notNullish);
142
137
  });
@@ -145,13 +140,15 @@ async function resolveAuthors(commits, options) {
145
140
  const loginSet = /* @__PURE__ */ new Set();
146
141
  const nameSet = /* @__PURE__ */ new Set();
147
142
  return resolved.sort((a, b) => (a.login || a.name).localeCompare(b.login || b.name)).filter((i) => {
148
- if (i.login && loginSet.has(i.login))
143
+ if (i.login && loginSet.has(i.login)) {
149
144
  return false;
145
+ }
150
146
  if (i.login) {
151
147
  loginSet.add(i.login);
152
148
  } else {
153
- if (nameSet.has(i.name))
149
+ if (nameSet.has(i.name)) {
154
150
  return false;
151
+ }
155
152
  nameSet.add(i.name);
156
153
  }
157
154
  return true;
@@ -171,8 +168,9 @@ async function hasTagOnGitHub(tag, options) {
171
168
  async function getGitHubRepo() {
172
169
  const url = await execCommand("git", ["config", "--get", "remote.origin.url"]);
173
170
  const match = url.match(/github\.com[\/:]([\w\d._-]+?)\/([\w\d._-]+?)(\.git)?$/i);
174
- if (!match)
171
+ if (!match) {
175
172
  throw new Error(`Can not parse GitHub repo from url ${url}`);
173
+ }
176
174
  return `${match[1]}/${match[2]}`;
177
175
  }
178
176
  async function getCurrentGitBranch() {
@@ -231,19 +229,23 @@ async function getGitDiff(from, to = "HEAD") {
231
229
  const emojisRE = /([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g;
232
230
  function formatReferences(references, github, type) {
233
231
  const refs = references.filter((i) => {
234
- if (type === "issues")
232
+ if (type === "issues") {
235
233
  return i.type === "issue" || i.type === "pull-request";
234
+ }
236
235
  return i.type === "hash";
237
236
  }).map((ref) => {
238
- if (!github)
237
+ if (!github) {
239
238
  return ref.value;
240
- if (ref.type === "pull-request" || ref.type === "issue")
239
+ }
240
+ if (ref.type === "pull-request" || ref.type === "issue") {
241
241
  return `https://github.com/${github}/issues/${ref.value.slice(1)}`;
242
+ }
242
243
  return `[<samp>(${ref.value.slice(0, 5)})</samp>](https://github.com/${github}/commit/${ref.value})`;
243
244
  });
244
245
  const referencesString = join(refs).trim();
245
- if (type === "issues")
246
+ if (type === "issues") {
246
247
  return referencesString && `in ${referencesString}`;
248
+ }
247
249
  return referencesString;
248
250
  }
249
251
  function formatLine(commit, options) {
@@ -252,11 +254,13 @@ function formatLine(commit, options) {
252
254
  let authors = join([
253
255
  ...new Set(commit.resolvedAuthors?.map((i) => i.login ? `@${i.login}` : `**${i.name}**`))
254
256
  ])?.trim();
255
- if (authors)
257
+ if (authors) {
256
258
  authors = `by ${authors}`;
259
+ }
257
260
  let refs = [authors, prRefs, hashRefs].filter((i) => i?.trim()).join(" ");
258
- if (refs)
261
+ if (refs) {
259
262
  refs = `&nbsp;-&nbsp; ${refs}`;
263
+ }
260
264
  const description = options.capitalize ? capitalize(commit.description) : commit.description;
261
265
  return [description, refs].filter((i) => i?.trim()).join(" ");
262
266
  }
@@ -268,13 +272,15 @@ function formatTitle(name, options) {
268
272
  return `### &nbsp;&nbsp;&nbsp;${formatName}`;
269
273
  }
270
274
  function formatSection(commits, sectionName, options) {
271
- if (!commits.length)
275
+ if (!commits.length) {
272
276
  return [];
277
+ }
273
278
  const lines = ["", formatTitle(sectionName, options), ""];
274
279
  const scopes = groupBy(commits, "scope");
275
280
  let useScopeGroup = options.group;
276
- if (!Object.entries(scopes).some(([k, v]) => k && v.length > 1))
281
+ if (!Object.entries(scopes).some(([k, v]) => k && v.length > 1)) {
277
282
  useScopeGroup = false;
283
+ }
278
284
  Object.keys(scopes).sort().forEach((scope) => {
279
285
  let padding = "";
280
286
  let prefix = "";
@@ -346,7 +352,6 @@ async function resolveConfig(options) {
346
352
  if (config.to === config.from) {
347
353
  config.from = await getLastGitTag(-1) || await getFirstGitCommit();
348
354
  }
349
- console.log("resolveConfig => config.token: ", config.token);
350
355
  return config;
351
356
  }
352
357
 
package/dist/index.mjs CHANGED
@@ -92,16 +92,12 @@ async function resolveAuthorInfo(options, info) {
92
92
  return info;
93
93
  if (!options.token)
94
94
  return info;
95
- const authorInfo = { ...info };
96
95
  try {
97
96
  const data = await $fetch(`https://api.github.com/search/users?q=${encodeURIComponent(info.email)}`, {
98
97
  headers: getHeaders(options)
99
98
  });
100
- console.log("fetch github user: ", data);
101
- authorInfo.login = data.items[0].login;
102
- } catch (error) {
103
- console.log("error: ", error);
104
- console.log("error fetch github user");
99
+ info.login = data.items[0].login;
100
+ } catch {
105
101
  }
106
102
  if (info.login)
107
103
  return info;
@@ -110,21 +106,19 @@ async function resolveAuthorInfo(options, info) {
110
106
  const data = await $fetch(`https://api.github.com/repos/${options.github}/commits/${info.commits[0]}`, {
111
107
  headers: getHeaders(options)
112
108
  });
113
- console.log("data: ", data);
114
- authorInfo.login = data.author.login;
109
+ info.login = data.author.login;
115
110
  } catch (e) {
116
- console.log("e: ", e);
117
- console.log("error fetch github commit");
118
111
  }
119
112
  }
120
- return authorInfo;
113
+ return info;
121
114
  }
122
115
  async function resolveAuthors(commits, options) {
123
116
  const map = /* @__PURE__ */ new Map();
124
117
  commits.forEach((commit) => {
125
118
  commit.resolvedAuthors = commit.authors.map((a, idx) => {
126
- if (!a.email || !a.name)
119
+ if (!a.email || !a.name) {
127
120
  return null;
121
+ }
128
122
  if (!map.has(a.email)) {
129
123
  map.set(a.email, {
130
124
  commits: [],
@@ -133,8 +127,9 @@ async function resolveAuthors(commits, options) {
133
127
  });
134
128
  }
135
129
  const info = map.get(a.email);
136
- if (idx === 0)
130
+ if (idx === 0) {
137
131
  info.commits.push(commit.shortHash);
132
+ }
138
133
  return info;
139
134
  }).filter(notNullish);
140
135
  });
@@ -143,13 +138,15 @@ async function resolveAuthors(commits, options) {
143
138
  const loginSet = /* @__PURE__ */ new Set();
144
139
  const nameSet = /* @__PURE__ */ new Set();
145
140
  return resolved.sort((a, b) => (a.login || a.name).localeCompare(b.login || b.name)).filter((i) => {
146
- if (i.login && loginSet.has(i.login))
141
+ if (i.login && loginSet.has(i.login)) {
147
142
  return false;
143
+ }
148
144
  if (i.login) {
149
145
  loginSet.add(i.login);
150
146
  } else {
151
- if (nameSet.has(i.name))
147
+ if (nameSet.has(i.name)) {
152
148
  return false;
149
+ }
153
150
  nameSet.add(i.name);
154
151
  }
155
152
  return true;
@@ -169,8 +166,9 @@ async function hasTagOnGitHub(tag, options) {
169
166
  async function getGitHubRepo() {
170
167
  const url = await execCommand("git", ["config", "--get", "remote.origin.url"]);
171
168
  const match = url.match(/github\.com[\/:]([\w\d._-]+?)\/([\w\d._-]+?)(\.git)?$/i);
172
- if (!match)
169
+ if (!match) {
173
170
  throw new Error(`Can not parse GitHub repo from url ${url}`);
171
+ }
174
172
  return `${match[1]}/${match[2]}`;
175
173
  }
176
174
  async function getCurrentGitBranch() {
@@ -229,19 +227,23 @@ async function getGitDiff(from, to = "HEAD") {
229
227
  const emojisRE = /([\u2700-\u27BF]|[\uE000-\uF8FF]|\uD83C[\uDC00-\uDFFF]|\uD83D[\uDC00-\uDFFF]|[\u2011-\u26FF]|\uD83E[\uDD10-\uDDFF])/g;
230
228
  function formatReferences(references, github, type) {
231
229
  const refs = references.filter((i) => {
232
- if (type === "issues")
230
+ if (type === "issues") {
233
231
  return i.type === "issue" || i.type === "pull-request";
232
+ }
234
233
  return i.type === "hash";
235
234
  }).map((ref) => {
236
- if (!github)
235
+ if (!github) {
237
236
  return ref.value;
238
- if (ref.type === "pull-request" || ref.type === "issue")
237
+ }
238
+ if (ref.type === "pull-request" || ref.type === "issue") {
239
239
  return `https://github.com/${github}/issues/${ref.value.slice(1)}`;
240
+ }
240
241
  return `[<samp>(${ref.value.slice(0, 5)})</samp>](https://github.com/${github}/commit/${ref.value})`;
241
242
  });
242
243
  const referencesString = join(refs).trim();
243
- if (type === "issues")
244
+ if (type === "issues") {
244
245
  return referencesString && `in ${referencesString}`;
246
+ }
245
247
  return referencesString;
246
248
  }
247
249
  function formatLine(commit, options) {
@@ -250,11 +252,13 @@ function formatLine(commit, options) {
250
252
  let authors = join([
251
253
  ...new Set(commit.resolvedAuthors?.map((i) => i.login ? `@${i.login}` : `**${i.name}**`))
252
254
  ])?.trim();
253
- if (authors)
255
+ if (authors) {
254
256
  authors = `by ${authors}`;
257
+ }
255
258
  let refs = [authors, prRefs, hashRefs].filter((i) => i?.trim()).join(" ");
256
- if (refs)
259
+ if (refs) {
257
260
  refs = `&nbsp;-&nbsp; ${refs}`;
261
+ }
258
262
  const description = options.capitalize ? capitalize(commit.description) : commit.description;
259
263
  return [description, refs].filter((i) => i?.trim()).join(" ");
260
264
  }
@@ -266,13 +270,15 @@ function formatTitle(name, options) {
266
270
  return `### &nbsp;&nbsp;&nbsp;${formatName}`;
267
271
  }
268
272
  function formatSection(commits, sectionName, options) {
269
- if (!commits.length)
273
+ if (!commits.length) {
270
274
  return [];
275
+ }
271
276
  const lines = ["", formatTitle(sectionName, options), ""];
272
277
  const scopes = groupBy(commits, "scope");
273
278
  let useScopeGroup = options.group;
274
- if (!Object.entries(scopes).some(([k, v]) => k && v.length > 1))
279
+ if (!Object.entries(scopes).some(([k, v]) => k && v.length > 1)) {
275
280
  useScopeGroup = false;
281
+ }
276
282
  Object.keys(scopes).sort().forEach((scope) => {
277
283
  let padding = "";
278
284
  let prefix = "";
@@ -344,7 +350,6 @@ async function resolveConfig(options) {
344
350
  if (config.to === config.from) {
345
351
  config.from = await getLastGitTag(-1) || await getFirstGitCommit();
346
352
  }
347
- console.log("resolveConfig => config.token: ", config.token);
348
353
  return config;
349
354
  }
350
355
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "githublogen",
3
3
  "type": "module",
4
- "version": "0.0.3",
4
+ "version": "0.1.0",
5
5
  "sideEffects": false,
6
6
  "author": {
7
7
  "name": "SoybeanJS",