update.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. qlog "github.com/qiniu/log"
  10. "github.com/gogits/gogs/models"
  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 updateEnv(refName, oldCommitId, newCommitId string) {
  20. os.Setenv("refName", refName)
  21. os.Setenv("oldCommitId", oldCommitId)
  22. os.Setenv("newCommitId", newCommitId)
  23. qlog.Info("set envs:", refName, oldCommitId, newCommitId)
  24. }
  25. func runUpdate(c *cli.Context) {
  26. cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
  27. if cmd == "" {
  28. return
  29. }
  30. setup("log/update.log")
  31. args := c.Args()
  32. if len(args) != 3 {
  33. qlog.Fatal("received less 3 parameters")
  34. } else if args[0] == "" {
  35. qlog.Fatal("refName is empty, shouldn't use")
  36. }
  37. //updateEnv(args[0], args[1], args[2])
  38. userName := os.Getenv("userName")
  39. userId, _ := strconv.ParseInt(os.Getenv("userId"), 10, 64)
  40. //repoId := os.Getenv("repoId")
  41. repoUserName := os.Getenv("repoUserName")
  42. repoName := os.Getenv("repoName")
  43. models.Update(args[0], args[1], args[2], userName, repoUserName, repoName, userId)
  44. }