From cad7d92b58248acba9e92b8660fdd11b9058dc47 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sat, 17 Jun 2017 02:42:05 -0500 Subject: [PATCH] add commit ref (#1) * add commit ref Signed-off-by: Bo-Yi Wu * update to RefSpec Signed-off-by: Bo-Yi Wu --- main.go | 6 ++++++ plugin.go | 9 ++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index a1ed436..1201f88 100644 --- a/main.go +++ b/main.go @@ -85,6 +85,11 @@ func main() { Usage: "git commit sha", EnvVar: "DRONE_COMMIT_SHA", }, + cli.StringFlag{ + Name: "commit.refspec", + Usage: "git commit ref spec", + EnvVar: "DRONE_COMMIT_REFSPEC", + }, cli.StringFlag{ Name: "commit.branch", Value: "master", @@ -173,6 +178,7 @@ func run(c *cli.Context) error { 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"), diff --git a/plugin.go b/plugin.go index 029ceb1..60f0c3e 100644 --- a/plugin.go +++ b/plugin.go @@ -26,6 +26,7 @@ type ( Event string Number int Commit string + RefSpec string Branch string Author string Avatar string @@ -171,7 +172,13 @@ func (p *Plugin) DroneTemplate() EmbedObject { case "push": description = fmt.Sprintf("%s pushed to %s", p.Build.Author, p.Build.Branch) case "pull_request": - description = fmt.Sprintf("%s created pull request %s", p.Build.Author, p.Build.Branch) + branch := "" + if p.Build.RefSpec != "" { + branch = p.Build.RefSpec + } else { + branch = p.Build.Branch + } + description = fmt.Sprintf("%s updated pull request %s", p.Build.Author, branch) case "tag": description = fmt.Sprintf("%s pushed tag %s", p.Build.Author, p.Build.Branch) }