Browse Source

list commits

pull/2039/head
Kim Lindhardt Madsen 9 years ago
parent
commit
801b092452
  1. 1
      cmd/web.go
  2. 32
      routers/api/v1/repo_commits.go

1
cmd/web.go

@ -244,6 +244,7 @@ func runWeb(ctx *cli.Context) {
m.Get("/commits/:commitid", middleware.RepoRef(), v1.CommitByID) m.Get("/commits/:commitid", middleware.RepoRef(), v1.CommitByID)
m.Get("/commits/head", middleware.RepoRef(), v1.HEADCommit) 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) m.Get("/compare/:before([a-z0-9]{40})...:after([a-z0-9]{40})", middleware.RepoRef(), v1.DiffRange)

32
routers/api/v1/repo_commits.go

@ -41,13 +41,37 @@ func CommitByID(ctx *middleware.Context) {
commit, err := ctx.Repo.GitRepo.GetCommit(ctx.Params(":commitid")) commit, err := ctx.Repo.GitRepo.GetCommit(ctx.Params(":commitid"))
if err != nil { if err != nil {
log.Error(4, "GetCommit: %v", err) log.Error(4, "GetCommit: %v", err)
ctx.Error(500, err.Error()) ctx.APIError(500, "GetCommit", err.Error())
return return
} }
ctx.JSON(200, ToApiCommit(commit)) 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 { func ToApiDiff(diff *models.Diff) *api.Diff {
return &api.Diff{ return &api.Diff{
@ -117,19 +141,19 @@ func DiffRange(ctx *middleware.Context) {
_, err := ctx.Repo.GitRepo.GetCommit(beforeCommitID) _, err := ctx.Repo.GitRepo.GetCommit(beforeCommitID)
if err != nil { if err != nil {
ctx.Handle(404, "GetCommit", err) ctx.APIError(404, "GetCommit", err)
return return
} }
_, err = ctx.Repo.GitRepo.GetCommit(afterCommitID) _, err = ctx.Repo.GitRepo.GetCommit(afterCommitID)
if err != nil { if err != nil {
ctx.Handle(404, "GetCommit", err) ctx.APIError(404, "GetCommit", err)
return return
} }
diff, err := models.GetDiffRange(ctx.Repo.GitRepo.Path, beforeCommitID, afterCommitID, 10000) diff, err := models.GetDiffRange(ctx.Repo.GitRepo.Path, beforeCommitID, afterCommitID, 10000)
if err != nil { if err != nil {
log.Error(4, "GetDiffRange: %v", err) log.Error(4, "GetDiffRange: %v", err)
ctx.Error(500, err.Error()) ctx.APIError(500, "GetDiffRange", err.Error())
return return
} }

Loading…
Cancel
Save