add commits

release/v1.15
Lunny Xiao 2014-03-17 23:04:49 +08:00
parent be8baea7ad
commit 45a6444b1e
4 changed files with 26 additions and 2 deletions

View File

@ -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()
}

View File

@ -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)
}

View File

@ -4,6 +4,11 @@
{{template "repo/toolbar" .}}
<div id="gogs-body" class="container">
<div id="gogs-commits">
<ul>
{{range .Commits}}
<li>{{.Committer.Name}} - {{.Id}} - {{.Message}} - {{.Committer.When}}</li>
{{end}}
</ul>
</div>
</div>
{{template "base/footer" .}}

2
web.go
View File

@ -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)