Skip to content

Commit

Permalink
DOP-3756: update S3 bucket for Changelog to prod (#832)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmeigs authored Jun 12, 2023
1 parent 0734a74 commit b8227bb
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 18 deletions.
20 changes: 8 additions & 12 deletions gatsby-node.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const yaml = require('js-yaml');
const path = require('path');
const { transformBreadcrumbs } = require('./src/utils/setup/transform-breadcrumbs.js');
const { baseUrl } = require('./src/utils/base-url');
Expand Down Expand Up @@ -76,14 +75,13 @@ const createRemoteMetadataNode = async ({ createNode, createNodeId, createConten
}
};

const atlasAdminChangelogS3Prefix = 'https://mms-openapi-poc.s3.eu-west-1.amazonaws.com/openapi';
const atlasAdminChangelogS3Prefix = 'https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/changelog';

const fetchChangelogData = async (runId, versions) => {
try {
/* Using metadata runId, fetch OpenAPI Changelog full change list */
const changelogResp = await fetch(`${atlasAdminChangelogS3Prefix}/${runId}/changelog.yaml`);
const changelogText = await changelogResp.text();
const changelog = yaml.safeLoad(changelogText, 'utf8');
const changelogResp = await fetch(`${atlasAdminChangelogS3Prefix}/${runId}/changelog.json`);
const changelog = await changelogResp.json();

/* Aggregate all Resources in changelog for frontend filter */
const resourcesListSet = new Set();
Expand All @@ -95,9 +93,8 @@ const fetchChangelogData = async (runId, versions) => {
/* Fetch most recent Resource Versions' diff */
const mostRecentResourceVersions = versions.slice(-2);
const mostRecentDiffLabel = mostRecentResourceVersions.join('_');
const mostRecentDiffResp = await fetch(`${atlasAdminChangelogS3Prefix}/${runId}/${mostRecentDiffLabel}.yaml`);
const mostRecentDiffText = await mostRecentDiffResp.text();
const mostRecentDiffData = yaml.safeLoad(mostRecentDiffText, 'utf8');
const mostRecentDiffResp = await fetch(`${atlasAdminChangelogS3Prefix}/${runId}/${mostRecentDiffLabel}.json`);
const mostRecentDiffData = await mostRecentDiffResp.json();

return {
changelog,
Expand All @@ -117,14 +114,13 @@ const fetchChangelogData = async (runId, versions) => {
const createOpenAPIChangelogNode = async ({ createNode, createNodeId, createContentDigest }) => {
try {
/* Fetch OpenAPI Changelog metadata */
const indexResp = await fetch(`${atlasAdminChangelogS3Prefix}/index.yaml`);
const indexText = await indexResp.text();
const index = yaml.safeLoad(indexText, 'utf8');
const indexResp = await fetch(`${atlasAdminChangelogS3Prefix}/prod.json`);
const index = await indexResp.json();

const { runId, versions } = index;

if (!runId || typeof runId !== 'string')
throw new Error('OpenAPI Changelog Error: `runId` not available in S3 index.yaml!');
throw new Error('OpenAPI Changelog Error: `runId` not available in S3 index.json!');

let changelogData = {
index,
Expand Down
2 changes: 1 addition & 1 deletion src/components/OpenAPIChangelog/OpenAPIChangelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ const OpenAPIChangelog = () => {
<Body>(2.0{!!index.specRevisionShort && `~${index.specRevisionShort}`})</Body>
</Title>
<DownloadButton href={downloadChangelogUrl} disabled={!index.runId}>
Download API Changelog
Download Full API Changelog
</DownloadButton>
</ChangelogHeader>
<FiltersPanel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,11 @@ const ResourceChangesBlock = ({ path, httpMethod, operationId, tag, changes, ver
const { openapi_pages } = useSnootyMetadata();
const resourceLinkUrl = getResourceLinkUrl(metadata, tag, operationId, openapi_pages);

const allResourceChanges = changes || versions.map((version) => version.changes.map((change) => change)).flat();
const allResourceChanges =
changes || versions.map((version) => (version.changes ? version.changes.map((change) => change) : null)).flat();
/* Filter out all null changes or non-public-facing changes */
const publicResourceChanges = allResourceChanges.filter(
(c) => c.changeCode !== 'operation-id-changed' || c.changeCode !== 'operation-tag-changed'
(c) => c && (c.changeCode !== 'operation-id-changed' || c.changeCode !== 'operation-tag-changed')
);
const changeTypeBadge = versions?.[0]?.changeType ? changeTypeBadges[versions[0].changeType] : null;

Expand Down
2 changes: 1 addition & 1 deletion src/components/OpenAPIChangelog/utils/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export const ALL_VERSIONS = 'ALL_VERSIONS';
export const COMPARE_VERSIONS = 'COMPARE_VERSIONS';

export const getDownloadChangelogUrl = (runId) =>
`https://mms-openapi-poc.s3.eu-west-1.amazonaws.com/openapi/${runId}/changelog.yaml`;
`https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/changelog/${runId}/changelog.json`;

export const changeTypeBadges = {
release: {
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/__snapshots__/OpenAPIChangelog.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -855,15 +855,15 @@ exports[`OpenAPIChangelog tests OpenAPIChangelog renders correctly 1`] = `
aria-disabled="false"
class="emotion-8 emotion-9 emotion-10"
data-leafygreen-ui="button"
href="https://mms-openapi-poc.s3.eu-west-1.amazonaws.com/openapi/20230403105948111/changelog.yaml"
href="https://mongodb-mms-prod-build-server.s3.amazonaws.com/openapi/changelog/20230403105948111/changelog.json"
>
<div
class="emotion-11"
/>
<div
class="emotion-12"
>
Download API Changelog
Download Full API Changelog
</div>
</a>
</div>
Expand Down

0 comments on commit b8227bb

Please sign in to comment.