Skip to content

Commit b4ccafc

Browse files
authored
feat(new): add Related Resources source link to builtin rule doc template (#1957)
Builtin rule docs scaffolded by `regal new rule --type builtin` now include a Related Resources section pointing at the rule's .rego file on GitHub, matching the pattern in existing rule docs. Part of #1567 Signed-off-by: Matt Van Horn <mvanhorn@gmail.com>
1 parent 12cc776 commit b4ccafc

2 files changed

Lines changed: 6 additions & 0 deletions

File tree

cmd/new.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ type TemplateValues struct {
3535
NameOriginal string
3636
Name string
3737
NameTest string
38+
FileName string
3839
}
3940

4041
var (
@@ -257,6 +258,7 @@ func createBuiltinDocs(params newRuleCommandParams) error {
257258
func templateValues(params newRuleCommandParams) (tvs TemplateValues) {
258259
tvs.Category = params.category
259260
tvs.NameOriginal = params.name
261+
tvs.FileName = strings.ToLower(strings.ReplaceAll(params.name, "-", "_")) + ".rego"
260262

261263
if strings.Contains(params.name, "-") || strings.Contains(params.name, "_") {
262264
dashedNameValue := strings.ReplaceAll(params.name, "_", "-")

internal/embeds/templates/builtin/builtin.md.tpl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,7 @@ rules:
3535
# one of "error", "warning", "ignore"
3636
level: error
3737
```
38+
39+
## Related Resources
40+
41+
- GitHub: [Source Code](https://github.com/open-policy-agent/regal/blob/main/bundle/regal/rules/{{.Category}}/{{.NameOriginal}}/{{.FileName}})

0 commit comments

Comments
 (0)