Skip to content

Commit

Permalink
Merge 0099913 into 1966e2c
Browse files Browse the repository at this point in the history
  • Loading branch information
dstaley authored Apr 7, 2023
2 parents 1966e2c + 0099913 commit cc0dc4e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/moody-bags-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@hashicorp/platform-tools': minor
---

Add support for skipCommentIfEmpty
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ describe('next-touched-pages', () => {

it('generates a comment when changedPages is empty', async () => {
const { generateCommentMarkdown } = await import('../')
expect(generateCommentMarkdown([], {})).toBe(`<h2>Changed Pages</h2>
expect(generateCommentMarkdown([], {})).toBe(`<h2>📄 Changed Pages</h2>
<br>
This PR doesn't appear to affect any pages.<br>
This comment was generated by <a href="https:/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>
Expand All @@ -20,7 +20,7 @@ This comment was generated by <a href="https:/hashicorp/web-platform
baseBranch: 'main',
branch: 'feature',
})
).toBe(`<h2>Changed Pages</h2>
).toBe(`<h2>📄 Changed Pages</h2>
<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>
<br>
This comment was generated by <a href="https:/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>
Expand All @@ -39,7 +39,7 @@ This comment was generated by <a href="https:/hashicorp/web-platform
deployUrl: 'feature-test.example',
baseBranchDeployUrl: 'main-test.example',
})
).toBe(`<h2>Changed Pages</h2>
).toBe(`<h2>📄 Changed Pages</h2>
<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>
<br>
This comment was generated by <a href="https:/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>
Expand Down
12 changes: 11 additions & 1 deletion packages/tools/scripts/next-touched-pages/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ interface BuildManifest {
interface Configuration {
name?: string
paths?: Record<string, string[]>
skipCommentIfEmpty?: boolean
}

const css = /\/\*+[\s\S]*?sourceMappingURL\s*=([\s\S]*?)\*\//
Expand Down Expand Up @@ -245,17 +246,25 @@ export function generateCommentMarkdown(
deployUrl,
dynamicPathsConfig,
packageName,
skipCommentIfEmpty,
}: {
baseBranch?: string
baseBranchDeployUrl?: string
branch?: string
deployUrl?: string
dynamicPathsConfig?: Record<string, string[]>
packageName?: string
skipCommentIfEmpty?: boolean
}
): string {
// If there aren't any changed pages and skipCommentIfEmpty is truthy, return
// an empty string.
if (skipCommentIfEmpty && changedPages.length === 0) {
return ''
}

let comment = summary.addHeading(
packageName ? `Changed Pages for ${packageName}` : 'Changed Pages',
packageName ? `📄 Changed Pages for ${packageName}` : '📄 Changed Pages',
2
)
if (changedPages.length > 0) {
Expand Down Expand Up @@ -400,6 +409,7 @@ export default async function main() {
baseBranchDeployUrl: argv.baseBranchDeployUrl,
dynamicPathsConfig: config.paths,
packageName: config.name,
skipCommentIfEmpty: config.skipCommentIfEmpty,
})
break
}
Expand Down

0 comments on commit cc0dc4e

Please sign in to comment.