Browse Source

some fixes

pull/1630/head
Kim Lindhardt Madsen 9 years ago
parent
commit
bf7f738aa1
  1. 4
      cmd/web.go
  2. 8
      routers/api/v1/repo_commits.go
  3. 29
      routers/api/v1/repo_releases.go

4
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).

8
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())

29
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
}

Loading…
Cancel
Save