From 801b0924524a85a585f300a5d353734fe9937526 Mon Sep 17 00:00:00 2001 From: Kim Lindhardt Madsen Date: Thu, 22 Oct 2015 09:36:44 +0200 Subject: [PATCH] list commits --- cmd/web.go | 1 + routers/api/v1/repo_commits.go | 32 ++++++++++++++++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) diff --git a/cmd/web.go b/cmd/web.go index 778b3ac01..af396e7c9 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -244,6 +244,7 @@ func runWeb(ctx *cli.Context) { m.Get("/commits/:commitid", middleware.RepoRef(), v1.CommitByID) m.Get("/commits/head", middleware.RepoRef(), v1.HEADCommit) + m.Get("/commits/branch/*", middleware.RepoRef(), v1.ListCommits) m.Get("/compare/:before([a-z0-9]{40})...:after([a-z0-9]{40})", middleware.RepoRef(), v1.DiffRange) diff --git a/routers/api/v1/repo_commits.go b/routers/api/v1/repo_commits.go index bf51d6339..d7f7057a7 100644 --- a/routers/api/v1/repo_commits.go +++ b/routers/api/v1/repo_commits.go @@ -41,13 +41,37 @@ func CommitByID(ctx *middleware.Context) { commit, err := ctx.Repo.GitRepo.GetCommit(ctx.Params(":commitid")) if err != nil { log.Error(4, "GetCommit: %v", err) - ctx.Error(500, err.Error()) + ctx.APIError(500, "GetCommit", err.Error()) return } ctx.JSON(200, ToApiCommit(commit)) } +func ListCommits(ctx *middleware.Context) { + commits, err := ctx.Repo.Commit.CommitsBefore() + if err != nil { + log.Error(4, "CommitsBefore: %v", err) + ctx.APIError(500, "CommitsBefore", err) + return + } + + apiCommits := make([]*api.Commit, commits.Len()) + i := 0 + for e := commits.Front(); e != nil; e = e.Next() { + apiCommits[i] = ToApiCommit(e.Value.(*git.Commit)) + i = i+ 1 + } + + ctx.JSON(200, apiCommits) +} + + +/** + ******************* + * DIFF + ******************* + */ func ToApiDiff(diff *models.Diff) *api.Diff { return &api.Diff{ @@ -117,19 +141,19 @@ func DiffRange(ctx *middleware.Context) { _, err := ctx.Repo.GitRepo.GetCommit(beforeCommitID) if err != nil { - ctx.Handle(404, "GetCommit", err) + ctx.APIError(404, "GetCommit", err) return } _, err = ctx.Repo.GitRepo.GetCommit(afterCommitID) if err != nil { - ctx.Handle(404, "GetCommit", err) + ctx.APIError(404, "GetCommit", err) return } diff, err := models.GetDiffRange(ctx.Repo.GitRepo.Path, beforeCommitID, afterCommitID, 10000) if err != nil { log.Error(4, "GetDiffRange: %v", err) - ctx.Error(500, err.Error()) + ctx.APIError(500, "GetDiffRange", err.Error()) return }