Skip to content

Commit

Permalink
feat: separate github repo info from contributors (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
icaraps authored Aug 14, 2020
1 parent 62dcf37 commit e2fc99e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,21 @@ plugins: [
GraphQL
```
{
allGithub {
nodes {
repository
branch
root
}
}
allGithubContributors {
nodes {
contributors {
date
login
name
}
path,
href
path
}
}
}
Expand Down
14 changes: 13 additions & 1 deletion gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,25 @@ exports.sourceNodes = async ({ actions, createNodeId, createContentDigest }, opt
}
})

const repository = `${owner}/${name}`

actions.createNode({
repository,
branch,
root,
id: createNodeId(repository),
internal: {
type: 'Github',
contentDigest: createContentDigest(repository)
}
})

for (const _path of paths) {
const githubPath = path.join(root, _path.replace(process.cwd(), ''))
const contributors = await githubFetchContributorsForPage(owner, name, branch, githubPath, token)
actions.createNode({
contributors,
path: _path,
href: `https://github.com/${owner}/${name}`,
id: createNodeId(_path),
internal: {
type: 'GithubContributors',
Expand Down
7 changes: 3 additions & 4 deletions test/gatsby-node.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,20 @@ test('sourceNodes', async () => {
.mockResolvedValueOnce(contributors[1])

await expect(gatsbyNode.sourceNodes(gatsbyHelpers, options)).resolves.toEqual(undefined)
expect(gatsbyHelpers.actions.createNode).toHaveBeenCalledTimes(pages.length)
expect(gatsbyHelpers.actions.createNode).toHaveBeenCalledTimes(pages.length + 1)
expect(mockGithubFetchContributors).toHaveBeenCalledTimes(pages.length)

options.root = 'my-root' // coverage
mockGlobby.mockResolvedValueOnce([])
await expect(gatsbyNode.sourceNodes(gatsbyHelpers, options)).resolves.toEqual(undefined)
expect(gatsbyHelpers.actions.createNode).toHaveBeenCalledTimes(pages.length)
expect(gatsbyHelpers.actions.createNode).toHaveBeenCalledTimes(pages.length + 2)
expect(mockGithubFetchContributors).toHaveBeenCalledTimes(pages.length)

pages.forEach((page, index) => {
const { owner, name, branch, token } = options.repo
expect(mockGithubFetchContributors).toHaveBeenNthCalledWith(index + 1, owner, name, branch, page, token)
expect(gatsbyHelpers.actions.createNode).toHaveBeenNthCalledWith(index + 1, expect.objectContaining({
expect(gatsbyHelpers.actions.createNode).toHaveBeenNthCalledWith(index + 2, expect.objectContaining({
contributors: contributors[index],
href: `https://github.com/${owner}/${name}`,
internal: expect.objectContaining({
type: 'GithubContributors'
})
Expand Down

0 comments on commit e2fc99e

Please sign in to comment.