From 28fc4d6511a42ecad00bbf920b45dc1c2eff6159 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 24 Feb 2019 13:07:12 +0800 Subject: [PATCH] feat: support default message for GitHub Action --- main.go | 6 ++++-- plugin.go | 30 +++++++++++++++++++++++++----- plugin_test.go | 6 +++--- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index ad6496e..3abe8a1 100644 --- a/main.go +++ b/main.go @@ -217,8 +217,9 @@ func run(c *cli.Context) error { EventPath: c.String("github.event.path"), }, Repo: Repo{ - Owner: c.String("repo.owner"), - Name: c.String("repo.name"), + FullName: c.String("repo"), + Namespace: c.String("repo.namespace"), + Name: c.String("repo.name"), }, Build: Build{ Tag: c.String("build.tag"), @@ -242,6 +243,7 @@ func run(c *cli.Context) error { Message: c.StringSlice("message"), Color: c.String("color"), Drone: c.Bool("drone"), + GitHub: c.Bool("github"), }, Payload: Payload{ Wait: c.Bool("wait"), diff --git a/plugin.go b/plugin.go index 59ef18a..170ba89 100644 --- a/plugin.go +++ b/plugin.go @@ -31,8 +31,9 @@ type ( // Repo information Repo struct { - Owner string - Name string + FullName string + Namespace string + Name string } // Build information @@ -60,6 +61,7 @@ type ( Color string Message []string Drone bool + GitHub bool } // EmbedFooterObject for Embed Footer Structure. @@ -119,7 +121,7 @@ func (p *Plugin) Exec() error { } if p.Config.Drone && len(p.Config.Message) == 0 { - object := p.DroneTemplate() + object := p.Template() p.Payload.Embeds = []EmbedObject{object} err := p.Send() if err != nil { @@ -181,8 +183,26 @@ func (p *Plugin) DefaultTemplate(title string) EmbedObject { } } -// DroneTemplate is plugin default template for Drone CI. -func (p *Plugin) DroneTemplate() EmbedObject { +// Template is plugin default template for Drone CI or GitHub Action. +func (p *Plugin) Template() EmbedObject { + if p.Config.GitHub { + message := fmt.Sprintf("%s/%s triggered by %s (%s)", + p.Repo.FullName, + p.GitHub.Workflow, + p.Repo.Namespace, + p.GitHub.EventName, + ) + + return EmbedObject{ + Title: message, + Color: p.Color(), + Footer: EmbedFooterObject{ + Text: DroneDesc, + IconURL: DroneIconURL, + }, + } + } + description := "" switch p.Build.Event { case "push": diff --git a/plugin_test.go b/plugin_test.go index 2bbd87c..850534b 100644 --- a/plugin_test.go +++ b/plugin_test.go @@ -16,11 +16,11 @@ func TestMissingConfig(t *testing.T) { assert.NotNil(t, err) } -func TestDroneTemplate(t *testing.T) { +func TestTemplate(t *testing.T) { plugin := Plugin{ Repo: Repo{ - Name: "go-hello", - Owner: "appleboy", + Name: "go-hello", + Namespace: "appleboy", }, Build: Build{ Number: 101,