From e3908c4796d2bd830785b1f2da29d4cc379f7c1c Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Sat, 16 Mar 2019 21:17:21 -0400 Subject: [PATCH 1/2] Updating the gatsby-plugin-checker. It now filters out packages that lack a repository, have bad repo links, incorrect name formats, or lack READMEs. --- scripts/gatsby-plugin-checker/README.md | 3 ++ scripts/gatsby-plugin-checker/index.js | 59 +++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 scripts/gatsby-plugin-checker/README.md diff --git a/scripts/gatsby-plugin-checker/README.md b/scripts/gatsby-plugin-checker/README.md new file mode 100644 index 0000000000000..daa095cf07ec4 --- /dev/null +++ b/scripts/gatsby-plugin-checker/README.md @@ -0,0 +1,3 @@ +# gatsby-plugin-checker + +This script searches the npm API for plugins that start with either "gatsby-source", "gatsby-plugin", or "gatsby-transformer" but don't have the "gatsby-plugin" keyword in their `package.json` and thus are not included in Gatsby's keyword search. The script will then notify those repositories by creating an issue notifying them to add the keyword to their `package.json` (This functionality will be included in the next commit). Once a repo has been notified, its `notified` attribute will be changed to `true` in `plugins.json` and won't be notified. Similarly, if a repo is a false positive or doesn't want to be notified, it can be `blacklisted`. diff --git a/scripts/gatsby-plugin-checker/index.js b/scripts/gatsby-plugin-checker/index.js index c8bd5ba5767b7..b7aab8e1a5710 100644 --- a/scripts/gatsby-plugin-checker/index.js +++ b/scripts/gatsby-plugin-checker/index.js @@ -64,6 +64,60 @@ const filterNotNotified = (packages, plugins) => { return packages.filter(pkg => notified.indexOf(pkg.name) < 0) } +const removePackagesWithoutRepository = packages => + packages.filter(p => hasRepository(p)) + +const hasRepository = packageToCheck => { + if (packageToCheck.links.repository) { + return true + } + return false +} + +const removePackagesWithBadRepoLinks = async packages => { + let packagesWithValidRepoLinks = [] + for (let i = 0; i < packages.length; i++) { + const hasValidRepo = await hasValidRepository(packages[i]) + if (hasValidRepo) packagesWithValidRepoLinks.push(packages[i]) + } + return packagesWithValidRepoLinks +} + +const hasValidRepository = async packageToSearch => { + const response = got(packageToSearch.links.repository) + if (response.statusCode == 404) return false + return true +} + +const removeBadNameFormats = packages => packages.filter(p => hasGoodName(p)) + +const hasGoodName = pkg => { + const name = pkg.name + + if (name.indexOf(`/`) !== -1) { + const nameWithoutScope = name.split(`/`, 2)[1] + if (startsWithAllowedPrefix(nameWithoutScope)) return true + } else { + if (startsWithAllowedPrefix(name)) return true + } + return false +} + +const startsWithAllowedPrefix = name => { + let isGoodName = false + keywords.forEach(keyword => { + if (name.indexOf(keyword) === 0) isGoodName = true + }) + return isGoodName +} + +const removePackagesWithoutReadme = packages => + packages.filter(p => hasReadMe(p)) + +const hasReadMe = pkg => { + if (pkg.links.homepage || pkg.readme) return true + return false +} const updatePlugins = (updates, plugins) => { let res = plugins.map(p => Object.assign({}, p)) updates.forEach(u => { @@ -84,11 +138,16 @@ const main = () => { .then(transformResults) .then(packages => filterNotBlacklisted(packages, plugins)) .then(packages => filterNotNotified(packages, plugins)) + .then(packages => removePackagesWithoutRepository(packages)) + .then(packages => removePackagesWithBadRepoLinks(packages)) + .then(packages => removeBadNameFormats(packages)) + .then(packages => removePackagesWithoutReadme(packages)) .then(packages => packages.map(p => { // TODO: notify / comment on github console.info(`Notify package "${p.name}"`) // return update status + // will turn notified to true once notifications are created return { name: p.name, blacklist: false, notified: false } }) ) From 68598f726234ba1f2e953b62e0a8c281adcd880c Mon Sep 17 00:00:00 2001 From: Reese Williams Date: Mon, 25 Mar 2019 21:44:47 -0400 Subject: [PATCH 2/2] Clean up functions and remove unneeded checks. Add check to see if git repo has README. --- scripts/gatsby-plugin-checker/index.js | 56 ++++++++------------------ 1 file changed, 16 insertions(+), 40 deletions(-) diff --git a/scripts/gatsby-plugin-checker/index.js b/scripts/gatsby-plugin-checker/index.js index b7aab8e1a5710..47a5847ee7e09 100644 --- a/scripts/gatsby-plugin-checker/index.js +++ b/scripts/gatsby-plugin-checker/index.js @@ -65,59 +65,36 @@ const filterNotNotified = (packages, plugins) => { } const removePackagesWithoutRepository = packages => - packages.filter(p => hasRepository(p)) - -const hasRepository = packageToCheck => { - if (packageToCheck.links.repository) { - return true - } - return false -} - -const removePackagesWithBadRepoLinks = async packages => { - let packagesWithValidRepoLinks = [] - for (let i = 0; i < packages.length; i++) { - const hasValidRepo = await hasValidRepository(packages[i]) - if (hasValidRepo) packagesWithValidRepoLinks.push(packages[i]) - } - return packagesWithValidRepoLinks -} - -const hasValidRepository = async packageToSearch => { - const response = got(packageToSearch.links.repository) - if (response.statusCode == 404) return false - return true -} + packages.filter(pkg => !!pkg.links.repository) const removeBadNameFormats = packages => packages.filter(p => hasGoodName(p)) const hasGoodName = pkg => { const name = pkg.name - - if (name.indexOf(`/`) !== -1) { - const nameWithoutScope = name.split(`/`, 2)[1] - if (startsWithAllowedPrefix(nameWithoutScope)) return true - } else { - if (startsWithAllowedPrefix(name)) return true + const isScopedPackage = name.startsWith(`@`) + if (!isScopedPackage) { + return startsWithAllowedPrefix(name) } - return false -} -const startsWithAllowedPrefix = name => { - let isGoodName = false - keywords.forEach(keyword => { - if (name.indexOf(keyword) === 0) isGoodName = true - }) - return isGoodName + const nameWithoutScope = name.slice(0, name.indexOf(`/`)) + return startsWithAllowedPrefix(nameWithoutScope) } +const startsWithAllowedPrefix = name => + keywords.some(keyword => name.startsWith(keyword)) + const removePackagesWithoutReadme = packages => - packages.filter(p => hasReadMe(p)) + packages.filter(pkg => hasReadMe(pkg)) const hasReadMe = pkg => { if (pkg.links.homepage || pkg.readme) return true - return false + if (pkg.links.repository) { + return got(pkg.links.repository + `/blob/master/README.md`) + .then(response => response.statusCode === 200) + .catch(_ => false) + } else return false } + const updatePlugins = (updates, plugins) => { let res = plugins.map(p => Object.assign({}, p)) updates.forEach(u => { @@ -139,7 +116,6 @@ const main = () => { .then(packages => filterNotBlacklisted(packages, plugins)) .then(packages => filterNotNotified(packages, plugins)) .then(packages => removePackagesWithoutRepository(packages)) - .then(packages => removePackagesWithBadRepoLinks(packages)) .then(packages => removeBadNameFormats(packages)) .then(packages => removePackagesWithoutReadme(packages)) .then(packages =>