Browse Source

add commits

for-closed-social
Lunny Xiao 10 years ago
parent
commit
45a6444b1e
4 changed files with 26 additions and 2 deletions
  1. +12
    -0
      models/repo2.go
  2. +8
    -1
      routers/repo/single.go
  3. +5
    -0
      templates/repo/commits.tmpl
  4. +1
    -1
      web.go

+ 12
- 0
models/repo2.go 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()
}

+ 8
- 1
routers/repo/single.go 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)
}

+ 5
- 0
templates/repo/commits.tmpl 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" .}}

+ 1
- 1
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)

Loading…
Cancel
Save