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

Check whether extension has an OSI approved license #513

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
21 changes: 21 additions & 0 deletions lib/resolveExtension.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const fs = require('fs');
const path = require('path');
const Octokit = require('octokit').Octokit;
const readVSIXPackage = require('vsce/out/zip').readVSIXPackage;
const osiLicenses = require('osi-licenses');
const download = require('download');
const exec = require('./exec');

Expand Down Expand Up @@ -53,6 +54,26 @@ exports.resolveExtension = async function ({ id, repository, location }, ms) {
await exec(`git clone --filter=blob:none --recurse-submodules ${repository} ${repoPath}`, { quiet: true });

const packagePath = [repoPath, location, 'package.json'].filter(p => !!p).join('/');

//#region Check if the extension has an OSI-approved open-source license
try {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not we check a revision form which we build vsix file?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great catch, @akosyakov, I was thinking about doing that, settled on "licenses don't change from commit to commit, right?". In edge cases where a license might be changed, added, or removed, I'll integrate it into the resolveVersion function to avoid otherwise duplicating the code over and over.

https://github.com/open-vsx/publish-extensions/blob/4d657302ecdb5f219159486335ec883df1216bf9/lib/resolveExtension.js#L60-L71

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just looked into this again, and it seems there is no way to fetch the license for a specific time in the repository, just the current state. I checked with both the REST and GraphQL APIs, the only parameters allowed are name and owner.

const manifest = JSON.parse(await fs.promises.readFile(packagePath, 'utf-8'));
const license = manifest.license;
if (!(license && Object.keys(osiLicenses).includes(license))) {
if (repositoryUrl.hostname !== 'github.com') return undefined;

const ghLicenseResponse = (await octokit.rest.licenses.getForRepo({ owner, repo })).data.license;
if (!Object.keys(osiLicenses).includes(ghLicenseResponse.spdx_id)) {
console.log(`Not an OSS license: ${ghLicenseResponse.name} (${ghLicenseResponse.spdx_id})`);
return undefined;
}
}
} catch {
console.log('Can\'t process license');
return undefined;
}
//#endregion

/**
* @param {string} ref
* @returns {Promise<string | undefined>}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"download": "^8.0.0",
"minimist": "^1.2.5",
"octokit": "^1.7.0",
"osi-licenses": "^0.1.1",
"ovsx": "latest",
"semver": "^7.1.3",
"vsce": "^2.3.0"
Expand Down