From 3367af7b2fc49d8068ad82be1d1ea329ad490bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kim=20=22BKC=22=20Carlb=C3=A4cker?= Date: Mon, 3 Oct 2016 12:35:42 +0200 Subject: [PATCH] Add undocumented endpoint for /repositories/:id --- routers/api/v1/api.go | 2 ++ routers/api/v1/repo/repo.go | 14 ++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 0591cddb8..c7925a21a 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -232,6 +232,8 @@ func RegisterRoutes(m *macaron.Macaron) { m.Get("/search", repo.Search) }) + m.Combo("/repositories/:id", reqToken()).Get(repo.GetByID) + m.Group("/repos", func() { m.Post("/migrate", bind(auth.MigrateRepoForm{}), repo.Migrate) m.Combo("/:username/:reponame").Get(repo.Get). diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index cc75f5bf4..295dc5763 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -272,6 +272,20 @@ func Get(ctx *context.APIContext) { ctx.JSON(200, repo.APIFormat(&api.Permission{true, true, true})) } +func GetByID(ctx *context.APIContext) { + repo, err := models.GetRepositoryByID(ctx.ParamsInt64(":id")) + if err != nil { + if models.IsErrRepoNotExist(err) { + ctx.Status(404) + } else { + ctx.Error(500, "GetRepositoryByID", err) + } + return + } + + ctx.JSON(200, repo.APIFormat(&api.Permission{true, true, true})) +} + // https://github.com/gogits/go-gogs-client/wiki/Repositories#delete func Delete(ctx *context.APIContext) { owner, repo := parseOwnerAndRepo(ctx)