Skip to content

Commit

Permalink
start updating comment
Browse files Browse the repository at this point in the history
  • Loading branch information
jazanne committed Nov 13, 2023
1 parent 8bf8973 commit 7b1e130
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
13 changes: 5 additions & 8 deletions comments/comments.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,13 @@ func githubFlagComment(flag ldapi.FeatureFlag, aliases []string, added, extinct
commentTemplate.ArchivedAt = time.UnixMilli(*flag.ArchivedDate)
}
// All whitespace for template is required to be there or it will not render properly nested.
tmplSetup := `| {{- if eq .Flag.Archived true}}{{- if eq .Added true}} :warning:{{- end}}{{- end}}` +
`{{- if eq .Extinct true}} :skull:{{- end}}` +
` [{{.Flag.Name}}]({{.LDInstance}}{{.Primary.Site.Href}})` +
`{{- if eq .Flag.Archived true}}` +
` (archived on {{.ArchivedAt | date "2006-01-02"}})` +
`{{- end}} | ` +
tmplSetup := `| [{{.Flag.Name}}]({{.LDInstance}}{{.Primary.Site.Href}}) | ` +
"`" + `{{.Flag.Key}}` + "` |" +
`{{- if ne (len .Aliases) 0}}` +
`{{range $i, $e := .Aliases }}` + `{{if $i}},{{end}}` + " `" + `{{$e}}` + "`" + `{{end}}` +
`{{- end}} |`
`{{- end}} | ` +
`{{- if eq .Extinct true}} :white_check_mark: all references removed{{- end}} ` +
`{{- if eq .Flag.Archived true}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} archived on {{.ArchivedAt | date "2006-01-02"}}{{- end}} |`

tmpl := template.Must(template.New("comment").Funcs(template.FuncMap{"trim": strings.TrimSpace, "isNil": isNil}).Funcs(sprig.FuncMap()).Parse(tmplSetup))
err := tmpl.Execute(&commentBody, commentTemplate)
Expand Down Expand Up @@ -89,7 +86,7 @@ type FlagComments struct {
}

func BuildFlagComment(buildComment FlagComments, flagsRef lflags.FlagsRef, existingComment *github.IssueComment) string {
tableHeader := "| Name | Key | Aliases found |\n| --- | --- | --- |"
tableHeader := "| Name | Key | Aliases found | Info |\n| --- | --- | --- | --- |"

var commentStr []string
commentStr = append(commentStr, "## LaunchDarkly flag references")
Expand Down
18 changes: 9 additions & 9 deletions comments/comments_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,31 +167,31 @@ func (e *testFlagEnv) NoAliases(t *testing.T) {
comment, err := githubFlagComment(e.Flag, []string{}, true, false, &e.Config)
require.NoError(t, err)

expected := "| [example flag](https://example.com/test) | `example-flag` | |"
expected := "| [example flag](https://example.com/test) | `example-flag` | | |"
assert.Equal(t, expected, comment)
}

func (e *testFlagEnv) Alias(t *testing.T) {
comment, err := githubFlagComment(e.Flag, []string{"exampleFlag", "ExampleFlag"}, true, false, &e.Config)
require.NoError(t, err)

expected := "| [example flag](https://example.com/test) | `example-flag` | `exampleFlag`, `ExampleFlag` |"
expected := "| [example flag](https://example.com/test) | `example-flag` | `exampleFlag`, `ExampleFlag` | |"
assert.Equal(t, expected, comment)
}

func (e *testFlagEnv) ArchivedAdded(t *testing.T) {
comment, err := githubFlagComment(e.ArchivedFlag, []string{}, true, false, &e.Config)
require.NoError(t, err)

expected := "| :warning: [archived flag](https://example.com/test) (archived on 2023-08-03) | `archived-flag` | |"
expected := "| [archived flag](https://example.com/test) | `archived-flag` | | :warning: archived on 2023-08-03 |"
assert.Equal(t, expected, comment)
}

func (e *testFlagEnv) ArchivedRemoved(t *testing.T) {
comment, err := githubFlagComment(e.ArchivedFlag, []string{}, false, false, &e.Config)
require.NoError(t, err)

expected := "| [archived flag](https://example.com/test) (archived on 2023-08-03) | `archived-flag` | |"
expected := "| [archived flag](https://example.com/test) | `archived-flag` | | :information_source: archived on 2023-08-03 |"
assert.Equal(t, expected, comment)
}

Expand All @@ -200,7 +200,7 @@ func (e *testCommentBuilder) AddedOnly(t *testing.T) {
e.Comments.CommentsAdded = []string{"comment1", "comment2"}
comment := BuildFlagComment(e.Comments, e.FlagsRef, nil)

expected := "## LaunchDarkly flag references\n### :mag: 1 flag added or modified\n\n| Name | Key | Aliases found |\n| --- | --- | --- |\ncomment1\ncomment2\n\n\n <!-- flags:example-flag -->\n <!-- comment hash: c449ce18623b2038f1ae2f02c46869cd -->"
expected := "## LaunchDarkly flag references\n### :mag: 1 flag added or modified\n\n| Name | Key | Aliases found | Info |\n| --- | --- | --- | --- |\ncomment1\ncomment2\n\n\n <!-- flags:example-flag -->\n <!-- comment hash: c449ce18623b2038f1ae2f02c46869cd -->"
assert.Equal(t, expected, comment)
}

Expand All @@ -210,7 +210,7 @@ func (e *testCommentBuilder) RemovedOnly(t *testing.T) {
e.Comments.CommentsRemoved = []string{"comment1", "comment2"}
comment := BuildFlagComment(e.Comments, e.FlagsRef, nil)

expected := "## LaunchDarkly flag references\n### :x: 2 flags removed\n\n| Name | Key | Aliases found |\n| --- | --- | --- |\ncomment1\ncomment2\n <!-- flags:example-flag,sample-flag -->\n <!-- comment hash: 9ab2cb5c0fcfcce9002cf0935f5f4ad5 -->"
expected := "## LaunchDarkly flag references\n### :x: 2 flags removed\n\n| Name | Key | Aliases found |Info |\n| --- | --- | --- | --- |\ncomment1\ncomment2\n <!-- flags:example-flag,sample-flag -->\n <!-- comment hash: 9ab2cb5c0fcfcce9002cf0935f5f4ad5 -->"
assert.Equal(t, expected, comment)
}

Expand All @@ -231,7 +231,7 @@ func (e *testProcessor) Basic(t *testing.T) {
e.FlagsRef.FlagsAdded["example-flag"] = []string{}
processor := ProcessFlags(e.FlagsRef, e.Flags, &e.Config)
expected := FlagComments{
CommentsAdded: []string{"| [example flag](https://example.com/test) | `example-flag` | |"},
CommentsAdded: []string{"| [example flag](https://example.com/test) | `example-flag` | | |"},
}
assert.Equal(t, expected, processor)
}
Expand All @@ -242,8 +242,8 @@ func (e *testProcessor) Multi(t *testing.T) {
processor := ProcessFlags(e.FlagsRef, e.Flags, &e.Config)
expected := FlagComments{
CommentsAdded: []string{
"| [example flag](https://example.com/test) | `example-flag` | |",
"| [second flag](https://example.com/test) | `second-flag` | |",
"| [example flag](https://example.com/test) | `example-flag` | | |",
"| [second flag](https://example.com/test) | `second-flag` | | |",
},
}
assert.Equal(t, expected, processor)
Expand Down

0 comments on commit 7b1e130

Please sign in to comment.