Skip to content

Commit

Permalink
Do not consider urls that redirect to /pulls as valid when working ou…
Browse files Browse the repository at this point in the history
…t issues url
  • Loading branch information
holly-cummins committed Jun 9, 2024
1 parent 86fa533 commit c369ef0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 10 deletions.
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"date-fns": "^3.6.0",
"encodeurl": "^2.0.0",
"eslint-plugin-gatsby": "^1.0.2",
"follow-redirect-url": "^2.0.1",
"gatsby": "^4.25.8",
"gatsby-plugin-feed": "^4.25.0",
"gatsby-plugin-force-file-loader": "^4.0.2",
Expand Down
39 changes: 29 additions & 10 deletions plugins/github-enricher/gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const followRedirect = require("follow-redirect-url")

const gh = require("parse-github-url")
const path = require("path")
const encodeUrl = require("encodeurl")
Expand Down Expand Up @@ -275,11 +277,14 @@ const fetchGitHubInfo = async (scmUrl, groupId, artifactId, labels) => {
const coords = gh(scmUrl)
const project = coords.name

const { issuesUrl, issues } = await getIssueInformation(coords, labels, scmUrl)
const scmInfo = { labels }

const scmInfo = { issuesUrl, issues }
const { issuesUrl, issues } = await getIssueInformation(coords, labels, scmUrl)

scmInfo.labels = labels
if (issuesUrl) {
scmInfo.issuesUrl = issuesUrl
scmInfo.issues = issues
}

const imageInfo = await getImageInformation(coords, scmUrl)

Expand Down Expand Up @@ -696,22 +701,36 @@ const getIssueInformationNoCache = async (coords, labels, scmUrl) => {
// The parent objects may be undefined and destructuring nested undefineds is not good
const issues = body?.data?.repository?.issues?.totalCount

// If we got an issue count we can be pretty confident our url will be ok, but otherwise, it might not be,
// so check it. We don't check for every url because otherwise we start getting 429s and dropping good URLs
if (!issues) {
issuesUrl = await maybeIssuesUrl(issues, issuesUrl)

return { issues, issuesUrl }
}

const maybeIssuesUrl = async (issues, issuesUrl) => {
if (issues) {
return issuesUrl
} else {
// If we got an issue count we can be pretty confident our url will be ok, but otherwise, it might not be,
// so check it. We don't check for every url because otherwise we start getting 429s and dropping good URLs
// We have to access the url exist as a dynamic import (because CJS), await it because dynamic imports give a promise, and then destructure it to get the default
// A simple property read won't work
const {
default: urlExist,
} = await import("url-exist")

const isValidUrl = await urlExist(issuesUrl)
if (!isValidUrl) {
issuesUrl = undefined
}

let isOriginalUrl = isValidUrl && await isNotRedirectToPulls(issuesUrl)

return isOriginalUrl ? issuesUrl : undefined
}
}

return { issues, issuesUrl }
const isNotRedirectToPulls = async (issuesUrl) => {
// Being a valid url may not be enough, we also want to check for redirects to /pulls
const urls = await followRedirect.startFollowing(issuesUrl)
const finalUrl = urls[urls.length - 1]
return !(finalUrl.url.includes("/pulls"))
}

// This combines the sponsor opt-in information (which we only fully have after processing all nodes) with the companies and sponsor information for individual nodes,
Expand Down

0 comments on commit c369ef0

Please sign in to comment.