From 200940f63792a5fcb676867fbe98dbe86f3e54ae Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Sat, 23 Sep 2017 19:30:22 +0200 Subject: [PATCH] Adding crowdin branch support Signed-off-by: Jonas Franz --- main.go | 14 ++++++++++++++ plugin.go | 11 ++++++++--- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/main.go b/main.go index 5fe9d3c..9162c98 100644 --- a/main.go +++ b/main.go @@ -33,6 +33,17 @@ func main() { EnvVar: "PLUGIN_FILES", Value: &StringMapFlag{}, }, + cli.StringFlag{ + Name: "commit.branch", + Value: "master", + Usage: "git commit branch", + EnvVar: "DRONE_COMMIT_BRANCH", + }, + cli.BoolFlag{ + Name: "ignore-branch", + Usage: "if true it will not pass the branch to crowdin", + EnvVar: "PLUGIN_IGNORE_BRANCH", + }, } if err := app.Run(os.Args); err != nil { log.Fatal(err) @@ -47,5 +58,8 @@ func run(c *cli.Context) error { Key: c.String("project-key"), }, } + if !c.Bool("ignore-branch") { + plugin.Branch = c.String("commit.branch") + } return plugin.Exec() } diff --git a/plugin.go b/plugin.go index 53ee0da..7714b0c 100644 --- a/plugin.go +++ b/plugin.go @@ -26,6 +26,7 @@ type ( Plugin struct { Config Config Files Files + Branch string } ) @@ -57,9 +58,13 @@ func (p Plugin) Exec() error { if _, err = io.Copy(part, file); err != nil { return err } - if err = writer.Close(); err != nil { - return err - } + } + // Adding branch if it is not ignored + if p.Branch != "" { + writer.WriteField("branch", p.Branch) + } + if err := writer.Close(); err != nil { + return err } var req *http.Request var err error