diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-17 23:04:49 +0800 |
---|---|---|
committer | Lunny Xiao <xiaolunwen@gmail.com> | 2014-03-17 23:04:49 +0800 |
commit | 45a6444b1ead3ebedcf79204cabe44df672f59d5 (patch) | |
tree | 3aa7e4d1c274d895588f29106282f09b3e862c8c | |
parent | be8baea7ad269eb633a6b5a569b904982021723d (diff) | |
download | gitea-45a6444b1ead3ebedcf79204cabe44df672f59d5.tar.gz gitea-45a6444b1ead3ebedcf79204cabe44df672f59d5.zip |
add commits
-rw-r--r-- | models/repo2.go | 12 | ||||
-rw-r--r-- | routers/repo/single.go | 9 | ||||
-rw-r--r-- | templates/repo/commits.tmpl | 5 | ||||
-rw-r--r-- | web.go | 2 |
4 files changed, 26 insertions, 2 deletions
diff --git a/models/repo2.go b/models/repo2.go index 91c057808b..8356c52de4 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 cf64cc6b52..eda71f2925 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 7ebe68b6a0..9190a030a3 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -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" .}}
\ No newline at end of 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) |