Skip to content

Commit

Permalink
Merge pull request #6 from sakajunquality/feature/use-event-lib
Browse files Browse the repository at this point in the history
use event libs
  • Loading branch information
sakajunquality authored Jan 22, 2019
2 parents 96eca95 + f786c44 commit 4a01558
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 66 deletions.
54 changes: 0 additions & 54 deletions flow/event.go

This file was deleted.

17 changes: 9 additions & 8 deletions flow/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"os"
"strings"

"github.com/sakajunquality/cloud-pubsub-events/cloudbuildevent"
"github.com/sakajunquality/flow/gitbot"
"github.com/sakajunquality/flow/slackbot"
)
Expand All @@ -19,19 +20,19 @@ type PullRequest struct {
err error
}

func (f *Flow) process(ctx context.Context, e Event) error {
if !e.isFinished() { // Notify only the finished
func (f *Flow) process(ctx context.Context, e cloudbuildevent.Event) error {
if !e.IsFinished() { // Notify only the finished
fmt.Fprintf(os.Stdout, "Build hasn't finished\n")
return nil
}

app, err := getApplicationByEventTriggerID(e.TriggerID)
app, err := getApplicationByEventTriggerID(*e.TriggerID)
if err != nil {
fmt.Fprintf(os.Stdout, "No app is configured for %s\n", e.TriggerID)
return nil
}

if !e.isSuuccess() { // CloudBuild Failure
if !e.IsSuuccess() { // CloudBuild Failure
return f.notifyFalure(e, "", nil)
}

Expand Down Expand Up @@ -117,7 +118,7 @@ func (f *Flow) createRelasePR(ctx context.Context, version string, a Application
return *prURL, nil
}

func (f *Flow) notifyRelasePR(e Event, prs PullRequests, app *Application) error {
func (f *Flow) notifyRelasePR(e cloudbuildevent.Event, prs PullRequests, app *Application) error {
var prURL string

for _, pr := range prs {
Expand All @@ -143,20 +144,20 @@ func (f *Flow) notifyRelasePR(e Event, prs PullRequests, app *Application) error
return slackbot.NewSlackMessage(f.slackBotToken, cfg.SlackNotifiyChannel, d).Post()
}

func (f *Flow) notifyDeploy(e Event) error {
func (f *Flow) notifyDeploy(e cloudbuildevent.Event) error {
d := slackbot.MessageDetail{
IsSuccess: true,
IsPrNotify: false,
LogURL: e.LogURL,
AppName: e.RepoName,
AppName: *e.RepoName,
TagName: e.TagName,
BranchName: e.BranchName,
}

return slackbot.NewSlackMessage(f.slackBotToken, cfg.SlackNotifiyChannel, d).Post()
}

func (f *Flow) notifyFalure(e Event, errorMessage string, app *Application) error {
func (f *Flow) notifyFalure(e cloudbuildevent.Event, errorMessage string, app *Application) error {
d := slackbot.MessageDetail{
IsSuccess: false,
LogURL: e.LogURL,
Expand Down
7 changes: 3 additions & 4 deletions flow/subscribe.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package flow

import (
"context"
"encoding/json"
"fmt"
"log"
"os"
"sync"

"cloud.google.com/go/pubsub"
"github.com/sakajunquality/cloud-pubsub-events/cloudbuildevent"
)

var (
Expand All @@ -31,9 +31,8 @@ func (f *Flow) subscribe(ctx context.Context, errCh chan error) {
}

err := subscription.Receive(ctx, func(ctx context.Context, msg *pubsub.Message) {
var e Event

if err := json.Unmarshal(msg.Data, &e); err != nil {
e, err := cloudbuildevent.ParseMessage(msg.Data)
if err != nil {
fmt.Fprintf(os.Stderr, "Error: could not decode message data: %#v", msg)
msg.Ack()
return
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ require (
github.com/nlopes/slack v0.4.0
github.com/pkg/errors v0.8.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/sakajunquality/cloud-pubsub-events v0.0.0-20190117094524-e3828a247582
github.com/stretchr/testify v1.2.2 // indirect
go.opencensus.io v0.17.0 // indirect
golang.org/x/net v0.0.0-20181017193950-04a2e542c03f // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
github.com/sakajunquality/cloud-pubsub-events v0.0.0-20190117094524-e3828a247582 h1:icL5nNiXcEVS61weueCXUI7O7mN4jQXIjjHU/OHyeQE=
github.com/sakajunquality/cloud-pubsub-events v0.0.0-20190117094524-e3828a247582/go.mod h1:ge90hWT8vT100pJ3wdBk9uYRyQ+KXj91+CuCFA9j5R8=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
go.opencensus.io v0.17.0 h1:2Cu88MYg+1LU+WVD+NWwYhyP0kKgRlN9QjWGaX0jKTE=
Expand Down

0 comments on commit 4a01558

Please sign in to comment.