summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md2
-rw-r--r--bee.json3
-rw-r--r--gogs.go2
-rw-r--r--models/repo2.go65
-rw-r--r--modules/base/template.go1
-rw-r--r--modules/base/tool.go5
-rw-r--r--routers/repo/single.go14
-rw-r--r--templates/repo/single.tmpl22
8 files changed, 97 insertions, 17 deletions
diff --git a/README.md b/README.md
index f4250a47a4..d0a0c2054c 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a GitHub-like clone in the Go Programming Language.
Since we choose to use pure Go implmentation of Git manipulation, Gogs certainly supports **ALL platforms** that Go supports, including Linux, Max OS X, and Windows with **ZERO** dependency.
-##### Current version: 0.0.8 Alpha
+##### Current version: 0.0.9 Alpha
## Purpose
diff --git a/bee.json b/bee.json
index de211f7277..19efcbc205 100644
--- a/bee.json
+++ b/bee.json
@@ -12,7 +12,8 @@
"models": "",
"others": [
"modules",
- "$GOPATH/src/github.com/gogits/binding"
+ "$GOPATH/src/github.com/gogits/binding",
+ "$GOPATH/src/github.com/gogits/git"
]
},
"cmd_args": [
diff --git a/gogs.go b/gogs.go
index 2d5283f3af..6b587993a2 100644
--- 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
diff --git a/models/repo2.go b/models/repo2.go
index e3fdc2784b..0c17a58335 100644
--- a/models/repo2.go
+++ b/models/repo2.go
@@ -6,11 +6,22 @@ package models
import (
"path"
+ "strings"
"time"
- git "github.com/gogits/git"
+ "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
@@ -19,10 +30,26 @@ type RepoFile struct {
Size int64
}
-func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) {
- f := RepoPath(userName, reposName)
+func GetBranches(userName, reposName string) ([]string, error) {
+ repo, err := git.OpenRepository(RepoPath(userName, reposName))
+ if err != nil {
+ return nil, err
+ }
- repo, err := git.OpenRepository(f)
+ refs, err := repo.AllReferences()
+ if err != nil {
+ return nil, err
+ }
+
+ brs := make([]string, len(refs))
+ for i, ref := range refs {
+ brs[i] = ref.Name
+ }
+ return brs, nil
+}
+
+func GetReposFiles(userName, reposName, branchName, rpath string) ([]*RepoFile, error) {
+ repo, err := git.OpenRepository(RepoPath(userName, reposName))
if err != nil {
return nil, err
}
@@ -69,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
+}
diff --git a/modules/base/template.go b/modules/base/template.go
index b38ab140c9..1a0b5977e3 100644
--- a/modules/base/template.go
+++ b/modules/base/template.go
@@ -19,6 +19,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
"AppVer": func() string {
return AppVer
},
+ "AvatarLink": AvatarLink,
"str2html": Str2html,
"TimeSince": TimeSince,
"FileSize": FileSize,
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 10b3fee375..046b2c5174 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -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
diff --git a/routers/repo/single.go b/routers/repo/single.go
index 3541dac937..c4189ad6d0 100644
--- a/routers/repo/single.go
+++ b/routers/repo/single.go
@@ -33,6 +33,13 @@ func Single(ctx *middleware.Context, params martini.Params) {
ctx.Data["Reponame"] = params["reponame"]
ctx.Data["Branchname"] = params["branchname"]
+ brs, err := models.GetBranches(params["username"], params["reponame"])
+ if err != nil {
+ ctx.Handle(200, "repo.Single", err)
+ return
+ }
+ ctx.Data["Branches"] = brs
+
var treenames []string
Paths := make([]string, 0)
@@ -43,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
diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl
index b5207d0820..4c6c7dd941 100644
--- a/templates/repo/single.tmpl
+++ b/templates/repo/single.tmpl
@@ -5,21 +5,23 @@
<div id="gogs-body" class="container">
<div id="gogs-source">
<div class="source-toolbar">
+ {{ $username := .Username}}
+ {{ $reponame := .Reponame}}
+ {{ $branchname := .Branchname}}
+ {{ $treenames := .Treenames}}
+ {{ $repoLink := .RepositoryLink}}
+ {{ $n := len $treenames}}
<button class="btn btn-default pull-right"><i class="fa fa-plus-square"></i>Add File</button>
<div class="dropdown branch-switch">
- <a href="#" class="btn btn-success dropdown-toggle" data-toggle="dropdown"><i class="fa fa-chain"></i>master&nbsp;&nbsp;
+ <a href="#" class="btn btn-success dropdown-toggle" data-toggle="dropdown"><i class="fa fa-chain"></i>{{$branchname}}&nbsp;&nbsp;
<b class="caret"></b></a>
<ul class="dropdown-menu">
- <li><a class="current" href="/{{.RepositoryLink}}/tree/master">master</a></li>
- <li><a href="/{{.RepositoryLink}}/tree/develop">develop</a></li>
+ {{range .Branches}}
+ <li><a {{if eq . $branchname}}class="current" {{end}}href="/{{$repoLink}}/tree/{{.}}">{{.}}</a></li>
+ {{end}}
</ul>
</div>
{{$paths := .Paths}}
- {{ $username := .Username}}
- {{ $reponame := .Reponame}}
- {{ $branchname := .Branchname}}
- {{ $treenames := .Treenames}}
- {{ $n := len $treenames}}
{{ $l := Subtract $n 1}}
<ol class="breadcrumb">
<li class="root dir"><a href="/{{$username}}/{{$reponame}}/tree/{{$branchname}}">{{.Repository.Name}}</a></li>
@@ -34,10 +36,10 @@
</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">