Use a custom config named user.username to pass Github username to the checker

This commit is contained in:
gbuomprisco
2024-09-22 23:19:22 +02:00
parent d5f23cd49f
commit d6bcbbdfdf

View File

@@ -6,15 +6,16 @@ async function checkLicense() {
let gitUser, gitEmail; let gitUser, gitEmail;
try { try {
gitUser = execSync('git config user.name').toString().trim(); gitUser =
execSync('git config user.username').toString().trim() ||
execSync('git config user.name').toString().trim();
} catch (error) { } catch (error) {
console.error('Error getting git config:', error.message); return;
process.exit(1);
} }
if (!gitUser) { if (!gitUser && !gitEmail) {
throw new Error( throw new Error(
"Please set the git user name with the command 'git config user.name <username>'. The username needs to match the username in your Makerkit organization.", "Please set the git user name with the command 'git config user.username <username>'. The username needs to match the GitHub username in your Makerkit organization.",
); );
} }
@@ -22,6 +23,12 @@ async function checkLicense() {
gitEmail = execSync('git config user.email').toString().trim(); gitEmail = execSync('git config user.email').toString().trim();
} catch (error) { } catch (error) {
console.info('Error getting git config:', error.message); console.info('Error getting git config:', error.message);
if (!gitUser) {
throw new Error(
"Please set the git user name with the command 'git config user.username <username>'. The username needs to match the GitHub username in your Makerkit organization.",
);
}
} }
const searchParams = new URLSearchParams(); const searchParams = new URLSearchParams();
@@ -32,15 +39,13 @@ async function checkLicense() {
searchParams.append('email', gitEmail); searchParams.append('email', gitEmail);
} }
const res = await fetch( const res = await fetch(`${endpoint}?${searchParams.toString()}`);
`${endpoint}?${searchParams.toString()}`,
);
if (res.status === 200) { if (res.status === 200) {
return Promise.resolve(); return Promise.resolve();
} else { } else {
return Promise.reject( return Promise.reject(
new Error(`License check failed with status code: ${res.status}`), new Error(`License check failed. Please set the git user name with the command 'git config user.username <username>'. The username needs to match the GitHub username in your Makerkit organization.`),
); );
} }
} }