Skip to content

Commit 3586bb9

Browse files
authored
Merge pull request #199 from hashicorp/ds.ntp-skipcomment
2 parents 1966e2c + 0099913 commit 3586bb9

File tree

3 files changed

+19
-4
lines changed

3 files changed

+19
-4
lines changed

.changeset/moody-bags-design.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@hashicorp/platform-tools': minor
3+
---
4+
5+
Add support for skipCommentIfEmpty

packages/tools/scripts/next-touched-pages/__tests__/index.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ describe('next-touched-pages', () => {
66

77
it('generates a comment when changedPages is empty', async () => {
88
const { generateCommentMarkdown } = await import('../')
9-
expect(generateCommentMarkdown([], {})).toBe(`<h2>Changed Pages</h2>
9+
expect(generateCommentMarkdown([], {})).toBe(`<h2>📄 Changed Pages</h2>
1010
<br>
1111
This PR doesn't appear to affect any pages.<br>
1212
This comment was generated by <a href="https://github.com/hashicorp/web-platform-packages/tree/main/packages/tools/scripts/next-touched-pages"><code>next-touched-pages</code></a> and isn't guaranteed to be accurate.<br>
@@ -20,7 +20,7 @@ This comment was generated by <a href="https://github.com/hashicorp/web-platform
2020
baseBranch: 'main',
2121
branch: 'feature',
2222
})
23-
).toBe(`<h2>Changed Pages</h2>
23+
).toBe(`<h2>📄 Changed Pages</h2>
2424
<table><tr><th>Page</th><th><code>main</code></th><th><code>feature</code></th></tr><tr><td><code>/</code></td><td><li><code>/</code></li></td><td><li><code>/</code></li></td></tr></table>
2525
<br>
2626
This comment was generated by <a href="https://github.com/hashicorp/web-platform-packages/tree/main/packages/tools/scripts/next-touched-pages"><code>next-touched-pages</code></a> and isn't guaranteed to be accurate.<br>
@@ -39,7 +39,7 @@ This comment was generated by <a href="https://github.com/hashicorp/web-platform
3939
deployUrl: 'feature-test.example',
4040
baseBranchDeployUrl: 'main-test.example',
4141
})
42-
).toBe(`<h2>Changed Pages</h2>
42+
).toBe(`<h2>📄 Changed Pages</h2>
4343
<table><tr><th>Page</th><th><code>main</code></th><th><code>feature</code></th></tr><tr><td><code>/[page]</code></td><td><li><a href="https://main-test.example/one"><code>/[page]</code> #1</a></li><li><a href="https://main-test.example/two"><code>/[page]</code> #2</a></li></td><td><li><a href="https://feature-test.example/one"><code>/[page]</code> #1</a></li><li><a href="https://feature-test.example/two"><code>/[page]</code> #2</a></li></td></tr></table>
4444
<br>
4545
This comment was generated by <a href="https://github.com/hashicorp/web-platform-packages/tree/main/packages/tools/scripts/next-touched-pages"><code>next-touched-pages</code></a> and isn't guaranteed to be accurate.<br>

packages/tools/scripts/next-touched-pages/index.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ interface BuildManifest {
1818
interface Configuration {
1919
name?: string
2020
paths?: Record<string, string[]>
21+
skipCommentIfEmpty?: boolean
2122
}
2223

2324
const css = /\/\*+[\s\S]*?sourceMappingURL\s*=([\s\S]*?)\*\//
@@ -245,17 +246,25 @@ export function generateCommentMarkdown(
245246
deployUrl,
246247
dynamicPathsConfig,
247248
packageName,
249+
skipCommentIfEmpty,
248250
}: {
249251
baseBranch?: string
250252
baseBranchDeployUrl?: string
251253
branch?: string
252254
deployUrl?: string
253255
dynamicPathsConfig?: Record<string, string[]>
254256
packageName?: string
257+
skipCommentIfEmpty?: boolean
255258
}
256259
): string {
260+
// If there aren't any changed pages and skipCommentIfEmpty is truthy, return
261+
// an empty string.
262+
if (skipCommentIfEmpty && changedPages.length === 0) {
263+
return ''
264+
}
265+
257266
let comment = summary.addHeading(
258-
packageName ? `Changed Pages for ${packageName}` : 'Changed Pages',
267+
packageName ? `📄 Changed Pages for ${packageName}` : '📄 Changed Pages',
259268
2
260269
)
261270
if (changedPages.length > 0) {
@@ -400,6 +409,7 @@ export default async function main() {
400409
baseBranchDeployUrl: argv.baseBranchDeployUrl,
401410
dynamicPathsConfig: config.paths,
402411
packageName: config.name,
412+
skipCommentIfEmpty: config.skipCommentIfEmpty,
403413
})
404414
break
405415
}

0 commit comments

Comments
 (0)