|
| 1 | +const followRedirect = require("follow-redirect-url") |
| 2 | + |
1 | 3 | const gh = require("parse-github-url") |
2 | 4 | const path = require("path") |
3 | 5 | const encodeUrl = require("encodeurl") |
@@ -275,11 +277,14 @@ const fetchGitHubInfo = async (scmUrl, groupId, artifactId, labels) => { |
275 | 277 | const coords = gh(scmUrl) |
276 | 278 | const project = coords.name |
277 | 279 |
|
278 | | - const { issuesUrl, issues } = await getIssueInformation(coords, labels, scmUrl) |
| 280 | + const scmInfo = { labels } |
279 | 281 |
|
280 | | - const scmInfo = { issuesUrl, issues } |
| 282 | + const { issuesUrl, issues } = await getIssueInformation(coords, labels, scmUrl) |
281 | 283 |
|
282 | | - scmInfo.labels = labels |
| 284 | + if (issuesUrl) { |
| 285 | + scmInfo.issuesUrl = issuesUrl |
| 286 | + scmInfo.issues = issues |
| 287 | + } |
283 | 288 |
|
284 | 289 | const imageInfo = await getImageInformation(coords, scmUrl) |
285 | 290 |
|
@@ -696,22 +701,36 @@ const getIssueInformationNoCache = async (coords, labels, scmUrl) => { |
696 | 701 | // The parent objects may be undefined and destructuring nested undefineds is not good |
697 | 702 | const issues = body?.data?.repository?.issues?.totalCount |
698 | 703 |
|
699 | | - // If we got an issue count we can be pretty confident our url will be ok, but otherwise, it might not be, |
700 | | - // so check it. We don't check for every url because otherwise we start getting 429s and dropping good URLs |
701 | | - if (!issues) { |
| 704 | + issuesUrl = await maybeIssuesUrl(issues, issuesUrl) |
| 705 | + |
| 706 | + return { issues, issuesUrl } |
| 707 | +} |
| 708 | + |
| 709 | +const maybeIssuesUrl = async (issues, issuesUrl) => { |
| 710 | + if (issues) { |
| 711 | + return issuesUrl |
| 712 | + } else { |
| 713 | + // If we got an issue count we can be pretty confident our url will be ok, but otherwise, it might not be, |
| 714 | + // so check it. We don't check for every url because otherwise we start getting 429s and dropping good URLs |
702 | 715 | // 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 |
703 | 716 | // A simple property read won't work |
704 | 717 | const { |
705 | 718 | default: urlExist, |
706 | 719 | } = await import("url-exist") |
707 | 720 |
|
708 | 721 | const isValidUrl = await urlExist(issuesUrl) |
709 | | - if (!isValidUrl) { |
710 | | - issuesUrl = undefined |
711 | | - } |
| 722 | + |
| 723 | + let isOriginalUrl = isValidUrl && await isNotRedirectToPulls(issuesUrl) |
| 724 | + |
| 725 | + return isOriginalUrl ? issuesUrl : undefined |
712 | 726 | } |
| 727 | +} |
713 | 728 |
|
714 | | - return { issues, issuesUrl } |
| 729 | +const isNotRedirectToPulls = async (issuesUrl) => { |
| 730 | + // Being a valid url may not be enough, we also want to check for redirects to /pulls |
| 731 | + const urls = await followRedirect.startFollowing(issuesUrl) |
| 732 | + const finalUrl = urls[urls.length - 1] |
| 733 | + return !(finalUrl.url.includes("/pulls")) |
715 | 734 | } |
716 | 735 |
|
717 | 736 | // 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, |
|
0 commit comments