Adding crowdin branch support

Signed-off-by: Jonas Franz <info@jonasfranz.de>
pull/1/head
Jonas Franz 7 years ago
parent 7779b60987
commit 200940f637
  1. 14
      main.go
  2. 9
      plugin.go

@ -33,6 +33,17 @@ func main() {
EnvVar: "PLUGIN_FILES", EnvVar: "PLUGIN_FILES",
Value: &StringMapFlag{}, 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 { if err := app.Run(os.Args); err != nil {
log.Fatal(err) log.Fatal(err)
@ -47,5 +58,8 @@ func run(c *cli.Context) error {
Key: c.String("project-key"), Key: c.String("project-key"),
}, },
} }
if !c.Bool("ignore-branch") {
plugin.Branch = c.String("commit.branch")
}
return plugin.Exec() return plugin.Exec()
} }

@ -26,6 +26,7 @@ type (
Plugin struct { Plugin struct {
Config Config Config Config
Files Files Files Files
Branch string
} }
) )
@ -57,9 +58,13 @@ func (p Plugin) Exec() error {
if _, err = io.Copy(part, file); err != nil { if _, err = io.Copy(part, file); err != nil {
return err 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 req *http.Request
var err error var err error

Loading…
Cancel
Save