summaryrefslogtreecommitdiffstats
path: root/update.go
blob: 339b3ab94f80f9de19647029916e373453fc560e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main

import (
	"os"
	"strconv"

	"github.com/gogits/gogs/models"

	"github.com/codegangsta/cli"
	git "github.com/gogits/git"
)

var CmdUpdate = cli.Command{
	Name:  "update",
	Usage: "This command just should be called by ssh shell",
	Description: `
gogs serv provide access auth for repositories`,
	Action: runUpdate,
	Flags:  []cli.Flag{},
}

func runUpdate(*cli.Context) {
	userName := os.Getenv("userName")
	userId := os.Getenv("userId")
	repoId := os.Getenv("repoId")
	repoName := os.Getenv("repoName")

	f := models.RepoPath(userName, repoName)

	repo, err := git.OpenRepository(f)
	if err != nil {
		return
	}

	ref, err := repo.LookupReference("HEAD")
	if err != nil {
		return
	}

	lastCommit, err := repo.LookupCommit(ref.Oid)
	if err != nil {
		return
	}
	sUserId, _ := strconv.Atoi(userId)
	sRepoId, _ := strconv.Atoi(repoId)
	err = models.CommitRepoAction(int64(sUserId), userName,
		int64(sRepoId), repoName, lastCommit.Message())
	if err != nil {
		//TODO: log
	}
}