Skip to content

Commit

Permalink
scripts/update-integrations.mjs: wrong homepage criteria
Browse files Browse the repository at this point in the history
A homepage url is considered as wrong when:
- the response is greater than 400
- or it does not respond

Signed-off-by: Pascal Brand <[email protected]>
  • Loading branch information
pascal-brand38 committed Nov 6, 2024
1 parent 97bb965 commit 5050c57
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions scripts/update-integrations.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,16 @@ async function unsafeUpdateAllIntegrations() {

// check if the homepageurl is valid
// if not, replace it by the link to the package on npm
let fixHomepageUrl = false
try {
const response = await fetch(details.homepageUrl, { method: 'HEAD'})
if (response.status === 404) {
details.homepageUrl = `https://www.npmjs.com/package/${data.name}`
}
fixHomepageUrl = (response.status >= 400)
} catch (error) {
// such an error may occur when the hostname is unknown
// we consider it ok at this may come from a down server
console.info(`Package ${details.name}: Cannot access ${details.homepageUrl} (not fixed)`)
fixHomepageUrl = true
}
if (fixHomepageUrl) {
details.homepageUrl = `https://www.npmjs.com/package/${data.name}`
}

const frontmatter = yaml.stringify({
Expand Down Expand Up @@ -237,7 +238,8 @@ ${frontmatter}---\n`,

const args = process.argv.slice(2);

// only fetch unsafe changes like new and deprecated integrations, and fix 404 homepageurl
// only fetch unsafe changes like new and deprecated integrations,
// and fix wrong homepageurl (response>=400 or not responding)
// if the --unsafe CLI flag was provided
if (args.includes('--unsafe')) {
await unsafeUpdateAllIntegrations();
Expand Down

0 comments on commit 5050c57

Please sign in to comment.