From bf7f738aa1e4c3c46433076ccf741e924823388a Mon Sep 17 00:00:00 2001 From: Kim Lindhardt Madsen Date: Mon, 21 Sep 2015 08:50:11 +0200 Subject: [PATCH] some fixes --- cmd/web.go | 4 ++-- routers/api/v1/repo_commits.go | 8 ++++---- routers/api/v1/repo_releases.go | 29 ++++++++++++++++++++--------- 3 files changed, 26 insertions(+), 15 deletions(-) diff --git a/cmd/web.go b/cmd/web.go index db2f483bc..57c8f0077 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -244,8 +244,8 @@ func runWeb(ctx *cli.Context) { m.Get("/archive/*", v1.GetRepoArchive) m.Post("/forks", v1.ForkRepo) - m.Get("/commits/:commitId", middleware.RepoRef(), v1.CommitById) - m.Get("/commits/current", middleware.RepoRef(), v1.CurrentCommit) + m.Get("/commits/:commitid", middleware.RepoRef(), v1.CommitByID) + m.Get("/commits/head", middleware.RepoRef(), v1.HEADCommit) m.Group("/releases", func() { m.Combo("").Get(v1.ListReleases). diff --git a/routers/api/v1/repo_commits.go b/routers/api/v1/repo_commits.go index f74176411..9892dce5a 100644 --- a/routers/api/v1/repo_commits.go +++ b/routers/api/v1/repo_commits.go @@ -29,14 +29,14 @@ func ToApiCommit(commit *git.Commit) *api.Commit { } } -func CurrentCommit(ctx *middleware.Context) { - ctx.JSON(200, ToApiCommit(ctx.Repo.Commit)) +func HEADCommit(ctx *middleware.Context) { + ctx.JSON(200, ToApiCommit(ctx.Repo.Commit.Id.String())) } -func CommitById(ctx *middleware.Context) { +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 { log.Error(4, "GetCommit: %v", err) ctx.Error(500, err.Error()) diff --git a/routers/api/v1/repo_releases.go b/routers/api/v1/repo_releases.go index 4f9765e8c..3af75fcc3 100644 --- a/routers/api/v1/repo_releases.go +++ b/routers/api/v1/repo_releases.go @@ -17,7 +17,7 @@ import ( func ToApiRelease(release *models.Release, publisher *models.User) *api.Release { return &api.Release{ - Id: release.Id, + ID: release.Id, Publisher: *ToApiUser(publisher), TagName: release.TagName, LowerTagName: release.LowerTagName, @@ -42,13 +42,19 @@ func ListReleases(ctx *middleware.Context) { apiReleases := make([]*api.Release, len(rels)) for i, rel := range rels { - publisher, err := models.GetUserByID(rel.PublisherId) - if err != nil { - log.Error(4, "GetUserByID: %v", err) - return + if models.IsUserExist(rel.PublisherId, "") { + publisher, err := models.GetUserByID(rel.PublisherId) + if err != nil { + if models.IsErrUserNotExist(err) { + publisher = models.NewFakeUser() + } else { + log.Error(4, "GetUserByID: %v", err) + ctx.Status(500) + return + } + } + apiReleases[i] = ToApiRelease(rel, publisher) } - - apiReleases[i] = ToApiRelease(rel, publisher) } ctx.JSON(200, &apiReleases) } @@ -63,7 +69,12 @@ func ReleaseByName(ctx *middleware.Context) { publisher, err := models.GetUserByID(rel.PublisherId) if err != nil { - log.Error(4, "GetUserByID: %v", err) + if models.IsErrUserNotExist(err) { + publisher = models.NewFakeUser() + } else { + ctx.Handle(422, "GetUserByID", err) + return + } return } @@ -104,7 +115,7 @@ func CreateRelease(ctx *middleware.Context, form api.CreateReleaseOption) { err = models.CreateRelease(ctx.Repo.GitRepo, rel) if err != nil { - ctx.Handle(400, "CreateRelease", err) + ctx.Handle(500, "CreateRelease", err) return }