Skip to content

Commit 63fb1fd

Browse files
committed
Let the footer be generated without conf.Feedback
Signed-off-by: David Pordomingo <[email protected]>
1 parent 5d7b11e commit 63fb1fd

File tree

5 files changed

+15
-22
lines changed

5 files changed

+15
-22
lines changed

.helm-staging.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ providers:
2727
app_id: 17877
2828
private_key: /local/lookout/private-key.pem
2929
secretName: lookout-staging-github-key
30-
comment_footer: "_If you have feedback about this comment made by the analyzer {{.Name}}, please, [tell us]({{.Feedback}})._"
30+
comment_footer: "_If you have feedback about this comment made by the analyzer {{.Name}}{{with .Feedback}}, please, [tell us]({{.}}){{end}}._"
3131
installation_sync_interval: 5m
3232

3333
analyzers:

config.yml.tpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ analyzers:
88

99
providers:
1010
github:
11-
comment_footer: "_If you have feedback about this comment made by the analyzer {{.Name}}, please, [tell us]({{.Feedback}})._"
11+
comment_footer: "_If you have feedback about this comment made by the analyzer {{.Name}}{{with .Feedback}}, please, [tell us]({{.}}){{end}}._"
1212
# The minimum watch interval to discover new pull requests and push events
1313
watch_min_interval: 2s
1414
# Authorization with GitHub App

docs/configuration.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The `providers.github` key configures how **source{d} Lookout** will connect wit
3939
```yaml
4040
providers:
4141
github:
42-
comment_footer: "_Comment made by analyzer '{{.Name}}', [report]({{.Feedback}})._"
42+
comment_footer: "_Comment made by '{{.Name}}'{{with .Feedback}}, [tell us]({{.}}){{end}}._"
4343
# app_id: 1234
4444
# private_key: ./key.pem
4545
# installation_sync_interval: 1h
@@ -141,29 +141,30 @@ analyzers:
141141

142142
### Add a Custom Message to the Posted Comments
143143

144-
You can configure **source{d} Lookout** to add a custom message to every comment that each analyzer returns. This custom message will be created from the template defined by `providers.github.comment_footer`, using the `name` and `feedback` set for each analyzer.
144+
You can configure **source{d} Lookout** to add a custom message to every comment that each analyzer returns. This custom message will be created from the template defined by `providers.github.comment_footer`, using the configuration set for each analyzer.
145145

146146
If the template (`providers.github.comment_footer`) is empty, or the analyzer configuration does not define any of the values that the template requires, the custom message won't be added.
147147

148-
For example, for this configuration, each analyzer needs to define `name` and `feedback`:
148+
For example, for this configuration, each analyzer needs to define `name` and `settings.email`:
149149

150150
```yaml
151151
providers:
152152
github:
153-
comment_footer: "Comment made by analyzer {{.Name}}, [report]({{.Feedback}})."
153+
comment_footer: "Comment made by analyzer {{.Name}}, [email me]({{.Settings.email}})."
154154
155155
analyzers:
156156
- name: Fancy Analyzer
157157
addr: ipv4://localhost:9930
158-
feedback: http://example.com/report-issue
158+
settings:
159+
159160
- name: Awesome Analyzer
160161
addr: ipv4://localhost:9931
161162
```
162163

163164
Comments from `Fancy Analyzer` will have this footer appended:
164-
>_Comment made by analyzer Fancy Analyzer, [report](http://example.com/report-issue)._
165+
>_Comment made by analyzer Fancy Analyzer, [email me](admin@example.org)._
165166

166-
but comments from `Awesome Analyzer` will not have a footer message because its configuration is missing a `feedback` value.
167+
but comments from `Awesome Analyzer` wont have a footer message because in its configuration it's missing the `settings.email` value.
167168

168169

169170
## Timeouts

provider/github/review.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,10 @@ const commentsSeparator = "\n<!-- lookout comment separator -->\n---\n"
3131
const footnoteSeparator = "\n<!-- lookout footnote separator -->\n"
3232

3333
var (
34-
ErrEmptyTemplate = errors.NewKind("empty footer template")
35-
ErrOldTemplate = errors.NewKind("old footer template: '%%s' placeholder is no longer supported: '%s'")
36-
ErrParseTemplate = errors.NewKind("error parsing footer template: %s")
37-
ErrNoDataForFooter = errors.NewKind("there is no enough data to generate the footer")
38-
ErrTemplateError = errors.NewKind("error generating the footer: %s")
34+
ErrEmptyTemplate = errors.NewKind("empty footer template")
35+
ErrOldTemplate = errors.NewKind("old footer template: '%%s' placeholder is no longer supported: '%s'")
36+
ErrParseTemplate = errors.NewKind("error parsing footer template: %s")
37+
ErrTemplateError = errors.NewKind("error generating the footer: %s")
3938
)
4039

4140
// createReview creates pull request review on github using multiple http calls
@@ -245,16 +244,13 @@ func addFootnote(
245244
footer, err := getFootnote(tmpl, analyzerConf)
246245
if err != nil {
247246
ctxlog.Get(ctx).Warningf("footer could not be generated: %s", err)
247+
return comment
248248
}
249249

250250
return comment + footer
251251
}
252252

253253
func getFootnote(tmpl *template.Template, analyzerConf *lookout.AnalyzerConfig) (string, error) {
254-
if analyzerConf == nil || analyzerConf.Feedback == "" || analyzerConf.Name == "" {
255-
return "", ErrNoDataForFooter.New()
256-
}
257-
258254
var footer strings.Builder
259255
if err := tmpl.Execute(&footer, analyzerConf); err != nil {
260256
return "", ErrTemplateError.New(err)

provider/github/review_test.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,4 @@ func TestCouldNotExecuteFooterTemplate(t *testing.T) {
233233
require.Nil(err)
234234
commentsWrongTemplate := addFootnote(context.TODO(), "comments", unkonwnDataTemplate, nil)
235235
require.Equal("comments", commentsWrongTemplate)
236-
237-
footerWrongTemplate, err := getFootnote(unkonwnDataTemplate, nil)
238-
require.True(ErrNoDataForFooter.Is(err))
239-
require.Equal("", footerWrongTemplate)
240236
}

0 commit comments

Comments
 (0)