From 930f3d2051011df6f993de9fd01255a529680a3f Mon Sep 17 00:00:00 2001 From: jamie1192 Date: Sun, 28 Feb 2021 12:12:52 +1100 Subject: [PATCH] [#20] convert bool inputs to "yes|no" - as per Steplib PR recommendation - fix step.yml typo --- config.go | 8 ++++---- main.go | 12 ++++++++---- main_test.go | 22 +++++++++++----------- step.yml | 26 +++++++++++++++++++------- 4 files changed, 42 insertions(+), 26 deletions(-) diff --git a/config.go b/config.go index 7772efe..b70c3b7 100644 --- a/config.go +++ b/config.go @@ -24,10 +24,10 @@ type config struct { SectionSubtitle string `env:"section_subtitle"` SectionText string `env:"section_text"` SectionHeaderImage string `env:"section_header_image"` - EnablePrimarySectionMarkdown bool `env:"enable_primary_section_markdown"` - EnableBuildFactsMarkdown bool `env:"enable_build_status_facts_markdown"` - EnableDefaultActions bool `env:"enable_default_actions"` - EnableDebug bool `env:"enable_debug"` + EnablePrimarySectionMarkdown string `env:"enable_primary_section_markdown"` + EnableBuildFactsMarkdown string `env:"enable_build_status_facts_markdown"` + EnableDefaultActions string `env:"enable_default_actions"` + EnableDebug string `env:"enable_debug"` RepoURL string `env:"repository_url"` Actions string `env:"actions"` } diff --git a/main.go b/main.go index c9f561d..61d49b7 100644 --- a/main.go +++ b/main.go @@ -29,6 +29,10 @@ func optionalUserValue(defaultValue, userValue string) string { return userValue } +func valueOptionToBool(userValue string) bool { + return userValue == "yes" +} + func newMessage(cfg config, buildSuccessful bool) Message { message := Message{} message.Type = "MessageCard" @@ -52,7 +56,7 @@ func newMessage(cfg config, buildSuccessful bool) Message { // MessageCard Actions actions := []OpenURIAction{} - if cfg.EnableDefaultActions { + if valueOptionToBool(cfg.EnableDefaultActions) { goToRepoAction := buildURIAction(Action{ Text: "Go To Repo", Targets: []ActionTarget{ @@ -87,7 +91,7 @@ func buildPrimarySection(cfg config) Section { section.ActivitySubtitle = cfg.SectionSubtitle section.Text = cfg.SectionText section.ActivityImage = cfg.SectionHeaderImage - section.Markdown = cfg.EnablePrimarySectionMarkdown + section.Markdown = valueOptionToBool(cfg.EnablePrimarySectionMarkdown) return section } @@ -129,7 +133,7 @@ func buildFactsSection(cfg config, buildSuccessful bool) Section { } return Section{ - Markdown: cfg.EnableBuildFactsMarkdown, + Markdown: valueOptionToBool(cfg.EnableBuildFactsMarkdown), Facts: []Fact{buildStatusFact, buildNumberFact, buildBranchFact, buildTimeFact, workflowFact}, } } @@ -191,7 +195,7 @@ func main() { stepconf.Print(cfg) message := newMessage(cfg, buildSucceeded) - if err := postMessage(cfg.WebhookURL, message, cfg.EnableDebug); err != nil { + if err := postMessage(cfg.WebhookURL, message, valueOptionToBool(cfg.EnableDebug)); err != nil { fmt.Println(fmt.Sprintf("Error: %s", err)) os.Exit(1) } diff --git a/main_test.go b/main_test.go index 86cd156..f0b7e89 100644 --- a/main_test.go +++ b/main_test.go @@ -26,10 +26,10 @@ var mockConfig = config{ SectionSubtitle: "Commit message", SectionText: "Commit message body", SectionHeaderImage: "", - EnablePrimarySectionMarkdown: false, - EnableBuildFactsMarkdown: false, - EnableDefaultActions: true, - EnableDebug: false, + EnablePrimarySectionMarkdown: "no", + EnableBuildFactsMarkdown: "no", + EnableDefaultActions: "yes", + EnableDebug: "no", RepoURL: "https://www.github.com/username/repo", Actions: `[ { @@ -86,7 +86,7 @@ func TestBuildPrimarySection(t *testing.T) { SectionTitle: "Some author", SectionSubtitle: "A commit message", SectionText: "The commits message body", - EnablePrimarySectionMarkdown: false, + EnablePrimarySectionMarkdown: "no", } var tests = []struct { input config @@ -98,7 +98,7 @@ func TestBuildPrimarySection(t *testing.T) { ActivityTitle: defaultValuesConfig.SectionTitle, ActivitySubtitle: defaultValuesConfig.SectionSubtitle, Text: defaultValuesConfig.SectionText, - Markdown: defaultValuesConfig.EnablePrimarySectionMarkdown, + Markdown: valueOptionToBool(defaultValuesConfig.EnablePrimarySectionMarkdown), }, }, } @@ -122,7 +122,7 @@ func TestBuildFactsSection(t *testing.T) { mockConfig, true, Section{ - Markdown: mockConfig.EnableBuildFactsMarkdown, + Markdown: valueOptionToBool(mockConfig.EnableBuildFactsMarkdown), Facts: []Fact{ { Name: "Build Status", @@ -152,7 +152,7 @@ func TestBuildFactsSection(t *testing.T) { mockConfig, false, Section{ - Markdown: mockConfig.EnableBuildFactsMarkdown, + Markdown: valueOptionToBool(mockConfig.EnableBuildFactsMarkdown), Facts: []Fact{ { Name: "Build Status", @@ -210,7 +210,7 @@ func TestNewMessage(t *testing.T) { Value: mockConfig.Workflow, }, }, - Markdown: mockConfig.EnableBuildFactsMarkdown, + Markdown: valueOptionToBool(mockConfig.EnableBuildFactsMarkdown), HeroImage: HeroImage{}, } @@ -237,7 +237,7 @@ func TestNewMessage(t *testing.T) { Value: mockConfig.Workflow, }, }, - Markdown: mockConfig.EnableBuildFactsMarkdown, + Markdown: valueOptionToBool(mockConfig.EnableBuildFactsMarkdown), HeroImage: HeroImage{}, } @@ -245,7 +245,7 @@ func TestNewMessage(t *testing.T) { ActivityTitle: mockConfig.SectionTitle, ActivitySubtitle: mockConfig.SectionSubtitle, ActivityImage: mockConfig.SectionHeaderImage, - Markdown: mockConfig.EnablePrimarySectionMarkdown, + Markdown: valueOptionToBool(mockConfig.EnablePrimarySectionMarkdown), Text: mockConfig.SectionText, HeroImage: HeroImage{}, } diff --git a/step.yml b/step.yml index c49500c..68a2b14 100644 --- a/step.yml +++ b/step.yml @@ -1,6 +1,6 @@ --- title: Microsoft Teams Integration -summary: Allows you to recieve build status updates on Microsoft Team using Incoming Webhooks +summary: Allows you to receive build status updates on Microsoft Team using Incoming Webhooks description: | Uses Incoming Webhooks feature in Microsft Teams to send updates on your builds website: https://github.com/amrfarid140/bitrise-step-microsoft-teams-integration @@ -29,7 +29,7 @@ inputs: If no value is given, the default value will be the `BITRISE_APP_TITLE`. - - enable_debug: false + - enable_debug: "no" opts: title: "Enable debug logging" summary: "Toggles whether to log debug info to the build output" @@ -37,6 +37,9 @@ inputs: Enables debug logging to the Bitrise console. WARNING: This will output the JSON value of the Teams Webhook body, be mindful of what is output here. + value_options: + - "yes" + - "no" - success_theme_color: 359914 opts: @@ -58,7 +61,7 @@ inputs: Defaults to `E04504` if not overridden. - - enable_primary_section_markdown: true + - enable_primary_section_markdown: "yes" opts: category: "Markdown Rules" title: "Primary Section Markdown" @@ -70,8 +73,11 @@ inputs: * section_title * section_subtitle * section_text + value_options: + - "yes" + - "no" - - enable_build_status_facts_markdown: false + - enable_build_status_facts_markdown: "no" opts: category: "Markdown Rules" title: "Build Status Facts Markdown" @@ -85,6 +91,9 @@ inputs: * Git Branch * Build Triggered * Workflow + value_options: + - "yes" + - "no" - section_title: $GIT_CLONE_COMMIT_AUTHOR_NAME opts: @@ -116,7 +125,7 @@ inputs: this will be set to the commit message body that triggered the build. If desired, this is the perfect place to include release notes via the `generate-changelog` Bitrise step, however - setting `enable_primary_section_markdown` to `true` may be necessary to properly format the changelog content. + setting `enable_primary_section_markdown` to `yes` may be necessary to properly format the changelog content. - section_header_image: opts: @@ -124,7 +133,7 @@ inputs: title: "Section Image" summary: "Image that is displayed within the MessageCard Section `activityImage`" - - enable_default_actions: true + - enable_default_actions: "yes" opts: category: "MessageCard Actions" title: "Default MessageCard Actions" @@ -132,6 +141,9 @@ inputs: description: | Allows for disabling the default 'Go To Repo' and 'Go To Build' MessageCard Actions if you wish to provide only your own custom actions via the `actions` step input (up to a limit of 4 actions in total). + value_options: + - "yes" + - "no" - actions: "[]" opts: @@ -142,7 +154,7 @@ inputs: A stringified JSON object array of additional custom actions to display on the card. The maximum amount of actions a single card can display is 4, 2 of which are used if - `enable_default_actions` is set to `true`. + `enable_default_actions` is set to `yes`. Each action button object must have a `text` key/value pair, and a list of `target` objects which define the `uri`, specific to which platform-client (`os` value) the Teams message is viewed on.