Skip to content

Commit

Permalink
fix(www): fallback to github renamed owner (starters) (#21858)
Browse files Browse the repository at this point in the history
* fix(www): fallback to github renamed owner (starters)

* Revert "Remove crashing starter (#21801)"

This reverts commit 5938f0d.
  • Loading branch information
wardpeet committed Mar 2, 2020
1 parent 5b523bd commit 1af1180
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
12 changes: 12 additions & 0 deletions docs/starters.yml
Expand Up @@ -34,6 +34,18 @@
- MDX
- MaterialUI Components
- React Icons
- url: https://authenticaysh.netlify.com/
repo: https://github.com/ben-siewert/gatsby-starter-auth-aws-amplify
description: Full-featured Auth with AWS Amplify & AWS Cognito
tags:
- AWS
- Authentication
features:
- Full-featured AWS Authentication with Cognito
- Error feedback in forms
- Password Reset
- Multi-Factor Authentication
- Styling with Bootstrap and Sass
- url: https://gatsby-starter-blog-demo.netlify.com/
repo: https://github.com/gatsbyjs/gatsby-starter-blog
description: official blog
Expand Down
58 changes: 42 additions & 16 deletions www/src/utils/node/starters.js
Expand Up @@ -79,6 +79,47 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
})
}

const fetchGithubData = async ({ owner, repo, reporter }, retry = 0) => {
return githubApiClient
.request(
`
query {
repository(owner:"${owner}", name:"${repo}") {
name
stargazers {
totalCount
}
createdAt
pushedAt
owner {
login
}
nameWithOwner
}
}
`
)
.catch(async err => {
// we only try to do a fetch once because we want to track the new owner's username.
if (retry > 0) {
throw err
}

const githubUrl = `https://github.com/${owner}/${repo}`
const { url } = await fetch(githubUrl, { method: "HEAD" })
const { owner: newOwner, name: newRepo } = parseGHUrl(url)

reporter.warn(
`Starter showcase entry "${owner}/${repo}" was renamed to "${newOwner}/${newRepo}". Retrying....`
)

return fetchGithubData(
{ owner: newOwner, repo: newRepo, reporter },
retry + 1
)
})
}

exports.onCreateNode = ({ node, actions, getNode, reporter }) => {
const { createNodeField } = actions
if (node.internal.type === `StartersYaml` && node.repo) {
Expand Down Expand Up @@ -125,22 +166,7 @@ exports.onCreateNode = ({ node, actions, getNode, reporter }) => {
} else {
return Promise.all([
getpkgjson(node.repo),
githubApiClient.request(`
query {
repository(owner:"${owner}", name:"${repoStub}") {
name
stargazers {
totalCount
}
createdAt
pushedAt
owner {
login
}
nameWithOwner
}
}
`),
fetchGithubData({ owner, repo: repoStub, reporter }),
])
.then(results => {
const [pkgjson, githubData] = results
Expand Down

0 comments on commit 1af1180

Please sign in to comment.