]> source.dussan.org Git - gitea.git/commitdiff
Add latest commit in repo viewer
authorUnknown <joe2010xtmf@163.com>
Mon, 17 Mar 2014 04:57:18 +0000 (00:57 -0400)
committerUnknown <joe2010xtmf@163.com>
Mon, 17 Mar 2014 04:57:18 +0000 (00:57 -0400)
gogs.go
models/repo2.go
modules/base/template.go
modules/base/tool.go
routers/repo/single.go
templates/repo/single.tmpl

diff --git a/gogs.go b/gogs.go
index 2d5283f3af844def8c5866af56a71eda14c72a99..6b587993a2da196280371c602b9b4fbf5dcdd196 100644 (file)
--- a/gogs.go
+++ b/gogs.go
@@ -20,7 +20,7 @@ import (
 // Test that go1.1 tag above is included in builds. main.go refers to this definition.
 const go11tag = true
 
-const APP_VER = "0.0.9.0316.1"
+const APP_VER = "0.0.9.0317.1"
 
 func init() {
        base.AppVer = APP_VER
index a8dbc44db9712e08602e7f3d6dcf1bedaf9db997..0c17a58335edb8e10627aafa7660732c7d6d5575 100644 (file)
@@ -6,11 +6,22 @@ package models
 
 import (
        "path"
+       "strings"
        "time"
 
+       "github.com/Unknwon/com"
+
        "github.com/gogits/git"
 )
 
+type Commit struct {
+       Author  string
+       Email   string
+       Date    time.Time
+       SHA     string
+       Message string
+}
+
 type RepoFile struct {
        *git.TreeEntry
        Path    string
@@ -85,3 +96,33 @@ func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile,
 
        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
+}
index b38ab140c9a8239783eca171ceeaa1c25d6e370f..1a0b5977e365e6c2ac2236dbd1c5c9863c86ebea 100644 (file)
@@ -19,6 +19,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
        "AppVer": func() string {
                return AppVer
        },
+       "AvatarLink": AvatarLink,
        "str2html":   Str2html,
        "TimeSince":  TimeSince,
        "FileSize":   FileSize,
index 10b3fee3753f490c6a572f90e8dcb0bad4dfe5eb..046b2c5174efd25ab7b7993b49b7ab66aba40d1e 100644 (file)
@@ -22,6 +22,11 @@ func EncodeMd5(str string) string {
        return hex.EncodeToString(m.Sum(nil))
 }
 
+// AvatarLink returns avatar link by given e-mail.
+func AvatarLink(email string) string {
+       return "http://1.gravatar.com/avatar/" + EncodeMd5(email)
+}
+
 // Seconds-based time units
 const (
        Minute = 60
index fd4d5290310253f08bfa441ab68dfd81797c7a39..10b2ae81075b449e0a187400b45320f6a3fb8f84 100644 (file)
@@ -50,6 +50,13 @@ func Single(ctx *middleware.Context, params martini.Params) {
                }
        }
 
+       commit, err := models.GetLastestCommit(params["username"], params["reponame"])
+       if err != nil {
+               ctx.Handle(200, "repo.Single", err)
+               return
+       }
+       ctx.Data["LatestCommit"] = commit
+
        ctx.Data["Paths"] = Paths
        ctx.Data["Treenames"] = treenames
        ctx.Data["IsRepoToolbarSource"] = true
index e1fb05bd03d5e663f64567339faca9a7b5b9db40..4c6c7dd941c2ee0475c87dc4a18220801cdada9a 100644 (file)
         </div>
         <div class="panel panel-default info-box">
             <div class="panel-heading info-head">
-                Merge branch 'release/1.1.1'
+                <a href="/{{$username}}/{{$reponame}}/commit/{{.LatestCommit.SHA}}">{{.LatestCommit.Message}}</a>
             </div>
             <div class="panel-body info-content">
-                slene authored 4 days ago
+                <a href="/user/{{.LatestCommit.Author}}">{{.LatestCommit.Author}}</a> <span class="text-muted">{{TimeSince .LatestCommit.Date}}</span>
             </div>
             <table class="panel-footer table file-list">
                 <thead class="hidden">