Comparing version 3.0.1 to 3.0.2
@@ -31,2 +31,5 @@ import * as fs from "fs/promises"; | ||
} | ||
const user = await getGitUser(githubToken); | ||
childprocess.execSync(`git config --global user.name "${user.name}"`); | ||
childprocess.execSync(`git config --global user.email "${user.email}"`); | ||
const releaseTag = calculateReleaseTag(metadata.version, publishedVersions); | ||
@@ -185,1 +188,76 @@ try { | ||
} | ||
async function getGitUser(token) { | ||
const userResponse = await fetch("https://api.github.com/user", { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
Accept: "application/json" | ||
} | ||
}); | ||
if (!userResponse.ok) { | ||
if (userResponse.body !== null) { | ||
await userResponse.body.cancel(); | ||
} | ||
throw new Error("Failed to fetch data from GitHub"); | ||
} | ||
const githubUserJSON = await userResponse.json(); | ||
if (typeof githubUserJSON !== "object" || githubUserJSON === null) { | ||
throw new Error("Failed to fetch data from GitHub"); | ||
} | ||
let username; | ||
if ("login" in githubUserJSON && typeof githubUserJSON.login === "string") { | ||
username = githubUserJSON.login; | ||
} | ||
else { | ||
throw new Error("Failed to fetch data from GitHub"); | ||
} | ||
const emailsResponse = await fetch("https://api.github.com/user/emails", { | ||
headers: { | ||
Authorization: `Bearer ${token}`, | ||
Accept: "application/json" | ||
} | ||
}); | ||
if (!emailsResponse.ok) { | ||
if (emailsResponse.body !== null) { | ||
await emailsResponse.body.cancel(); | ||
} | ||
throw new Error("Failed to fetch data from GitHub"); | ||
} | ||
const githubEmailsJSON = await emailsResponse.json(); | ||
if (!Array.isArray(githubEmailsJSON)) { | ||
throw new Error("Failed to fetch data from GitHub"); | ||
} | ||
for (const emailJSON of githubEmailsJSON) { | ||
if (typeof emailJSON !== "object" || emailJSON === null) { | ||
throw new Error("Failed to fetch data from GitHub"); | ||
} | ||
let email; | ||
if ("email" in emailJSON && typeof emailJSON.email === "string") { | ||
email = emailJSON.email; | ||
} | ||
else { | ||
throw new Error("Failed to fetch data from GitHub"); | ||
} | ||
let emailVerified; | ||
if ("verified" in emailJSON && typeof emailJSON.verified === "boolean") { | ||
emailVerified = emailJSON.verified; | ||
} | ||
else { | ||
throw new Error("Failed to fetch data from GitHub"); | ||
} | ||
let primaryEmail; | ||
if ("primary" in emailJSON && typeof emailJSON.primary === "boolean") { | ||
primaryEmail = emailJSON.primary; | ||
} | ||
else { | ||
throw new Error("Failed to fetch data from GitHub"); | ||
} | ||
if (emailVerified && primaryEmail) { | ||
const gitUser = { | ||
email: email, | ||
name: username | ||
}; | ||
return gitUser; | ||
} | ||
} | ||
throw new Error("User email not verified"); | ||
} |
{ | ||
"name": "auri", | ||
"version": "3.0.1", | ||
"version": "3.0.2", | ||
"description": "Organize package changes and releases", | ||
@@ -5,0 +5,0 @@ "type": "module", |
20041
463
6