From 48b2425c1d49560094b2935e6451d55cd5aa1f1a Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 16 Mar 2014 11:30:35 -0400 Subject: Push feed --- modules/base/tool.go | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'modules') diff --git a/modules/base/tool.go b/modules/base/tool.go index 3f8b8ffa..5746cc8f 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -7,6 +7,7 @@ package base import ( "crypto/md5" "encoding/hex" + "encoding/json" "fmt" "math" "strings" @@ -235,6 +236,7 @@ type Actioner interface { GetOpType() int GetActUserName() string GetRepoName() string + GetContent() string } // ActionIcon accepts a int that represents action operation type @@ -243,13 +245,19 @@ func ActionIcon(opType int) string { switch opType { case 1: // Create repository. return "plus-circle" + case 5: // Commit repository. + return "arrow-circle-o-right" default: return "invalid type" } } const ( - CreateRepoTpl = `%s created repository %s` + TPL_CREATE_REPO = `%s created repository %s` + TPL_COMMIT_REPO = `%s pushed to %s at %s/%s +` ) // ActionDesc accepts int that represents action operation type @@ -257,9 +265,17 @@ const ( func ActionDesc(act Actioner) string { actUserName := act.GetActUserName() repoName := act.GetRepoName() + content := act.GetContent() switch act.GetOpType() { case 1: // Create repository. - return fmt.Sprintf(CreateRepoTpl, actUserName, actUserName, actUserName, repoName, repoName) + return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, actUserName, repoName, repoName) + case 5: // Commit repository. + var commits [][]string + if err := json.Unmarshal([]byte(content), &commits); err != nil { + return err.Error() + } + return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, actUserName, repoName, "master", "master", actUserName, repoName, actUserName, repoName, + actUserName, repoName, commits[0][0], commits[0][0][:7], commits[0][1]) default: return "invalid type" } -- cgit v1.2.3 From ec65be79f0337b11c01121eae9fd54fe49bee830 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sun, 16 Mar 2014 12:07:35 -0400 Subject: Fix commit feed ui --- gogs.go | 2 +- modules/base/tool.go | 17 ++++++++++------- public/css/gogs.css | 6 ++++++ routers/user/user.go | 2 +- templates/user/profile.tmpl | 3 ++- 5 files changed, 20 insertions(+), 10 deletions(-) (limited to 'modules') diff --git a/gogs.go b/gogs.go index 9d1f2032..2d5283f3 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.8.0316.1" +const APP_VER = "0.0.9.0316.1" func init() { base.AppVer = APP_VER diff --git a/modules/base/tool.go b/modules/base/tool.go index 5746cc8f..10b3fee3 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -5,6 +5,7 @@ package base import ( + "bytes" "crypto/md5" "encoding/hex" "encoding/json" @@ -253,16 +254,14 @@ func ActionIcon(opType int) string { } const ( - TPL_CREATE_REPO = `%s created repository %s` - TPL_COMMIT_REPO = `%s pushed to %s at %s/%s -` + TPL_CREATE_REPO = `%s created repository %s` + TPL_COMMIT_REPO = `%s pushed to %s at %s/%s%s` + TPL_COMMIT_REPO_LI = `
user-avatar %s %s
` ) // ActionDesc accepts int that represents action operation type // and returns the description. -func ActionDesc(act Actioner) string { +func ActionDesc(act Actioner, avatarLink string) string { actUserName := act.GetActUserName() repoName := act.GetRepoName() content := act.GetContent() @@ -274,8 +273,12 @@ func ActionDesc(act Actioner) string { if err := json.Unmarshal([]byte(content), &commits); err != nil { return err.Error() } + buf := bytes.NewBuffer([]byte("\n")) + for _, commit := range commits { + buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, avatarLink, actUserName, repoName, commit[0], commit[0][:7], commit[1]) + "\n") + } return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, actUserName, repoName, "master", "master", actUserName, repoName, actUserName, repoName, - actUserName, repoName, commits[0][0], commits[0][0][:7], commits[0][1]) + buf.String()) default: return "invalid type" } diff --git a/public/css/gogs.css b/public/css/gogs.css index 89da6055..45ce5d21 100755 --- a/public/css/gogs.css +++ b/public/css/gogs.css @@ -228,6 +228,12 @@ html, body { border-radius: 6px; } +#gogs-user-avatar-commit { + width: 16px; + height: 16px; + border-radius: 2px; +} + #gogs-user-name { margin-top: 20px; font-size: 1.6em; diff --git a/routers/user/user.go b/routers/user/user.go index 0ff5058d..c43cf84a 100644 --- a/routers/user/user.go +++ b/routers/user/user.go @@ -195,7 +195,7 @@ func Feeds(ctx *middleware.Context, form auth.FeedsForm) { feeds := make([]string, len(actions)) for i := range actions { feeds[i] = fmt.Sprintf(feedTpl, base.ActionIcon(actions[i].OpType), - base.TimeSince(actions[i].Created), base.ActionDesc(actions[i])) + base.TimeSince(actions[i].Created), base.ActionDesc(actions[i], ctx.User.AvatarLink())) } ctx.Render.JSON(200, &feeds) } diff --git a/templates/user/profile.tmpl b/templates/user/profile.tmpl index 84d3b13c..24ae76fe 100644 --- a/templates/user/profile.tmpl +++ b/templates/user/profile.tmpl @@ -32,10 +32,11 @@ {{if eq .TabName "activity"}}
    + {{$avatarLink := .Owner.AvatarLink}} {{range .Feeds}}
  • -
    {{TimeSince .Created}}
    {{ActionDesc . | str2html}}
    +
    {{TimeSince .Created}}
    {{ActionDesc . $avatarLink | str2html}}
  • {{else}} -- 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 'modules') 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 'modules') 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 @@