Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing licenses #28

Merged
merged 5 commits into from
Nov 29, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add tool to find license
sebromero committed Nov 29, 2024
commit 40b348b3084660d8b55455acf4f3210ffdb8d744
33 changes: 33 additions & 0 deletions tools/find-license.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
function convertToRawURL(url, suffix = null) {
url = url.replace('https://github.com/', '');
const parts = url.split('/');
const owner = parts[0];
const repoName = parts[1];
const branch = 'HEAD';
let path = parts[2] ? "/" + parts[2] : '';
if (suffix) {
path += "/" + suffix;
}
return `https://raw.githubusercontent.com/${owner}/${repoName}/${branch}${path}`;
}

async function findLicenseURL(url) {
const licenseFileURL = convertToRawURL(url, 'LICENSE');
// Fetch the license file
const licenseResponse = await fetch(licenseFileURL);
if (licenseResponse.ok) {
const licenseText = await licenseResponse.text();
// Get the first line of the license file
const license = licenseText.split('\n')[0];
return license;
}
return null;
}

if(process.argv.length < 3) {
console.error('Usage: node find-license.mjs <GitHub URL>');
process.exit(1);
}

const license = await findLicenseURL(process.argv[2]);
if (license) console.log(license);