From 39fb5cfbe02363aa38ea7a4b4ca7ba03580ead91 Mon Sep 17 00:00:00 2001 From: Jonas Franz Date: Sat, 23 Sep 2017 19:39:56 +0200 Subject: [PATCH] Adding crowdin branch support (#1) * Adding crowdin branch support Signed-off-by: Jonas Franz * Adding documentation for ignore_branche Signed-off-by: Jonas Franz --- DOCS.md | 1 + main.go | 14 ++++++++++++++ plugin.go | 11 ++++++++--- 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/DOCS.md b/DOCS.md index 9ac33dd..bdbd5f2 100644 --- a/DOCS.md +++ b/DOCS.md @@ -7,6 +7,7 @@ You must provide in your configuration: * `files` - Map of files to upload to Crowdin * key: the Crowdin file name * value: the real path the to file +* `ignore_branch` It will send the Drone branch to Crowdin if it is `false`. (Default: `false`) Information about API keys: https://support.crowdin.com/api/api-integration-setup/ ## Example 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