From 1ab023c10dd92f9e37aea9f741a059244eed1a07 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 12 Oct 2019 23:33:06 +0800 Subject: [PATCH] chore: update drone env --- main.go | 34 +++++++++++++++++++++++++++------- plugin.go | 44 ++++++++++++++++++++++++++------------------ 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/main.go b/main.go index 140a801..4a6fa45 100644 --- a/main.go +++ b/main.go @@ -110,6 +110,11 @@ func main() { Usage: "git commit branch", EnvVar: "DRONE_COMMIT_BRANCH", }, + cli.StringFlag{ + Name: "commit.link", + Usage: "git commit link", + EnvVar: "DRONE_COMMIT_LINK", + }, cli.StringFlag{ Name: "commit.author", Usage: "git author name", @@ -157,6 +162,11 @@ func main() { Usage: "build tag", EnvVar: "DRONE_TAG", }, + cli.StringFlag{ + Name: "pull.request", + Usage: "pull request", + EnvVar: "DRONE_PULL_REQUEST", + }, cli.Float64Flag{ Name: "job.started", Usage: "job started", @@ -201,6 +211,11 @@ func main() { Usage: "The GitHub workspace path. Value: /github/workspace.", EnvVar: "GITHUB_WORKSPACE", }, + cli.StringFlag{ + Name: "deploy.to", + Usage: "Provides the target deployment environment for the running build. This value is only available to promotion and rollback pipelines.", + EnvVar: "DRONE_DEPLOY_TO", + }, } if err := app.Run(os.Args); err != nil { @@ -226,21 +241,26 @@ func run(c *cli.Context) error { Namespace: c.String("repo.namespace"), Name: c.String("repo.name"), }, + Commit: Commit{ + Sha: c.String("commit.sha"), + Ref: c.String("commit.ref"), + Branch: c.String("commit.branch"), + Link: c.String("commit.link"), + Author: c.String("commit.author"), + Email: c.String("commit.author.email"), + Avatar: c.String("commit.author.avatar"), + Message: c.String("commit.message"), + }, Build: Build{ Tag: c.String("build.tag"), Number: c.Int("build.number"), Event: c.String("build.event"), Status: c.String("build.status"), - Commit: c.String("commit.sha"), - RefSpec: c.String("commit.refspec"), - Branch: c.String("commit.branch"), - Author: c.String("commit.author"), - Email: c.String("commit.author.email"), - Avatar: c.String("commit.author.avatar"), - Message: c.String("commit.message"), Link: c.String("build.link"), Started: c.Float64("job.started"), Finished: c.Float64("job.finished"), + PR: c.String("pull.request"), + DeployTo: c.String("deploy.to"), }, Config: Config{ WebhookID: c.String("webhook-id"), diff --git a/plugin.go b/plugin.go index 8b3a5d7..01b1181 100644 --- a/plugin.go +++ b/plugin.go @@ -33,29 +33,36 @@ type ( EventPath string } - // Repo information + // Repo information. Repo struct { FullName string Namespace string Name string } - // Build information + // Commit information. + Commit struct { + Sha string + Ref string + Branch string + Link string + Author string + Avatar string + Email string + Message string + } + + // Build information. Build struct { Tag string Event string Number int - Commit string - RefSpec string - Branch string - Author string - Avatar string - Message string - Email string Status string Link string Started float64 Finished float64 + PR string + DeployTo string } // Config for the plugin. @@ -116,6 +123,7 @@ type ( Build Build Config Config Payload Payload + Commit Commit } ) @@ -287,27 +295,27 @@ func (p *Plugin) Template() EmbedObject { description := "" switch p.Build.Event { case "push": - description = fmt.Sprintf("%s pushed to %s", p.Build.Author, p.Build.Branch) + description = fmt.Sprintf("%s pushed to %s", p.Commit.Author, p.Commit.Branch) case "pull_request": branch := "" - if p.Build.RefSpec != "" { - branch = p.Build.RefSpec + if p.Commit.Ref != "" { + branch = p.Commit.Ref } else { - branch = p.Build.Branch + branch = p.Commit.Branch } - description = fmt.Sprintf("%s updated pull request %s", p.Build.Author, branch) + description = fmt.Sprintf("%s updated pull request %s", p.Commit.Author, branch) case "tag": - description = fmt.Sprintf("%s pushed tag %s", p.Build.Author, p.Build.Branch) + description = fmt.Sprintf("%s pushed tag %s", p.Commit.Author, p.Commit.Branch) } return EmbedObject{ - Title: p.Build.Message, + Title: p.Commit.Message, Description: description, URL: p.Build.Link, Color: p.Color(), Author: EmbedAuthorObject{ - Name: p.Build.Author, - IconURL: p.Build.Avatar, + Name: p.Commit.Author, + IconURL: p.Commit.Avatar, }, Footer: EmbedFooterObject{ Text: DroneDesc,