keepchanges 1.0.0-beta.2 → 1.0.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.mjs +20 -10
- package/package.json +1 -1
package/dist/cli.mjs
CHANGED
|
@@ -8,7 +8,7 @@ import { resolve } from "node:path";
|
|
|
8
8
|
import ansis from "ansis";
|
|
9
9
|
import { x } from "tinyexec";
|
|
10
10
|
//#region package.json
|
|
11
|
-
var version = "1.0.0
|
|
11
|
+
var version = "1.0.0";
|
|
12
12
|
//#endregion
|
|
13
13
|
//#region src/git.ts
|
|
14
14
|
async function git(cwd, ...args) {
|
|
@@ -95,17 +95,18 @@ const giteaRepository = {
|
|
|
95
95
|
accept: "application/json",
|
|
96
96
|
authorization: `token ${token}`
|
|
97
97
|
};
|
|
98
|
-
const
|
|
99
|
-
|
|
100
|
-
|
|
98
|
+
const authorsByEmail = collectRepositoryAuthors(commits);
|
|
99
|
+
await Promise.all([...authorsByEmail.values()].map(async (info) => {
|
|
100
|
+
const { author, commit } = info;
|
|
101
|
+
if (!commit) return;
|
|
101
102
|
try {
|
|
102
103
|
const response = await fetch(`${new URL(repository.webUrl).origin}/api/v1/repos/${repository.path}/git/commits/${commit.hash}`, { headers });
|
|
103
104
|
if (!response.ok) return;
|
|
104
105
|
const data = await response.json();
|
|
105
|
-
if (data.author?.login)
|
|
106
|
+
if (data.author?.login) author.login = data.author.login;
|
|
106
107
|
} catch {}
|
|
107
108
|
}));
|
|
108
|
-
for (const commit of commits) for (const author of commit.authors) author.login =
|
|
109
|
+
for (const commit of commits) for (const author of commit.authors) author.login = authorsByEmail.get(author.email)?.author.login;
|
|
109
110
|
},
|
|
110
111
|
async publishRelease(repository, release, token, fetch) {
|
|
111
112
|
const headers = {
|
|
@@ -183,15 +184,15 @@ const githubRepository = {
|
|
|
183
184
|
accept: "application/vnd.github.v3+json",
|
|
184
185
|
authorization: `token ${token}`
|
|
185
186
|
};
|
|
186
|
-
const authorsByEmail =
|
|
187
|
-
await Promise.all([...authorsByEmail.values()].map(async (
|
|
187
|
+
const authorsByEmail = collectRepositoryAuthors(commits);
|
|
188
|
+
await Promise.all([...authorsByEmail.values()].map(async (info) => {
|
|
189
|
+
const { author, commit } = info;
|
|
188
190
|
try {
|
|
189
191
|
author.login = (await (await fetch(`https://api.github.com/search/users?q=${encodeURIComponent(`${author.email} type:user in:email`)}`, { headers })).json()).items?.[0]?.login;
|
|
190
|
-
const commit = commits.find((commit) => commit.authors[0].email === author.email);
|
|
191
192
|
if (!author.login && commit) author.login = (await (await fetch(`https://api.github.com/repos/${repository.path}/commits/${commit.hash}`, { headers })).json()).author?.login;
|
|
192
193
|
} catch {}
|
|
193
194
|
}));
|
|
194
|
-
for (const commit of commits) for (const author of commit.authors) author.login = authorsByEmail.get(author.email)?.login;
|
|
195
|
+
for (const commit of commits) for (const author of commit.authors) author.login = authorsByEmail.get(author.email)?.author.login;
|
|
195
196
|
},
|
|
196
197
|
async publishRelease(repository, release, token, fetch) {
|
|
197
198
|
const headers = {
|
|
@@ -229,6 +230,15 @@ const githubRepository = {
|
|
|
229
230
|
};
|
|
230
231
|
//#endregion
|
|
231
232
|
//#region src/repository.ts
|
|
233
|
+
function collectRepositoryAuthors(commits) {
|
|
234
|
+
const authorsByEmail = /* @__PURE__ */ new Map();
|
|
235
|
+
for (const commit of commits) commit.authors.forEach((author, index) => {
|
|
236
|
+
const info = authorsByEmail.get(author.email) ?? { author };
|
|
237
|
+
if (index === 0 && !info.commit) info.commit = commit;
|
|
238
|
+
authorsByEmail.set(author.email, info);
|
|
239
|
+
});
|
|
240
|
+
return authorsByEmail;
|
|
241
|
+
}
|
|
232
242
|
const repositoryProviders = {
|
|
233
243
|
github: githubRepository,
|
|
234
244
|
gitea: giteaRepository
|