update.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package cmd
  5. import (
  6. "os"
  7. "strconv"
  8. "github.com/codegangsta/cli"
  9. "github.com/gogits/gogs/models"
  10. "github.com/gogits/gogs/modules/log"
  11. )
  12. var CmdUpdate = cli.Command{
  13. Name: "update",
  14. Usage: "This command should only be called by SSH shell",
  15. Description: `Update get pushed info and insert into database`,
  16. Action: runUpdate,
  17. Flags: []cli.Flag{},
  18. }
  19. func runUpdate(c *cli.Context) {
  20. cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
  21. if cmd == "" {
  22. return
  23. }
  24. setup("update.log")
  25. args := c.Args()
  26. if len(args) != 3 {
  27. log.GitLogger.Fatal("received less 3 parameters")
  28. } else if args[0] == "" {
  29. log.GitLogger.Fatal("refName is empty, shouldn't use")
  30. }
  31. userName := os.Getenv("userName")
  32. userId, _ := strconv.ParseInt(os.Getenv("userId"), 10, 64)
  33. repoUserName := os.Getenv("repoUserName")
  34. repoName := os.Getenv("repoName")
  35. if err := models.Update(args[0], args[1], args[2], userName, repoUserName, repoName, userId); err != nil {
  36. log.GitLogger.Fatal(err.Error())
  37. }
  38. }