From 45a6444b1ead3ebedcf79204cabe44df672f59d5 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 17 Mar 2014 23:04:49 +0800 Subject: [PATCH] add commits --- models/repo2.go | 12 ++++++++++++ routers/repo/single.go | 9 ++++++++- templates/repo/commits.tmpl | 5 +++++ web.go | 2 +- 4 files changed, 26 insertions(+), 2 deletions(-) diff --git a/models/repo2.go b/models/repo2.go index 91c057808..8356c52de 100644 --- a/models/repo2.go +++ b/models/repo2.go @@ -191,3 +191,15 @@ func GetLastestCommit(userName, repoName string) (*Commit, error) { } return commit, nil } + +func GetCommits(userName, reposName, branchname string) ([]*git.Commit, error) { + repo, err := git.OpenRepository(RepoPath(userName, reposName)) + if err != nil { + return nil, err + } + r, err := repo.LookupReference(fmt.Sprintf("refs/heads/%s", branchname)) + if err != nil { + return nil, err + } + return r.AllCommits() +} diff --git a/routers/repo/single.go b/routers/repo/single.go index cf64cc6b5..eda71f292 100644 --- a/routers/repo/single.go +++ b/routers/repo/single.go @@ -131,8 +131,15 @@ func Setting(ctx *middleware.Context, params martini.Params) { ctx.Render.HTML(200, "repo/setting", ctx.Data) } -func Commits(ctx *middleware.Context) { +func Commits(ctx *middleware.Context, params martini.Params) { ctx.Data["IsRepoToolbarCommits"] = true + commits, err := models.GetCommits(params["username"], + params["reponame"], params["branchname"]) + if err != nil { + ctx.Render.Error(404) + return + } + ctx.Data["Commits"] = commits ctx.Render.HTML(200, "repo/commits", ctx.Data) } diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index 7ebe68b6a..9190a030a 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -4,6 +4,11 @@ {{template "repo/toolbar" .}}
+
    + {{range .Commits}} +
  • {{.Committer.Name}} - {{.Id}} - {{.Message}} - {{.Committer.When}}
  • + {{end}} +
{{template "base/footer" .}} \ No newline at end of file diff --git a/web.go b/web.go index b1399953b..2177d5662 100644 --- a/web.go +++ b/web.go @@ -74,7 +74,7 @@ func runWeb(*cli.Context) { m.Post("/:username/:reponame/settings", middleware.SignInRequire(true), middleware.RepoAssignment(true), repo.SettingPost) m.Get("/:username/:reponame/settings", middleware.SignInRequire(true), middleware.RepoAssignment(true), repo.Setting) - m.Get("/:username/:reponame/commits", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Commits) + m.Get("/:username/:reponame/commits/:branchname", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Commits) m.Get("/:username/:reponame/issues", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Issues) m.Get("/:username/:reponame/pulls", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Pulls) m.Get("/:username/:reponame/branches", middleware.SignInRequire(false), middleware.RepoAssignment(true), repo.Branches)