-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Where available, use the GitHub organisation avatar as the image for …
…an extension
- Loading branch information
1 parent
c8e12bb
commit dc3de47
Showing
9 changed files
with
179 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
const defaultOptions = { | ||
nodeType: "extension", | ||
} | ||
|
||
exports.onCreateNode = async ({ node, getNode, actions }, pluginOptions) => { | ||
const { createNodeField } = actions | ||
|
||
const options = { | ||
...defaultOptions, | ||
...pluginOptions, | ||
} | ||
|
||
if (node.internal.type !== options.nodeType) { | ||
return | ||
} | ||
|
||
const { metadata } = node | ||
const scmUrl = metadata["scm-url"] | ||
|
||
if (scmUrl) { | ||
// We should do this properly with the API, but for now make an educated guess about the image URL | ||
// See https://stackoverflow.com/questions/22932422/get-github-avatar-from-email-or-name | ||
// remove everything after the last backslash | ||
const orgUrl = scmUrl.substr(0, scmUrl.lastIndexOf("/")) | ||
const logoUrl = orgUrl + ".png" | ||
const scmInfo = { url: scmUrl, logoUrl } | ||
|
||
createNodeField({ | ||
node, | ||
name: "sourceControlInfo", | ||
value: scmInfo, | ||
}) | ||
} | ||
} | ||
|
||
exports.createSchemaCustomization = ({ actions }) => { | ||
const { createTypes } = actions | ||
const typeDefs = ` | ||
type SourceControlInfo implements Node { | ||
url: String | ||
logo: String | ||
} | ||
` | ||
createTypes(typeDefs) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
const { onCreateNode } = require("./gatsby-node") | ||
|
||
// This test relies on a mock in __mocks__. To validate things against | ||
// the real implementation, rename __mocks__/node-geocoder.js to something else temporarily. | ||
|
||
const createNodeField = jest.fn(({ node, name, value }) => { | ||
if (!node.fields) { | ||
node.fields = {} | ||
} | ||
node.fields[name] = value | ||
}) | ||
const actions = { createNodeField } | ||
const internal = { type: "extension" } | ||
|
||
describe("the preprocessor", () => { | ||
describe("for an extension with no scm information", () => { | ||
const metadata = {} | ||
|
||
const node = { | ||
metadata, | ||
internal, | ||
} | ||
|
||
beforeAll(async () => { | ||
await onCreateNode({ node, actions }) | ||
}) | ||
|
||
afterAll(() => {}) | ||
|
||
it("changes nothing", async () => { | ||
expect(node.metadata).toEqual({}) | ||
expect(node.sourceControlInfo).toBeUndefined() | ||
}) | ||
}) | ||
|
||
describe("for an extension with a scm-url", () => { | ||
const url = "http://gitsomething.com/someuser/somerepo" | ||
const imageUrl = "http://gitsomething.com/someuser.png" | ||
const metadata = { | ||
"scm-url": url, | ||
} | ||
|
||
const node = { | ||
metadata, | ||
internal, | ||
} | ||
|
||
beforeAll(async () => { | ||
await onCreateNode({ node, actions }) | ||
}) | ||
|
||
afterAll(() => {}) | ||
|
||
it("creates an scm object", async () => { | ||
expect(node.fields.sourceControlInfo).toBeTruthy() | ||
}) | ||
|
||
it("copies across the url", async () => { | ||
expect(node.fields.sourceControlInfo.url).toEqual(url) | ||
}) | ||
|
||
it("fills in an image", async () => { | ||
expect(node.fields.sourceControlInfo.logoUrl).toEqual(imageUrl) | ||
}) | ||
|
||
xit("adds a node for the remote image", async () => {}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "github-enricher" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters