Skip to content

Commit

Permalink
fix: makes description appear even if unrelated comment appears befor…
Browse files Browse the repository at this point in the history
…e description comment fixes #92
  • Loading branch information
norwoodj committed May 18, 2021
1 parent 023fece commit aaec4ec
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ htmlSnippets:
</body>
</html>
# nonsense comment before
#
# -- Let's put it in the description <html></html>
two: ""

Expand Down
3 changes: 3 additions & 0 deletions example-charts/special-characters/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ elasticsearch:
# elasticsearch.clusterHealthCheckParams -- The Elasticsearch cluster health status params that will be used by readinessProbe command
clusterHealthCheckParams: "wait_for_status=yellow&timeout=1s"

# unrelated comments
# before
#
# elasticsearch.clusterHealthCheckParamsDescription -- Now let's put some special characters in the description: wait_for_status=yellow&timeout=1s
clusterHealthCheckParamsDescription: ""

Expand Down
6 changes: 0 additions & 6 deletions pkg/document/values.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,6 @@ func getDescriptionFromNode(node *yaml.Node) helm.ChartValueDescription {
}

commentLines := strings.Split(node.HeadComment, "\n")
match := autoDocCommentRegex.FindStringSubmatch(commentLines[0])

if len(match) < 2 {
return helm.ChartValueDescription{}
}

keyFromComment, c := helm.ParseComment(commentLines)
if keyFromComment != "" {
return helm.ChartValueDescription{}
Expand Down
16 changes: 11 additions & 5 deletions pkg/helm/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,21 @@ package helm
func ParseComment(commentLines []string) (string, ChartValueDescription) {
var valueKey string
var c ChartValueDescription
var docStartIdx int

for i := range commentLines {
match := valuesDescriptionRegex.FindStringSubmatch(commentLines[i])
if len(match) < 3 {
continue
}

match := valuesDescriptionRegex.FindStringSubmatch(commentLines[0])
if match[1] != "" {
valueKey = match[1]
c.Description = match[2]
docStartIdx = i
break
}

c.Description = match[2]

for _, line := range commentLines[1:] {
for _, line := range commentLines[docStartIdx+ 1:] {
defaultCommentMatch := defaultValueRegex.FindStringSubmatch(line)

if len(defaultCommentMatch) > 1 {
Expand Down

0 comments on commit aaec4ec

Please sign in to comment.