mirror of
https://github.com/appleboy/drone-discord.git
synced 2026-06-04 18:33:47 +08:00
feat: support default message for GitHub Action
This commit is contained in:
@@ -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"),
|
||||
|
||||
@@ -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
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user