Skip to content

Commit

Permalink
ci: Updated bin/create-docs-pr to create an empty array if changelo…
Browse files Browse the repository at this point in the history
…g.json is missing security (#2348)
  • Loading branch information
bizob2828 committed Jul 12, 2024
1 parent b3f1ee3 commit 7d5368c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 4 deletions.
6 changes: 3 additions & 3 deletions bin/create-docs-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,9 @@ async function getFrontMatter(tagName, frontMatterFile) {
}

return {
security: JSON.stringify(frontmatter.changes.security),
bugfixes: JSON.stringify(frontmatter.changes.bugfixes),
features: JSON.stringify(frontmatter.changes.features)
security: JSON.stringify(frontmatter.changes.security || []),
bugfixes: JSON.stringify(frontmatter.changes.bugfixes || []),
features: JSON.stringify(frontmatter.changes.features || [])
}
}

Expand Down
24 changes: 24 additions & 0 deletions bin/test/create-docs-pr.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ tap.test('Create Docs PR script', (testHarness) => {
t.test('should throw an error if there is no frontmatter', async (t) => {
mockFs.readFile.yields(null, JSON.stringify({ entries: [{ version: '1.2.3', changes: [] }] }))

// eslint-disable-next-line sonarjs/no-duplicate-string
const func = () => script.getFrontMatter('v2.0.0', 'changelog.json')
t.rejects(func, 'Unable to find 2.0.0 entry in changelog.json')

Expand Down Expand Up @@ -106,6 +107,29 @@ tap.test('Create Docs PR script', (testHarness) => {
})
t.end()
})

t.test('should return empty arrays if missing changes', async (t) => {
mockFs.readFile.yields(
null,
JSON.stringify({
entries: [
{
version: '2.0.0',
changes: {}
}
]
})
)

const result = await script.getFrontMatter('v2.0.0', 'changelog.json')

t.same(result, {
security: '[]',
bugfixes: '[]',
features: '[]'
})
t.end()
})
})

testHarness.test('formatReleaseNotes', (t) => {
Expand Down
3 changes: 2 additions & 1 deletion changelog.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"version": "11.23.0",
"changes": {
"security": [],
"bugfixes": [],
"features": [
"Added support for account level governance of AI Monitoring"
]
Expand Down Expand Up @@ -514,4 +515,4 @@
}
}
]
}
}

0 comments on commit 7d5368c

Please sign in to comment.