Browse Source

Add latest commit in repo viewer

tags/v0.9.99
Unknown 10 years ago
parent
commit
0f68930892
6 changed files with 57 additions and 3 deletions
  1. 1
    1
      gogs.go
  2. 41
    0
      models/repo2.go
  3. 1
    0
      modules/base/template.go
  4. 5
    0
      modules/base/tool.go
  5. 7
    0
      routers/repo/single.go
  6. 2
    2
      templates/repo/single.tmpl

+ 1
- 1
gogs.go View File

// Test that go1.1 tag above is included in builds. main.go refers to this definition. // Test that go1.1 tag above is included in builds. main.go refers to this definition.
const go11tag = true const go11tag = true


const APP_VER = "0.0.9.0316.1"
const APP_VER = "0.0.9.0317.1"


func init() { func init() {
base.AppVer = APP_VER base.AppVer = APP_VER

+ 41
- 0
models/repo2.go View File



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


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
}

+ 1
- 0
modules/base/template.go View File

"AppVer": func() string { "AppVer": func() string {
return AppVer return AppVer
}, },
"AvatarLink": AvatarLink,
"str2html": Str2html, "str2html": Str2html,
"TimeSince": TimeSince, "TimeSince": TimeSince,
"FileSize": FileSize, "FileSize": FileSize,

+ 5
- 0
modules/base/tool.go View File

return hex.EncodeToString(m.Sum(nil)) 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 // Seconds-based time units
const ( const (
Minute = 60 Minute = 60

+ 7
- 0
routers/repo/single.go View File

} }
} }


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["Paths"] = Paths
ctx.Data["Treenames"] = treenames ctx.Data["Treenames"] = treenames
ctx.Data["IsRepoToolbarSource"] = true ctx.Data["IsRepoToolbarSource"] = true

+ 2
- 2
templates/repo/single.tmpl View File

</div> </div>
<div class="panel panel-default info-box"> <div class="panel panel-default info-box">
<div class="panel-heading info-head"> <div class="panel-heading info-head">
Merge branch 'release/1.1.1'
<a href="/{{$username}}/{{$reponame}}/commit/{{.LatestCommit.SHA}}">{{.LatestCommit.Message}}</a>
</div> </div>
<div class="panel-body info-content"> <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> </div>
<table class="panel-footer table file-list"> <table class="panel-footer table file-list">
<thead class="hidden"> <thead class="hidden">

Loading…
Cancel
Save