|
|
@ -6,11 +6,22 @@ package models |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
"path" |
|
|
|
"path" |
|
|
|
|
|
|
|
"strings" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/Unknwon/com" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/gogits/git" |
|
|
|
"github.com/gogits/git" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type Commit struct { |
|
|
|
|
|
|
|
Author string |
|
|
|
|
|
|
|
Email string |
|
|
|
|
|
|
|
Date time.Time |
|
|
|
|
|
|
|
SHA string |
|
|
|
|
|
|
|
Message string |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
type RepoFile struct { |
|
|
|
type RepoFile struct { |
|
|
|
*git.TreeEntry |
|
|
|
*git.TreeEntry |
|
|
|
Path string |
|
|
|
Path string |
|
|
@ -85,3 +96,33 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, |
|
|
|
|
|
|
|
|
|
|
|
return append(repodirs, repofiles...), nil |
|
|
|
return append(repodirs, repofiles...), nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func GetLastestCommit(userName, repoName string) (*Commit, error) { |
|
|
|
|
|
|
|
stdout, _, err := com.ExecCmd("git", "--git-dir="+RepoPath(userName, repoName), "log", "-1") |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
commit := new(Commit) |
|
|
|
|
|
|
|
for _, line := range strings.Split(stdout, "\n") { |
|
|
|
|
|
|
|
if len(line) == 0 { |
|
|
|
|
|
|
|
continue |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
switch { |
|
|
|
|
|
|
|
case line[0] == 'c': |
|
|
|
|
|
|
|
commit.SHA = line[7:] |
|
|
|
|
|
|
|
case line[0] == 'A': |
|
|
|
|
|
|
|
infos := strings.SplitN(line, " ", 3) |
|
|
|
|
|
|
|
commit.Author = infos[1] |
|
|
|
|
|
|
|
commit.Email = infos[2][1 : len(infos[2])-1] |
|
|
|
|
|
|
|
case line[0] == 'D': |
|
|
|
|
|
|
|
commit.Date, err = time.Parse("Mon Jan 02 15:04:05 2006 -0700", line[8:]) |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
|
|
|
|
return nil, err |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
case line[:4] == " ": |
|
|
|
|
|
|
|
commit.Message = line[4:] |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return commit, nil |
|
|
|
|
|
|
|
} |
|
|
|