Skip to content

Commit

Permalink
Merge pull request #1563 from newrelic/alec/rename-to-quickstarts
Browse files Browse the repository at this point in the history
Quickstarts rename
  • Loading branch information
moonlight-komorebi authored Aug 30, 2021
2 parents bbf639c + 35977e2 commit 8f3c78b
Show file tree
Hide file tree
Showing 12 changed files with 474 additions and 1,233 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Fetch Observability Packs
name: Fetch Quickstarts

on:
workflow_dispatch:
Expand All @@ -11,7 +11,7 @@ env:
NODE_OPTIONS: '--max-old-space-size=4096'

jobs:
fetch-observability-packs:
fetch-quickstarts:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
Expand All @@ -35,8 +35,8 @@ jobs:
if: steps.yarn-cache.outputs.cache-hit != 'true'
run: yarn install --frozen-lockfile

- name: Fetch observability packs
run: yarn run fetch-observability-packs
- name: Fetch quickstarts
run: yarn run fetch-quickstarts
env:
NR_API_URL: 'https://api.newrelic.com/graphql'
NR_API_TOKEN: ${{ secrets.NR_API_TOKEN }}
Expand Down Expand Up @@ -64,8 +64,8 @@ jobs:
run: |
git config --local user.email "${{ env.BOT_EMAIL }}"
git config --local user.name "${{ env.BOT_NAME }}"
git add ./src/data/observability-packs.json
git diff-index --quiet HEAD ./src/data/observability-packs.json || git commit -m 'chore(observability-packs): updated observability packs'
git add ./src/data/quickstarts.json
git diff-index --quiet HEAD ./src/data/quickstarts.json || git commit -m 'chore(quickstarts): updated quickstarts'
echo "::set-output name=commit::true"
- name: Push Commit
Expand Down
8 changes: 4 additions & 4 deletions gatsby-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ module.exports = {
{
resolve: 'gatsby-source-filesystem',
options: {
name: 'observability-packs',
path: `${__dirname}/src/data/observability-packs.json`
}
name: 'quickstarts',
path: `${__dirname}/src/data/quickstarts.json`,
},
},
{
resolve: 'gatsby-transformer-json',
Expand All @@ -156,7 +156,7 @@ module.exports = {
// consider making this dynamic. See the docs for ways to do this.
//
// https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-json
typeName: 'ObservabilityPacks',
typeName: 'Quickstarts',
},
},
'gatsby-remark-images',
Expand Down
10 changes: 5 additions & 5 deletions gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
}
}
allObservabilityPacks {
allQuickstarts {
edges {
node {
fields {
Expand All @@ -76,7 +76,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
allMdx,
allNewRelicSdkComponent,
allNewRelicSdkApi,
allObservabilityPacks,
allQuickstarts,
} = result.data;

allMdx.edges.forEach(({ node }) => {
Expand Down Expand Up @@ -112,7 +112,7 @@ exports.createPages = async ({ actions, graphql, reporter }) => {
});
});

allObservabilityPacks.edges.forEach(({ node }) => {
allQuickstarts.edges.forEach(({ node }) => {
const {
fields: { slug },
id,
Expand Down Expand Up @@ -192,11 +192,11 @@ exports.onCreateNode = ({ node, getNode, actions }) => {
});
}

if (node.internal.type === 'ObservabilityPacks') {
if (node.internal.type === 'Quickstarts') {
createNodeField({
node,
name: 'slug',
value: `/observability-packs/${slugify(node.name)}/${node.id}`,
value: `/instant-observability/${slugify(node.name)}/${node.id}`,
});
}
};
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@
"build:production": "GATSBY_NEWRELIC_ENV=production gatsby build",
"build:staging": "GATSBY_NEWRELIC_ENV=staging gatsby build",
"build:related-content": "BUILD_RELATED_CONTENT=true yarn run build:production",
"fetch-observability-packs": "node ./scripts/actions/fetch-observability-packs.js",
"fetch-quickstarts": "node ./scripts/actions/fetch-quickstarts.js",
"develop": "gatsby develop",
"format": "prettier --write \"**/*.{js,jsx,json,md}\"",
"start": "yarn run develop",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const fs = require('fs');
const fetch = require('node-fetch');
const fetchObservabilityPacks = require('../fetch-observability-packs');
const fetchQuickstarts = require('../fetch-quickstarts');

jest.mock('node-fetch');
jest.mock('fs');
Expand All @@ -15,103 +15,107 @@ describe('Action: Fetch Observability Packs', () => {
afterEach(() => {
jest.resetAllMocks();
});

test('writes observability packs to file', async () => {
const apiReturnValue = {
data: {
docs: {
openInstallation: {
observabilityPackSearch: {
quickstartSearch: {
results: {
observabilityPacks: [
quickstarts: [
{
test: 'test'
}
]
}
}
}
}
}
test: 'test',
},
],
},
},
},
},
},
};
fetch.mockResolvedValueOnce({
ok: true,
json: jest.fn(() => Promise.resolve(apiReturnValue))
json: jest.fn(() => Promise.resolve(apiReturnValue)),
});

await fetchObservabilityPacks(fakeGqlQuery, fakeAPIURL, fakeToken);
await fetchQuickstarts(fakeGqlQuery, fakeAPIURL, fakeToken);
expect(fs.writeFileSync.mock.calls.length).toBe(1);
expect(fs.writeFileSync.mock.calls[0][0]).toStrictEqual('./src/data/observability-packs.json');
expect(fs.writeFileSync.mock.calls[0][1]).toStrictEqual(JSON.stringify([{ test: 'test' }], null, 2));
expect(fs.writeFileSync.mock.calls[0][0]).toStrictEqual(
'./src/data/quickstarts.json'
);
expect(fs.writeFileSync.mock.calls[0][1]).toStrictEqual(
JSON.stringify([{ test: 'test' }], null, 2)
);
});

test('does not write file when graphql errors are returned', async () => {
const apiReturnValue = {
const apiReturnValue = {
errors: {
testError: 'error'
testError: 'error',
},
data: {
docs: {
openInstallation: {
observabilityPackSearch: {
quickstartSearch: {
results: {
observabilityPacks: [
quickstarts: [
{
test: 'test'
}
]
}
}
}
}
}
test: 'test',
},
],
},
},
},
},
},
};
fetch.mockResolvedValueOnce({
json: jest.fn(() => Promise.resolve(apiReturnValue)),
ok: true
ok: true,
});

await fetchObservabilityPacks(fakeGqlQuery, fakeAPIURL, fakeToken);
await fetchQuickstarts(fakeGqlQuery, fakeAPIURL, fakeToken);
expect(fs.writeFileSync).not.toHaveBeenCalled();
});

test('does not write file when graphql response is malformed', async () => {
const apiReturnValue = {
data: {
const apiReturnValue = {
data: {
docs: {
observabilityPackSearch: {
quickstartSearch: {
results: {
observabilityPacks: [
quickstarts: [
{
test: 'test'
}
]
}
}
}
}
test: 'test',
},
],
},
},
},
},
};
fetch.mockResolvedValueOnce({
json: jest.fn(() => Promise.resolve(apiReturnValue)),
ok: true
ok: true,
});

await fetchObservabilityPacks(fakeGqlQuery, fakeAPIURL, fakeToken);
await fetchQuickstarts(fakeGqlQuery, fakeAPIURL, fakeToken);
expect(fs.writeFileSync).not.toHaveBeenCalled();
});

test('does not write file when a network error occurs', async () => {
fetch.mockImplementation(() => Promise.reject());
await fetchObservabilityPacks(fakeGqlQuery, fakeAPIURL, fakeToken);
await fetchQuickstarts(fakeGqlQuery, fakeAPIURL, fakeToken);
expect(fs.writeFileSync).not.toHaveBeenCalled();
});

test('does not write file when a non-200 status is returned from the API', async () => {
fetch.mockResolvedValueOnce({
status: 500,
ok: false
ok: false,
});
await fetchObservabilityPacks(fakeGqlQuery, fakeAPIURL, fakeToken);
await fetchQuickstarts(fakeGqlQuery, fakeAPIURL, fakeToken);
expect(fs.writeFileSync).not.toHaveBeenCalled();
});
});
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

/**
* This script is used to query the New Relic GraphQL API for Observability Packs.
* It then writes the array of Observability Packs to src/data/observability-packs.json
* This script is used to query the New Relic GraphQL API for Quickstarts.
* It then writes the array of Quickstarts to src/data/quickstarts.json
* It requires the following environment variables to be set:
* NR_GQL_URL - The New Relic GraphQL URL
* NR_API_TOKEN - A New Relic personal API token
Expand All @@ -13,18 +13,18 @@ const fs = require('fs');
const fetch = require('node-fetch');
const get = require('lodash.get');

const PACKS_FILE_PATH = './src/data/observability-packs.json';
const QUICKSTARTS_FILE_PATH = './src/data/quickstarts.json';
const NR_API_URL = process.env.NR_API_URL;
const NR_API_TOKEN = process.env.NR_API_TOKEN;

const packQuery = `# gql
const quickstartQuery = `# gql
{
docs {
openInstallation {
observabilityPackSearch {
quickstartSearch {
count
results {
observabilityPacks {
quickstarts {
authors
dashboards {
description
Expand Down Expand Up @@ -67,7 +67,7 @@ const packQuery = `# gql
* @returns {Promise<Object[]|undefined>} returns the resulting array
* or `undefined` if there was an error
**/
const fetchPacks = async (queryString, url, token) => {
const fetchQuickstarts = async (queryString, url, token) => {
try {
const res = await fetch(url, {
method: 'post',
Expand All @@ -88,10 +88,7 @@ const fetchPacks = async (queryString, url, token) => {
throw new Error(JSON.stringify(results.errors, null, 2));
}

return get(
results,
'data.docs.openInstallation.observabilityPackSearch.results'
);
return get(results, 'data.docs.openInstallation.quickstartSearch.results');
} catch (error) {
console.error('Encountered a problem querying the graphql api', error);
}
Expand All @@ -108,21 +105,21 @@ const validateEnvVars = () => {
};

/*
* @param {String} query a graphql query for observability packs
* @param {String} query a graphql query for quickstarts
* @param {String} url the New Relic API endpoint
* @param {String} token a New Relic API token
**/
const main = async (query, url, token) => {
const results = await fetchPacks(query, url, token);
const results = await fetchQuickstarts(query, url, token);

if (results) {
const packs = results.observabilityPacks;
console.log(`Found ${packs.length} packs.`);
console.log(`Writing ${PACKS_FILE_PATH}`);
fs.writeFileSync(PACKS_FILE_PATH, JSON.stringify(packs, null, 2));
const quickstarts = results.quickstarts;
console.log(`Found ${quickstarts.length} quickstarts.`);
console.log(`Writing ${QUICKSTARTS_FILE_PATH}`);
fs.writeFileSync(QUICKSTARTS_FILE_PATH, JSON.stringify(quickstarts, null, 2));
} else {
console.log(
'No packs were returned from the api, check the logs for errors.'
'No quickstarts were returned from the api, check the logs for errors.'
);
if (require.main === module) {
process.exit(1);
Expand All @@ -132,7 +129,7 @@ const main = async (query, url, token) => {

if (require.main === module) {
validateEnvVars();
main(packQuery, NR_API_URL, NR_API_TOKEN);
main(quickstartQuery, NR_API_URL, NR_API_TOKEN);
}

module.exports = main;
Expand Down
2 changes: 1 addition & 1 deletion src/components/InstallButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const InstallButton = ({ quickstart, ...props }) => {

return (
<Button {...props} as={Link} to={url} variant={Button.VARIANT.PRIMARY}>
{hasInstallableComponent ? 'Install Pack' : 'See installation docs'}
{hasInstallableComponent ? 'Install quickstart' : 'See installation docs'}
</Button>
);
};
Expand Down
6 changes: 3 additions & 3 deletions src/components/quickstarts/EmptyTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ const EmptyTab = ({
name="edit"
/>
<p>
This pack doesn't include any {tabName}. Do you think it should?
This quickstart doesn't include any {tabName}. Do you think it should?
<br />
You can edit this pack to add helpful components. View the repository and
open a pull request.
You can edit this quickstart to add helpful components. View the
repository and open a pull request.
</p>
<div
css={css`
Expand Down
4 changes: 2 additions & 2 deletions src/data/nav.yml
Original file line number Diff line number Diff line change
Expand Up @@ -441,9 +441,9 @@
url: '/nerd-days'
- title: All things open
url: '/all-things-open'
- title: Observability packs
- title: Instant Observability
icon: box
url: '/observability-packs'
url: '/instant-observability'
- title: Nerd Bytes
icon: nr-nerd-bytes
url: '/nerd-bytes'
Expand Down
Loading

0 comments on commit 8f3c78b

Please sign in to comment.