From e1cd387aacc05d96e669360dd89d5057214b547a Mon Sep 17 00:00:00 2001 From: Jaz Date: Fri, 3 Nov 2023 11:06:52 -0400 Subject: [PATCH 01/10] start setting up deprecated work --- comments/comments.go | 38 +++++++++++++++++++++++++++++--------- comments/comments_test.go | 38 ++++++++++++++++++++++++++++++++------ testdata/test | 4 +++- 3 files changed, 64 insertions(+), 16 deletions(-) diff --git a/comments/comments.go b/comments/comments.go index 5fb34836..8b5838fc 100644 --- a/comments/comments.go +++ b/comments/comments.go @@ -23,7 +23,12 @@ import ( type Comment struct { Flag ldapi.FeatureFlag + FlagKey string + FlagName string + Archived bool ArchivedAt time.Time + Deprecated bool + DeprecatedAt time.Time Added bool Extinct bool Aliases []string @@ -41,6 +46,10 @@ func isNil(a interface{}) bool { func githubFlagComment(flag ldapi.FeatureFlag, aliases []string, added, extinct bool, config *lcr.Config) (string, error) { commentTemplate := Comment{ Flag: flag, + FlagKey: flag.Key, + FlagName: flag.Name, + Archived: flag.Archived, + Deprecated: flag.Deprecated, Added: added, Extinct: config.CheckExtinctions && extinct, Aliases: aliases, @@ -48,30 +57,41 @@ func githubFlagComment(flag ldapi.FeatureFlag, aliases []string, added, extinct LDInstance: config.LdInstance, ExtinctionsEnabled: config.CheckExtinctions, } - var commentBody bytes.Buffer if flag.ArchivedDate != nil { commentTemplate.ArchivedAt = time.UnixMilli(*flag.ArchivedDate) } + if flag.DeprecatedDate != nil { + commentTemplate.DeprecatedAt = time.UnixMilli(*flag.DeprecatedDate) + } + // All whitespace for template is required to be there or it will not render properly nested. - tmplSetup := `| [{{.Flag.Name}}]({{.LDInstance}}{{.Primary.Site.Href}}) | ` + - "`" + `{{.Flag.Key}}` + "` |" + + tmplSetup := `| [{{.FlagName}}]({{.LDInstance}}{{.Primary.Site.Href}}) | ` + + "`" + `{{.FlagKey}}` + "` |" + `{{- if ne (len .Aliases) 0}}` + `{{range $i, $e := .Aliases }}` + `{{if $i}},{{end}}` + " `" + `{{$e}}` + "`" + `{{end}}` + - `{{- end}} | ` + - `{{- if eq .Extinct true}} :white_check_mark: all references removed` + - `{{- else if eq .ExtinctionsEnabled true}} :warning: not all references removed {{- end}} ` + - `{{- if eq .Flag.Archived true}}{{- if eq .Extinct true}}
{{- else if eq .ExtinctionsEnabled true}}
{{end}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} archived on {{.ArchivedAt | date "2006-01-02"}}{{- end}} |` + `{{- end}} | ` + infoCellTemplate() + ` |` tmpl := template.Must(template.New("comment").Funcs(template.FuncMap{"trim": strings.TrimSpace, "isNil": isNil}).Funcs(sprig.FuncMap()).Parse(tmplSetup)) - err := tmpl.Execute(&commentBody, commentTemplate) - if err != nil { + + var commentBody bytes.Buffer + if err := tmpl.Execute(&commentBody, commentTemplate); err != nil { return "", err } + commentStr := html.UnescapeString(commentBody.String()) return commentStr, nil } +// Template for info cell +// Will only show deprecated warning, if flag is not archived +func infoCellTemplate() string { + return `{{- if eq .Extinct true}} :white_check_mark: all references removed` + + `{{- else if eq .ExtinctionsEnabled true}} :warning: not all references removed {{- end}} ` + + `{{- if eq .Archived true}}{{- if eq .Extinct true}}
{{end}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} archived on {{.ArchivedAt | date "2006-01-02"}} ` + + `{{- else if eq .Deprecated true}}{{- if eq .Extinct true}}
{{end}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} deprecated on {{.DeprecatedAt | date "2006-01-02"}}{{- end}}` +} + func GithubNoFlagComment() *github.IssueComment { commentStr := `## LaunchDarkly flag references diff --git a/comments/comments_test.go b/comments/comments_test.go index abd3dc74..787bffe8 100644 --- a/comments/comments_test.go +++ b/comments/comments_test.go @@ -14,9 +14,10 @@ import ( func ptr[T any](t T) *T { return &t } type testFlagEnv struct { - Flag ldapi.FeatureFlag - ArchivedFlag ldapi.FeatureFlag - Config config.Config + Flag ldapi.FeatureFlag + ArchivedFlag ldapi.FeatureFlag + DeprecatedFlag ldapi.FeatureFlag + Config config.Config } func newTestAccEnv() *testFlagEnv { @@ -30,10 +31,16 @@ func newTestAccEnv() *testFlagEnv { archivedFlag := createFlag("archived-flag") archivedFlag.Archived = true archivedFlag.ArchivedDate = ptr(int64(1691072480000)) + + deprecatedFlag := createFlag("deprecated-flag") + deprecatedFlag.Deprecated = true + deprecatedFlag.DeprecatedDate = ptr(int64(1691072480000)) + return &testFlagEnv{ - Flag: flag, - ArchivedFlag: archivedFlag, - Config: config, + Flag: flag, + ArchivedFlag: archivedFlag, + DeprecatedFlag: deprecatedFlag, + Config: config, } } @@ -140,6 +147,9 @@ func TestGithubFlagComment(t *testing.T) { t.Run("Archived flag removed", acceptanceTestEnv.ArchivedRemoved) t.Run("Extinct flag", acceptanceTestEnv.ExtinctFlag) t.Run("Extinct and Archived flag", acceptanceTestEnv.ExtinctAndArchivedFlag) + + t.Run("Deprecated flag added", acceptanceTestEnv.DeprecatedAdded) + t.Run("Deprecated flag removed", acceptanceTestEnv.DeprecatedRemoved) } func TestProcessFlags(t *testing.T) { @@ -214,6 +224,22 @@ func (e *testFlagEnv) ExtinctAndArchivedFlag(t *testing.T) { assert.Equal(t, expected, comment) } +func (e *testFlagEnv) DeprecatedAdded(t *testing.T) { + comment, err := githubFlagComment(e.DeprecatedFlag, []string{}, true, false, &e.Config) + require.NoError(t, err) + + expected := "| [deprecated flag](https://example.com/test) | `deprecated-flag` | | :warning: deprecated on 2023-08-03 |" + assert.Equal(t, expected, comment) +} + +func (e *testFlagEnv) DeprecatedRemoved(t *testing.T) { + comment, err := githubFlagComment(e.DeprecatedFlag, []string{}, false, false, &e.Config) + require.NoError(t, err) + + expected := "| [deprecated flag](https://example.com/test) | `deprecated-flag` | | :information_source: deprecated on 2023-08-03 |" + assert.Equal(t, expected, comment) +} + func (e *testCommentBuilder) AddedOnly(t *testing.T) { e.FlagsRef.FlagsAdded["example-flag"] = []string{} e.Comments.CommentsAdded = []string{"comment1", "comment2"} diff --git a/testdata/test b/testdata/test index a82e2f31..c8f2cbaf 100644 --- a/testdata/test +++ b/testdata/test @@ -2,6 +2,8 @@ show-widgets showWidgets show_widgets oldPricingBanner +show-widgets show_widgets -oldPricingBanner mobile-app-promo-ios +mobile-app-promo-ios +beta-ui From 60035a255afa3815c47bd1c47a00c36021488f6b Mon Sep 17 00:00:00 2001 From: Jaz Date: Mon, 25 Mar 2024 11:41:12 -0400 Subject: [PATCH 02/10] remove unused --- comments/comments.go | 1 - 1 file changed, 1 deletion(-) diff --git a/comments/comments.go b/comments/comments.go index 8b5838fc..161da4ac 100644 --- a/comments/comments.go +++ b/comments/comments.go @@ -45,7 +45,6 @@ func isNil(a interface{}) bool { func githubFlagComment(flag ldapi.FeatureFlag, aliases []string, added, extinct bool, config *lcr.Config) (string, error) { commentTemplate := Comment{ - Flag: flag, FlagKey: flag.Key, FlagName: flag.Name, Archived: flag.Archived, From 66f5c2d59970c490e3bf7c383032a5978fc26413 Mon Sep 17 00:00:00 2001 From: Jaz Date: Mon, 25 Mar 2024 11:41:41 -0400 Subject: [PATCH 03/10] remove unused --- comments/comments.go | 1 - 1 file changed, 1 deletion(-) diff --git a/comments/comments.go b/comments/comments.go index 161da4ac..975153df 100644 --- a/comments/comments.go +++ b/comments/comments.go @@ -22,7 +22,6 @@ import ( ) type Comment struct { - Flag ldapi.FeatureFlag FlagKey string FlagName string Archived bool From 3063c5c487bddada208a3889fdc6aadce0b3bde5 Mon Sep 17 00:00:00 2001 From: Jaz Date: Mon, 25 Mar 2024 11:43:47 -0400 Subject: [PATCH 04/10] fix breaks --- comments/comments.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/comments/comments.go b/comments/comments.go index 975153df..3654d36e 100644 --- a/comments/comments.go +++ b/comments/comments.go @@ -86,8 +86,8 @@ func githubFlagComment(flag ldapi.FeatureFlag, aliases []string, added, extinct func infoCellTemplate() string { return `{{- if eq .Extinct true}} :white_check_mark: all references removed` + `{{- else if eq .ExtinctionsEnabled true}} :warning: not all references removed {{- end}} ` + - `{{- if eq .Archived true}}{{- if eq .Extinct true}}
{{end}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} archived on {{.ArchivedAt | date "2006-01-02"}} ` + - `{{- else if eq .Deprecated true}}{{- if eq .Extinct true}}
{{end}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} deprecated on {{.DeprecatedAt | date "2006-01-02"}}{{- end}}` + `{{- if eq .Archived true}}{{- if eq .Extinct true}}
{{- else if eq .ExtinctionsEnabled true}}
{{- end}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} archived on {{.ArchivedAt | date "2006-01-02"}} ` + + `{{- else if eq .Deprecated true}}{{- if eq .Extinct true}}
{{- else if eq .ExtinctionsEnabled true}}
{{- end}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} deprecated on {{.DeprecatedAt | date "2006-01-02"}}{{- end}}` } func GithubNoFlagComment() *github.IssueComment { From 6f98bafbcf592edc6da0aeac44a8d46a2de3fec4 Mon Sep 17 00:00:00 2001 From: Jaz Date: Mon, 25 Mar 2024 11:48:56 -0400 Subject: [PATCH 05/10] fix logic? --- comments/comments.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/comments/comments.go b/comments/comments.go index 3654d36e..7e535035 100644 --- a/comments/comments.go +++ b/comments/comments.go @@ -85,9 +85,9 @@ func githubFlagComment(flag ldapi.FeatureFlag, aliases []string, added, extinct // Will only show deprecated warning, if flag is not archived func infoCellTemplate() string { return `{{- if eq .Extinct true}} :white_check_mark: all references removed` + - `{{- else if eq .ExtinctionsEnabled true}} :warning: not all references removed {{- end}} ` + - `{{- if eq .Archived true}}{{- if eq .Extinct true}}
{{- else if eq .ExtinctionsEnabled true}}
{{- end}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} archived on {{.ArchivedAt | date "2006-01-02"}} ` + - `{{- else if eq .Deprecated true}}{{- if eq .Extinct true}}
{{- else if eq .ExtinctionsEnabled true}}
{{- end}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} deprecated on {{.DeprecatedAt | date "2006-01-02"}}{{- end}}` + `{{- else if and .Removed .ExtinctionsEnabled}} :warning: not all references removed {{- end}} ` + + `{{- if eq .Archived true}}{{- if eq .Extinct true}}
{{- else if and .Removed .ExtinctionsEnabled }}
{{- end}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} archived on {{.ArchivedAt | date "2006-01-02"}} ` + + `{{- else if eq .Deprecated true}}{{- if eq .Extinct true}}
{{- else if and .Removed .ExtinctionsEnabled }}
{{- end}}{{- if eq .Added true}} :warning:{{else}} :information_source:{{- end}} deprecated on {{.DeprecatedAt | date "2006-01-02"}}{{- end}}` } func GithubNoFlagComment() *github.IssueComment { From 36a39c7300651747707e50b25d8b4be8681fc58c Mon Sep 17 00:00:00 2001 From: Jaz Date: Mon, 25 Mar 2024 11:51:05 -0400 Subject: [PATCH 06/10] fix variable --- comments/comments.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/comments/comments.go b/comments/comments.go index 7e535035..25dad966 100644 --- a/comments/comments.go +++ b/comments/comments.go @@ -29,6 +29,7 @@ type Comment struct { Deprecated bool DeprecatedAt time.Time Added bool + Removed bool Extinct bool Aliases []string ChangeType string @@ -49,6 +50,7 @@ func githubFlagComment(flag ldapi.FeatureFlag, aliases []string, added, extinct Archived: flag.Archived, Deprecated: flag.Deprecated, Added: added, + Removed: !added, Extinct: config.CheckExtinctions && extinct, Aliases: aliases, Primary: flag.Environments[config.LdEnvironment], From 482f7c2788652d621da5d98486f6308b1bb34bfe Mon Sep 17 00:00:00 2001 From: Jaz Date: Mon, 25 Mar 2024 11:52:00 -0400 Subject: [PATCH 07/10] comment --- comments/comments.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/comments/comments.go b/comments/comments.go index 25dad966..17cb0cba 100644 --- a/comments/comments.go +++ b/comments/comments.go @@ -84,7 +84,7 @@ func githubFlagComment(flag ldapi.FeatureFlag, aliases []string, added, extinct } // Template for info cell -// Will only show deprecated warning, if flag is not archived +// Will only show deprecated warning if flag is not archived func infoCellTemplate() string { return `{{- if eq .Extinct true}} :white_check_mark: all references removed` + `{{- else if and .Removed .ExtinctionsEnabled}} :warning: not all references removed {{- end}} ` + From 8b5f11801c33a538a6f90eb418067fda33c3d825 Mon Sep 17 00:00:00 2001 From: Jaz Date: Mon, 25 Mar 2024 11:52:31 -0400 Subject: [PATCH 08/10] rm --- testdata/test | 1 - 1 file changed, 1 deletion(-) diff --git a/testdata/test b/testdata/test index c8f2cbaf..613b7907 100644 --- a/testdata/test +++ b/testdata/test @@ -1,7 +1,6 @@ show-widgets showWidgets show_widgets -oldPricingBanner show-widgets show_widgets mobile-app-promo-ios From a89c3faa83b6d34943dd08612afd9f58f8e17788 Mon Sep 17 00:00:00 2001 From: Jaz Date: Mon, 25 Mar 2024 11:55:17 -0400 Subject: [PATCH 09/10] dev notes --- comments/comments.go | 1 + 1 file changed, 1 insertion(+) diff --git a/comments/comments.go b/comments/comments.go index 17cb0cba..78abb028 100644 --- a/comments/comments.go +++ b/comments/comments.go @@ -43,6 +43,7 @@ func isNil(a interface{}) bool { return a == nil || reflect.ValueOf(a).IsNil() } +// Test go template rendering here https://gotemplate.io/ func githubFlagComment(flag ldapi.FeatureFlag, aliases []string, added, extinct bool, config *lcr.Config) (string, error) { commentTemplate := Comment{ FlagKey: flag.Key, From 81aa3d82bfe12ed3855c67db943956a0bd2d3dc7 Mon Sep 17 00:00:00 2001 From: Jaz Date: Mon, 25 Mar 2024 11:57:30 -0400 Subject: [PATCH 10/10] fix tests --- comments/comments_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/comments/comments_test.go b/comments/comments_test.go index 787bffe8..5ca1a61d 100644 --- a/comments/comments_test.go +++ b/comments/comments_test.go @@ -180,7 +180,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` | | :warning: not all references removed |" + expected := "| [example flag](https://example.com/test) | `example-flag` | | |" assert.Equal(t, expected, comment) } @@ -188,7 +188,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` | :warning: not all references removed |" + expected := "| [example flag](https://example.com/test) | `example-flag` | `exampleFlag`, `ExampleFlag` | |" assert.Equal(t, expected, comment) } @@ -196,7 +196,7 @@ func (e *testFlagEnv) ArchivedAdded(t *testing.T) { comment, err := githubFlagComment(e.ArchivedFlag, []string{}, true, false, &e.Config) require.NoError(t, err) - expected := "| [archived flag](https://example.com/test) | `archived-flag` | | :warning: not all references removed
:warning: archived on 2023-08-03 |" + expected := "| [archived flag](https://example.com/test) | `archived-flag` | | :warning: archived on 2023-08-03 |" assert.Equal(t, expected, comment) } @@ -236,7 +236,7 @@ func (e *testFlagEnv) DeprecatedRemoved(t *testing.T) { comment, err := githubFlagComment(e.DeprecatedFlag, []string{}, false, false, &e.Config) require.NoError(t, err) - expected := "| [deprecated flag](https://example.com/test) | `deprecated-flag` | | :information_source: deprecated on 2023-08-03 |" + expected := "| [deprecated flag](https://example.com/test) | `deprecated-flag` | | :warning: not all references removed
:information_source: deprecated on 2023-08-03 |" assert.Equal(t, expected, comment) }