From c36d44a3661e8dc6bffa6112d00ea2c899d61ba4 Mon Sep 17 00:00:00 2001 From: Jacob Valdemar Date: Tue, 11 Aug 2020 12:57:39 +0200 Subject: [PATCH] remove filtering based on policies (#13) * remove filtering based on policies * Add message-template validation at start * spelling --- Makefile | 3 ++- issue_release_status.go | 14 +------------- main.go | 10 +++++++++- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/Makefile b/Makefile index 6e50884..a1cb978 100644 --- a/Makefile +++ b/Makefile @@ -16,4 +16,5 @@ start: --release-manager-auth-token $(HAMCTL_AUTH_TOKEN) \ --release-manager-url http://localhost:8081/ \ --github-private-key "`cat $(GITHUB_PRIVATE_KEY_PATH)`" \ - --github-integration-id 75542 + --github-integration-id 75542 \ + --message-template "`cat $(MESSAGE_TEMPLATE_PATH)`" diff --git a/issue_release_status.go b/issue_release_status.go index 41dfe7b..802933b 100644 --- a/issue_release_status.go +++ b/issue_release_status.go @@ -12,7 +12,6 @@ import ( "github.com/palantir/go-githubapp/githubapp" "github.com/pkg/errors" "github.com/rs/zerolog" - "github.com/rs/zerolog/log" ) type PRCreateHandler struct { @@ -108,12 +107,6 @@ func (handler *PRCreateHandler) Handle(ctx context.Context, eventType, deliveryI } var autoReleaseEnvironments []string - var botMessage string - - if len(policyResponse.AutoReleases) == 0 { - log.Debug().Msg("No auto-release policies was detected for this service.") - return nil - } for i := 0; i < len(policyResponse.AutoReleases); i++ { if policyResponse.AutoReleases[i].Branch == prBase { @@ -121,17 +114,12 @@ func (handler *PRCreateHandler) Handle(ctx context.Context, eventType, deliveryI } } - if len(autoReleaseEnvironments) == 0 { - log.Debug().Msg("No auto-release policies was detected for this base branch.") - return nil - } - messageData := BotMessageData{ Branch: prBase, AutoReleaseEnvironments: autoReleaseEnvironments, Template: handler.messageTemplate, } - botMessage, err = BotMessage(messageData) + botMessage, err := BotMessage(messageData) if err != nil { return errors.Wrapf(err, "creating bot message") } diff --git a/main.go b/main.go index 337d695..8103516 100644 --- a/main.go +++ b/main.go @@ -2,6 +2,7 @@ package main import ( "os" + "text/template" "time" "github.com/gregjones/httpcache" @@ -33,8 +34,15 @@ func main() { pflag.Parse() + // Flag validation if *releaseManagerAuthToken == "" { - logger.Error().Msgf("flag release-manager-auth-token is empty") + logger.Error().Msgf("flag 'release-manager-auth-token' is empty") + os.Exit(1) + return + } + _, err := template.New("flagValidation").Parse(*messageTemplate) + if err != nil { + logger.Error().Msgf("flag 'message-template' parsing error recieved: %v", err) os.Exit(1) return }