diff --git a/comments/comments.go b/comments/comments.go index ffeb156b..3de00713 100644 --- a/comments/comments.go +++ b/comments/comments.go @@ -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) @@ -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") diff --git a/comments/comments_test.go b/comments/comments_test.go index 177a5113..80663f9a 100644 --- a/comments/comments_test.go +++ b/comments/comments_test.go @@ -167,7 +167,7 @@ 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) } @@ -175,7 +175,7 @@ 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) } @@ -183,7 +183,7 @@ 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) } @@ -191,7 +191,7 @@ 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) } @@ -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 \n " + expected := "## LaunchDarkly flag references\n### :mag: 1 flag added or modified\n\n| Name | Key | Aliases found | Info |\n| --- | --- | --- | --- |\ncomment1\ncomment2\n\n\n \n " assert.Equal(t, expected, comment) } @@ -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 \n " + expected := "## LaunchDarkly flag references\n### :x: 2 flags removed\n\n| Name | Key | Aliases found |Info |\n| --- | --- | --- | --- |\ncomment1\ncomment2\n \n " assert.Equal(t, expected, comment) } @@ -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) } @@ -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)