Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: restore support for ignored yaml comment #254

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,24 @@ configMap:
not real config param: value
```

### Ignored YAML comments

In cases you would like to not include certain YAML comments, such as explicit example, context information, you me use a double `#` to tell helm-docs to ignore e.g.

```yaml
# -- Using existing secret
## Secret format:
## stringData:
## comm_config.yaml: |
## communications:
## # Here specify settings for each app, like Slack, Mattermost etc.
## # NOTE: Use setting format visible below.
##
## FIXME some keys needs stuff to happen. See #1234
# @default -- an empty string, meaning no existing secret
existingSecretName: ""
```

### Advanced table rendering
Some helm chart `values.yaml` uses complicated structure for the key/value
pairs. For example, it may uses a multiline string of Go template text instead
Expand Down
10 changes: 10 additions & 0 deletions example-charts/comment-ignored/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
apiVersion: v1
name: comment-ignored
description: A simple chart that installs, let's say PrometheusRules, that contains values.yaml comment that shouldn't be included in the helm-docs
version: "0.2.0"
home: "https://github.com/norwoodj/helm-docs/tree/master/example-charts/comment-ignored"
sources: ["https://github.com/norwoodj/helm-docs/tree/master/example-charts/comment-ignored"]
engine: gotpl
maintainers:
- email: norwood.john.m@gmail.com
name: John Norwood
29 changes: 29 additions & 0 deletions example-charts/comment-ignored/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# no-requirements

![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)

A simple chart that installs, let's say PrometheusRules, that needs no sub-charts

**Homepage:** <https://github.com/norwoodj/helm-docs/tree/master/example-charts/no-requirements>

## Maintainers

| Name | Email | Url |
| ---- | ------ | --- |
| John Norwood | <norwood.john.m@gmail.com> | |

## Source Code

* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/no-requirements>

## Values

| Key | Type | Default | Description |
|-----|------|---------|-------------|
| rules.latency.percentiles.99.duration | string | `"5m"` | Duration for which the 99th percentile must be above the threshold to alert |
| rules.latency.percentiles.99.threshold | float | `1.5` | Threshold in seconds for our 99th percentile latency above which the alert will fire |
| rules.statusCodes.codes.5xx.duration | string | `"5m"` | Duration for which the percent of 5xx responses must be above the threshold to alert |
| rules.statusCodes.codes.5xx.threshold | float | `1.5` | Threshold percentage of 5xx responses above which the alert will fire |

----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.14.0](https://github.com/norwoodj/helm-docs/releases/v1.14.0)
15 changes: 15 additions & 0 deletions example-charts/comment-ignored/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
rules:
latency:
percentiles:
"99":
# rules.latency.percentiles.99.threshold -- Threshold in seconds for our 99th percentile latency above which the alert will fire
## Note that this is a secret comment that should be added to the doc
threshold: 1.5
# rules.latency.percentiles.99.duration -- Duration for which the 99th percentile must be above the threshold to alert
## Secret format:
## stringData:
## comm_config.yaml: |
## communications:
## # Here specify settings for each app, like Slack, Mattermost etc.
## # NOTE: Use setting format visible below.
duration: 5m
6 changes: 3 additions & 3 deletions example-charts/no-requirements/README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# no-requirements
# comment-ignored

![Version: 0.2.0](https://img.shields.io/badge/Version-0.2.0-informational?style=flat-square)

A simple chart that installs, let's say PrometheusRules, that needs no sub-charts

**Homepage:** <https://github.com/norwoodj/helm-docs/tree/master/example-charts/no-requirements>
**Homepage:** <https://github.com/norwoodj/helm-docs/tree/master/example-charts/comment-ignored>

## Maintainers

Expand All @@ -14,7 +14,7 @@ A simple chart that installs, let's say PrometheusRules, that needs no sub-chart

## Source Code

* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/no-requirements>
* <https://github.com/norwoodj/helm-docs/tree/master/example-charts/comment-ignored>

## Values

Expand Down
49 changes: 49 additions & 0 deletions pkg/document/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,6 +1304,55 @@ animals:
assert.Equal(t, "The best kind of animal probably, allow me to list their many varied benefits. Cats are very funny, and quite friendly, in almost all cases", valuesRows[0].AutoDescription)
}

func TestIgnoredCommentDescription(t *testing.T) {
helmValues := parseYamlValues(`
animals:
# -- The best kind of animal probably, allow me to list their many varied benefits.
# Cats are very funny, and quite friendly, in almost all cases
## They can be dangerous sometimes
## especially when untamed!
# @default -- The list of cats that _I_ own
cats:
- echo
- foxtrot
## This one, you probable don't want to
## meet them face to face
- cobra
## They are always cute
# Little doggo
dogs:
- alpha
## Maybe this one not that much
- beta
`)

valuesRows, err := getSortedValuesTableRows(helmValues, make(map[string]helm.ChartValueDescription))

assert.Nil(t, err)
assert.Len(t, valuesRows, 3)

assert.Equal(t, "animals.cats", valuesRows[0].Key)
assert.Equal(t, listType, valuesRows[0].Type)
assert.Equal(t, "The list of cats that _I_ own", valuesRows[0].AutoDefault)
assert.Equal(t, "", valuesRows[0].Default)
assert.Equal(t, "", valuesRows[0].Description)
assert.Equal(t, "The best kind of animal probably, allow me to list their many varied benefits. Cats are very funny, and quite friendly, in almost all cases", valuesRows[0].AutoDescription)

assert.Equal(t, "animals.dogs[0]", valuesRows[1].Key)
assert.Equal(t, stringType, valuesRows[1].Type)
assert.Equal(t, "", valuesRows[1].AutoDefault)
assert.Equal(t, "`\"alpha\"`", valuesRows[1].Default)
assert.Equal(t, "", valuesRows[1].Description)
assert.Equal(t, "", valuesRows[1].AutoDescription)

assert.Equal(t, "animals.dogs[1]", valuesRows[2].Key)
assert.Equal(t, stringType, valuesRows[2].Type)
assert.Equal(t, "", valuesRows[2].AutoDefault)
assert.Equal(t, "`\"beta\"`", valuesRows[2].Default)
assert.Equal(t, "", valuesRows[2].Description)
assert.Equal(t, "", valuesRows[2].AutoDescription)
}

func TestAutoMultilineDescriptionWithoutValue(t *testing.T) {
helmValues := parseYamlValues(`
animals:
Expand Down
5 changes: 5 additions & 0 deletions pkg/helm/comment.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ func ParseComment(commentLines []string) (string, ChartValueDescription) {

commentContinuationMatch := commentContinuationRegex.FindStringSubmatch(line)

// If the comment uses a double hash, this means it should be ignored for the documentation
if len(line) > 2 && line[1] == '#' {
continue
}

if isRaw {

if len(commentContinuationMatch) > 1 {
Expand Down