Skip to content

Commit

Permalink
remove filtering based on policies (#13)
Browse files Browse the repository at this point in the history
* remove filtering based on policies

* Add message-template validation at start

* spelling
  • Loading branch information
JacobValdemar authored Aug 11, 2020
1 parent c617f32 commit c36d44a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 15 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)`"
14 changes: 1 addition & 13 deletions issue_release_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -108,30 +107,19 @@ 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 {
autoReleaseEnvironments = append(autoReleaseEnvironments, policyResponse.AutoReleases[i].Environment)
}
}

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")
}
Expand Down
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"os"
"text/template"
"time"

"github.com/gregjones/httpcache"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit c36d44a

Please sign in to comment.