From 685631627e5c4db881160bfc9b39dc45143989f6 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 16 Mar 2014 23:43:22 -0400 Subject: Show branches in repo viewer --- routers/repo/single.go | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'routers/repo/single.go') diff --git a/routers/repo/single.go b/routers/repo/single.go index 6bf03ca2..fd4d5290 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) -- cgit v1.2.3 From 0f68930892bc49966769f8931e9a531b37dacb3b Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 17 Mar 2014 00:57:18 -0400 Subject: Add latest commit in repo viewer --- gogs.go | 2 +- models/repo2.go | 41 +++++++++++++++++++++++++++++++++++++++++ modules/base/template.go | 1 + modules/base/tool.go | 5 +++++ routers/repo/single.go | 7 +++++++ templates/repo/single.tmpl | 4 ++-- 6 files changed, 57 insertions(+), 3 deletions(-) (limited to 'routers/repo/single.go') diff --git a/gogs.go b/gogs.go index 2d5283f3..6b587993 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 a8dbc44d..0c17a583 100644 --- a/models/repo2.go +++ b/models/repo2.go @@ -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 +} diff --git a/modules/base/template.go b/modules/base/template.go index b38ab140..1a0b5977 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 10b3fee3..046b2c51 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 fd4d5290..10b2ae81 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -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 diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl index e1fb05bd..4c6c7dd9 100644 --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@ -36,10 +36,10 @@
- Merge branch 'release/1.1.1' + {{.LatestCommit.Message}}
- slene authored 4 days ago + {{.LatestCommit.Author}} {{TimeSince .LatestCommit.Date}}
-- cgit v1.2.3 From c101471bdfd0a802e66adfb7402dbd980812da30 Mon Sep 17 00:00:00 2001 From: FuXiaoHei Date: Mon, 17 Mar 2014 13:12:28 +0800 Subject: ui update, repo-assignment panic bug fix --- modules/middleware/repo.go | 2 +- public/css/gogs.css | 1 + routers/repo/single.go | 2 -- templates/base/head.tmpl | 4 +++- templates/repo/toolbar.tmpl | 3 ++- 5 files changed, 7 insertions(+), 5 deletions(-) (limited to 'routers/repo/single.go') diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index 8cdc6df7..7a415736 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -24,7 +24,6 @@ func RepoAssignment(redirect bool) martini.Handler { // get repository owner ctx.Repo.IsOwner = ctx.IsSigned && ctx.User.LowerName == params["username"] - ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner if !ctx.Repo.IsOwner { user, err = models.GetUserByName(params["username"]) @@ -70,5 +69,6 @@ func RepoAssignment(redirect bool) martini.Handler { ctx.Data["Owner"] = user ctx.Data["Title"] = user.Name + "/" + repo.Name ctx.Data["RepositoryLink"] = ctx.Data["Title"] + ctx.Data["IsRepositoryOwner"] = ctx.Repo.IsOwner } } diff --git a/public/css/gogs.css b/public/css/gogs.css index 2c05d27e..f98cf7a1 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -10,6 +10,7 @@ body { html, body { height: 100%; + font-family: Helvetica, Arial, sans-serif; } /* override bs3 */ diff --git a/routers/repo/single.go b/routers/repo/single.go index 6bf03ca2..3541dac9 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -46,7 +46,6 @@ func Single(ctx *middleware.Context, params martini.Params) { ctx.Data["Paths"] = Paths ctx.Data["Treenames"] = treenames ctx.Data["IsRepoToolbarSource"] = true - ctx.Data["IsRepositoryOwner"] = strings.ToLower(params["username"]) == ctx.User.LowerName ctx.Data["Files"] = files ctx.Render.HTML(200, "repo/single", ctx.Data) } @@ -63,7 +62,6 @@ func Setting(ctx *middleware.Context, params martini.Params) { ctx.Data["Title"] = title + " - settings" ctx.Data["IsRepoToolbarSetting"] = true - ctx.Data["IsRepositoryOwner"] = strings.ToLower(params["username"]) == ctx.User.LowerName ctx.Render.HTML(200, "repo/setting", ctx.Data) } diff --git a/templates/base/head.tmpl b/templates/base/head.tmpl index da100975..f02ea095 100644 --- a/templates/base/head.tmpl +++ b/templates/base/head.tmpl @@ -3,7 +3,9 @@ - + + + diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index 4a0b60ad..3729edaf 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -5,8 +5,9 @@ + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +{{template "base/footer" .}} \ No newline at end of file diff --git a/templates/repo/single.tmpl b/templates/repo/single.tmpl index 4c6c7dd9..153910f7 100644 --- a/templates/repo/single.tmpl +++ b/templates/repo/single.tmpl @@ -24,13 +24,15 @@ {{$paths := .Paths}} {{ $l := Subtract $n 1}} @@ -43,20 +45,21 @@ - - - - - - + + + + + + - {{range .Files}} - - - + + - + - + - - {{end}} + + + {{end}} diff --git a/templates/repo/toolbar.tmpl b/templates/repo/toolbar.tmpl index 3729edaf..49a37ef4 100644 --- a/templates/repo/toolbar.tmpl +++ b/templates/repo/toolbar.tmpl @@ -4,10 +4,10 @@ -- cgit v1.2.3