diff options
author | Unknwon <u@gogs.io> | 2015-10-22 17:46:07 -0400 |
---|---|---|
committer | Unknwon <u@gogs.io> | 2015-10-22 17:46:07 -0400 |
commit | 35a65736fa1361d1d0fb83217f95d7aa8ca71336 (patch) | |
tree | 0b51195927a0fd2478d7d69c25e9eca8bc8ea30a | |
parent | 04af4b24fd87bb2ee8a2a3cecd66c5c1b1e413dd (diff) | |
download | gitea-35a65736fa1361d1d0fb83217f95d7aa8ca71336.tar.gz gitea-35a65736fa1361d1d0fb83217f95d7aa8ca71336.zip |
add get repo API
-rw-r--r-- | cmd/web.go | 13 | ||||
-rw-r--r-- | routers/api/v1/repo.go | 32 |
2 files changed, 32 insertions, 13 deletions
diff --git a/cmd/web.go b/cmd/web.go index 6ca61aea96..45a5ff2fa9 100644 --- a/cmd/web.go +++ b/cmd/web.go @@ -224,11 +224,12 @@ func runWeb(ctx *cli.Context) { m.Group("/repos", func() { m.Get("/search", v1.SearchRepos) + }) - m.Group("", func() { - m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo) - m.Delete("/:username/:reponame", v1.DeleteRepo) - }, middleware.ApiReqToken()) + m.Group("/repos", func() { + m.Post("/migrate", bindIgnErr(auth.MigrateRepoForm{}), v1.MigrateRepo) + m.Combo("/:username/:reponame").Get(v1.GetRepo) + m.Delete("/:username/:reponame", v1.DeleteRepo) m.Group("/:username/:reponame", func() { m.Combo("/hooks").Get(v1.ListRepoHooks). @@ -236,8 +237,8 @@ func runWeb(ctx *cli.Context) { m.Patch("/hooks/:id:int", bind(api.EditHookOption{}), v1.EditRepoHook) m.Get("/raw/*", middleware.RepoRef(), v1.GetRepoRawFile) m.Get("/archive/*", v1.GetRepoArchive) - }, middleware.ApiRepoAssignment(), middleware.ApiReqToken()) - }) + }, middleware.ApiRepoAssignment()) + }, middleware.ApiReqToken()) m.Any("/*", func(ctx *middleware.Context) { ctx.Error(404) diff --git a/routers/api/v1/repo.go b/routers/api/v1/repo.go index 9cdb16f846..712655bf40 100644 --- a/routers/api/v1/repo.go +++ b/routers/api/v1/repo.go @@ -252,37 +252,55 @@ func MigrateRepo(ctx *middleware.Context, form auth.MigrateRepoForm) { ctx.JSON(201, ToApiRepository(ctxUser, repo, api.Permission{true, true, true})) } -func DeleteRepo(ctx *middleware.Context) { - user, err := models.GetUserByName(ctx.Params(":username")) +func parseOwnerAndRepo(ctx *middleware.Context) (*models.User, *models.Repository) { + owner, err := models.GetUserByName(ctx.Params(":username")) if err != nil { if models.IsErrUserNotExist(err) { ctx.APIError(422, "", err) } else { ctx.APIError(500, "GetUserByName", err) } - return + return nil, nil } - repo, err := models.GetRepositoryByName(user.Id, ctx.Params(":reponame")) + repo, err := models.GetRepositoryByName(owner.Id, ctx.Params(":reponame")) if err != nil { if models.IsErrRepoNotExist(err) { ctx.Error(404) } else { ctx.APIError(500, "GetRepositoryByName", err) } + return nil, nil + } + + return owner, repo +} + +func GetRepo(ctx *middleware.Context) { + owner, repo := parseOwnerAndRepo(ctx) + if ctx.Written() { + return + } + + ctx.JSON(200, ToApiRepository(owner, repo, api.Permission{true, true, true})) +} + +func DeleteRepo(ctx *middleware.Context) { + owner, repo := parseOwnerAndRepo(ctx) + if ctx.Written() { return } - if user.IsOrganization() && !user.IsOwnedBy(ctx.User.Id) { + if owner.IsOrganization() && !owner.IsOwnedBy(ctx.User.Id) { ctx.APIError(403, "", "Given user is not owner of organization.") return } - if err := models.DeleteRepository(user.Id, repo.ID); err != nil { + if err := models.DeleteRepository(owner.Id, repo.ID); err != nil { ctx.APIError(500, "DeleteRepository", err) return } - log.Trace("Repository deleted: %s/%s", user.Name, repo.Name) + log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name) ctx.Status(204) } |