Skip to content

Commit 7dfbcd6

Browse files
provider index doc: Skip headers that mention Contributing (#2507)
This pull request globalizes skipping sections whose headers mention Contributing, in the `docs/_index.md` file. It does so by adding Contributing/contributing to the denylist of words found in a header in an index.md file. Example: pulumi/pulumi-vsphere#607
2 parents f865647 + c7d6bc1 commit 7dfbcd6

File tree

2 files changed

+91
-1
lines changed

2 files changed

+91
-1
lines changed

pkg/tfgen/installation_docs.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,9 @@ func getDefaultHeadersToSkip() []*regexp.Regexp {
401401
regexp.MustCompile("[Dd]evelopment"),
402402
regexp.MustCompile("[Dd]ebugging"),
403403
regexp.MustCompile("[Tt]erraform CLI"),
404-
regexp.MustCompile("[Tt]erraform Cloud"),
404+
regexp.MustCompile("[Tt]erraform [Cc]loud"),
405405
regexp.MustCompile("Delete Protection"),
406+
regexp.MustCompile("[Cc]ontributing"),
406407
}
407408
return defaultHeaderSkipRegexps
408409
}

pkg/tfgen/installation_docs_test.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package tfgen
22

33
import (
44
"bytes"
5+
"regexp"
56
"runtime"
67
"testing"
78

@@ -398,6 +399,94 @@ func TestSkipSectionHeadersByContent(t *testing.T) {
398399
})
399400
}
400401

402+
func TestSkipDefaultSectionHeaders(t *testing.T) {
403+
t.Parallel()
404+
type testCase struct {
405+
// The name of the test case.
406+
name string
407+
headersToSkip []*regexp.Regexp
408+
input string
409+
expected string
410+
}
411+
412+
testCases := []testCase{
413+
{
414+
name: "Skips Sections Mentioning Logging",
415+
headersToSkip: getDefaultHeadersToSkip(),
416+
input: "## Logging",
417+
expected: "",
418+
},
419+
{
420+
name: "Skips Sections Mentioning Logs",
421+
headersToSkip: getDefaultHeadersToSkip(),
422+
input: "## This section talks about logs",
423+
expected: "",
424+
},
425+
{
426+
name: "Skips Sections About Testing",
427+
headersToSkip: getDefaultHeadersToSkip(),
428+
input: "## Testing",
429+
expected: "",
430+
},
431+
{
432+
name: "Skips Sections About Development",
433+
headersToSkip: getDefaultHeadersToSkip(),
434+
input: "## Development",
435+
expected: "",
436+
},
437+
{
438+
name: "Skips Sections About Debugging",
439+
headersToSkip: getDefaultHeadersToSkip(),
440+
input: "## Debugging",
441+
expected: "",
442+
},
443+
{
444+
name: "Skips Sections Talking About Terraform CLI",
445+
headersToSkip: getDefaultHeadersToSkip(),
446+
input: "## Terraform CLI",
447+
expected: "",
448+
},
449+
{
450+
name: "Skips Sections Talking About terraform cloud",
451+
headersToSkip: getDefaultHeadersToSkip(),
452+
input: "### terraform cloud",
453+
expected: "",
454+
},
455+
{
456+
name: "Skips Sections About Delete Protection",
457+
headersToSkip: getDefaultHeadersToSkip(),
458+
input: "### Delete Protection",
459+
expected: "",
460+
}, {
461+
name: "Skips Sections About Contributing",
462+
headersToSkip: getDefaultHeadersToSkip(),
463+
input: "## Contributing",
464+
expected: "",
465+
}, {
466+
name: "Does Not Skip Sections About Unicorns",
467+
headersToSkip: getDefaultHeadersToSkip(),
468+
input: "## Unicorns",
469+
expected: "## Unicorns",
470+
},
471+
}
472+
for _, tt := range testCases {
473+
tt := tt
474+
t.Run(tt.name, func(t *testing.T) {
475+
t.Parallel()
476+
actual, err := SkipSectionByHeaderContent([]byte(tt.input), func(headerText string) bool {
477+
for _, header := range tt.headersToSkip {
478+
if header.Match([]byte(headerText)) {
479+
return true
480+
}
481+
}
482+
return false
483+
})
484+
require.NoError(t, err)
485+
assertEqualHTML(t, tt.expected, string(actual))
486+
})
487+
}
488+
}
489+
401490
// Helper func to determine if the HTML rendering is equal.
402491
// This helps in cases where the processed Markdown is slightly different from the expected Markdown
403492
// due to goldmark making some (insignificant to the final HTML) changes when parsing and rendering.

0 commit comments

Comments
 (0)