Skip to content

Commit

Permalink
provider index doc: Skip headers that mention Contributing (#2507)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
guineveresaenger authored Oct 25, 2024
2 parents f865647 + c7d6bc1 commit 7dfbcd6
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 1 deletion.
3 changes: 2 additions & 1 deletion pkg/tfgen/installation_docs.go
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,9 @@ func getDefaultHeadersToSkip() []*regexp.Regexp {
regexp.MustCompile("[Dd]evelopment"),
regexp.MustCompile("[Dd]ebugging"),
regexp.MustCompile("[Tt]erraform CLI"),
regexp.MustCompile("[Tt]erraform Cloud"),
regexp.MustCompile("[Tt]erraform [Cc]loud"),
regexp.MustCompile("Delete Protection"),
regexp.MustCompile("[Cc]ontributing"),
}
return defaultHeaderSkipRegexps
}
Expand Down
89 changes: 89 additions & 0 deletions pkg/tfgen/installation_docs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package tfgen

import (
"bytes"
"regexp"
"runtime"
"testing"

Expand Down Expand Up @@ -398,6 +399,94 @@ func TestSkipSectionHeadersByContent(t *testing.T) {
})
}

func TestSkipDefaultSectionHeaders(t *testing.T) {
t.Parallel()
type testCase struct {
// The name of the test case.
name string
headersToSkip []*regexp.Regexp
input string
expected string
}

testCases := []testCase{
{
name: "Skips Sections Mentioning Logging",
headersToSkip: getDefaultHeadersToSkip(),
input: "## Logging",
expected: "",
},
{
name: "Skips Sections Mentioning Logs",
headersToSkip: getDefaultHeadersToSkip(),
input: "## This section talks about logs",
expected: "",
},
{
name: "Skips Sections About Testing",
headersToSkip: getDefaultHeadersToSkip(),
input: "## Testing",
expected: "",
},
{
name: "Skips Sections About Development",
headersToSkip: getDefaultHeadersToSkip(),
input: "## Development",
expected: "",
},
{
name: "Skips Sections About Debugging",
headersToSkip: getDefaultHeadersToSkip(),
input: "## Debugging",
expected: "",
},
{
name: "Skips Sections Talking About Terraform CLI",
headersToSkip: getDefaultHeadersToSkip(),
input: "## Terraform CLI",
expected: "",
},
{
name: "Skips Sections Talking About terraform cloud",
headersToSkip: getDefaultHeadersToSkip(),
input: "### terraform cloud",
expected: "",
},
{
name: "Skips Sections About Delete Protection",
headersToSkip: getDefaultHeadersToSkip(),
input: "### Delete Protection",
expected: "",
}, {
name: "Skips Sections About Contributing",
headersToSkip: getDefaultHeadersToSkip(),
input: "## Contributing",
expected: "",
}, {
name: "Does Not Skip Sections About Unicorns",
headersToSkip: getDefaultHeadersToSkip(),
input: "## Unicorns",
expected: "## Unicorns",
},
}
for _, tt := range testCases {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
actual, err := SkipSectionByHeaderContent([]byte(tt.input), func(headerText string) bool {
for _, header := range tt.headersToSkip {
if header.Match([]byte(headerText)) {
return true
}
}
return false
})
require.NoError(t, err)
assertEqualHTML(t, tt.expected, string(actual))
})
}
}

// Helper func to determine if the HTML rendering is equal.
// This helps in cases where the processed Markdown is slightly different from the expected Markdown
// due to goldmark making some (insignificant to the final HTML) changes when parsing and rendering.
Expand Down

0 comments on commit 7dfbcd6

Please sign in to comment.