Skip to content

Commit 1af1180

Browse files
authoredMar 2, 2020
fix(www): fallback to github renamed owner (starters) (#21858)
* fix(www): fallback to github renamed owner (starters) * Revert "Remove crashing starter (#21801)" This reverts commit 5938f0d.
1 parent 5b523bd commit 1af1180

File tree

2 files changed

+54
-16
lines changed

2 files changed

+54
-16
lines changed
 

‎docs/starters.yml

+12
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
- MDX
3535
- MaterialUI Components
3636
- React Icons
37+
- url: https://authenticaysh.netlify.com/
38+
repo: https://github.com/ben-siewert/gatsby-starter-auth-aws-amplify
39+
description: Full-featured Auth with AWS Amplify & AWS Cognito
40+
tags:
41+
- AWS
42+
- Authentication
43+
features:
44+
- Full-featured AWS Authentication with Cognito
45+
- Error feedback in forms
46+
- Password Reset
47+
- Multi-Factor Authentication
48+
- Styling with Bootstrap and Sass
3749
- url: https://gatsby-starter-blog-demo.netlify.com/
3850
repo: https://github.com/gatsbyjs/gatsby-starter-blog
3951
description: official blog

‎www/src/utils/node/starters.js

+42-16
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,47 @@ exports.createPages = async ({ graphql, actions, reporter }) => {
7979
})
8080
}
8181

82+
const fetchGithubData = async ({ owner, repo, reporter }, retry = 0) => {
83+
return githubApiClient
84+
.request(
85+
`
86+
query {
87+
repository(owner:"${owner}", name:"${repo}") {
88+
name
89+
stargazers {
90+
totalCount
91+
}
92+
createdAt
93+
pushedAt
94+
owner {
95+
login
96+
}
97+
nameWithOwner
98+
}
99+
}
100+
`
101+
)
102+
.catch(async err => {
103+
// we only try to do a fetch once because we want to track the new owner's username.
104+
if (retry > 0) {
105+
throw err
106+
}
107+
108+
const githubUrl = `https://github.com/${owner}/${repo}`
109+
const { url } = await fetch(githubUrl, { method: "HEAD" })
110+
const { owner: newOwner, name: newRepo } = parseGHUrl(url)
111+
112+
reporter.warn(
113+
`Starter showcase entry "${owner}/${repo}" was renamed to "${newOwner}/${newRepo}". Retrying....`
114+
)
115+
116+
return fetchGithubData(
117+
{ owner: newOwner, repo: newRepo, reporter },
118+
retry + 1
119+
)
120+
})
121+
}
122+
82123
exports.onCreateNode = ({ node, actions, getNode, reporter }) => {
83124
const { createNodeField } = actions
84125
if (node.internal.type === `StartersYaml` && node.repo) {
@@ -125,22 +166,7 @@ exports.onCreateNode = ({ node, actions, getNode, reporter }) => {
125166
} else {
126167
return Promise.all([
127168
getpkgjson(node.repo),
128-
githubApiClient.request(`
129-
query {
130-
repository(owner:"${owner}", name:"${repoStub}") {
131-
name
132-
stargazers {
133-
totalCount
134-
}
135-
createdAt
136-
pushedAt
137-
owner {
138-
login
139-
}
140-
nameWithOwner
141-
}
142-
}
143-
`),
169+
fetchGithubData({ owner, repo: repoStub, reporter }),
144170
])
145171
.then(results => {
146172
const [pkgjson, githubData] = results

0 commit comments

Comments
 (0)
Please sign in to comment.