feat: support default message for GitHub Action

This commit is contained in:
Bo-Yi Wu
2019-02-24 13:07:12 +08:00
parent 4aa0bd8fc6
commit 28fc4d6511
3 changed files with 32 additions and 10 deletions
+4 -2
View File
@@ -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"),
+25 -5
View File
@@ -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":
+3 -3
View File
@@ -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,