diff options
author | Kim "BKC" Carlbäcker <kim.carlbacker@gmail.com> | 2016-12-02 10:04:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-02 10:04:15 +0100 |
commit | d7ed78a91971260169c429f9ee47ebe8fa8f92ad (patch) | |
tree | 3489dde790d31a7a249e2326bbdd97fae5beec3d /routers/api | |
parent | bea9d55da6df19777b00213e7b5303237910e97c (diff) | |
parent | e8e0539b454d622c1c428d03ac9c6f40d2654600 (diff) | |
download | gitea-d7ed78a91971260169c429f9ee47ebe8fa8f92ad.tar.gz gitea-d7ed78a91971260169c429f9ee47ebe8fa8f92ad.zip |
Merge pull request #227 from go-gitea/api/github-compliance
GitHub API Compliance Fixes
Diffstat (limited to 'routers/api')
-rw-r--r-- | routers/api/v1/api.go | 2 | ||||
-rw-r--r-- | routers/api/v1/repo/issue.go | 20 | ||||
-rw-r--r-- | routers/api/v1/repo/label.go | 13 | ||||
-rw-r--r-- | routers/api/v1/repo/repo.go | 21 |
4 files changed, 48 insertions, 8 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index 95bdfd072e..506a615624 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -243,6 +243,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", context.ExtractOwnerAndRepo()). diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go index 462aca88ad..908b5aeb96 100644 --- a/routers/api/v1/repo/issue.go +++ b/routers/api/v1/repo/issue.go @@ -17,14 +17,26 @@ import ( // ListIssues list the issues of a repository func ListIssues(ctx *context.APIContext) { - issues, err := models.Issues(&models.IssuesOptions{ - RepoID: ctx.Repo.Repository.ID, - Page: ctx.QueryInt("page"), - }) + issueOpts := models.IssuesOptions{ + RepoID: ctx.Repo.Repository.ID, + Page: ctx.QueryInt("page"), + IsClosed: ctx.Query("state") == "closed", + } + + issues, err := models.Issues(&issueOpts) if err != nil { ctx.Error(500, "Issues", err) return } + if ctx.Query("state") == "all" { + issueOpts.IsClosed = !issueOpts.IsClosed + tempIssues, err := models.Issues(&issueOpts) + if err != nil { + ctx.Error(500, "Issues", err) + return + } + issues = append(issues, tempIssues...) + } // FIXME: use IssueList to improve performance. apiIssues := make([]*api.Issue, len(issues)) diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go index 383868beda..a2bf3a9e40 100644 --- a/routers/api/v1/repo/label.go +++ b/routers/api/v1/repo/label.go @@ -5,6 +5,8 @@ package repo import ( + "strconv" + api "code.gitea.io/sdk/gitea" "code.gitea.io/gitea/models" @@ -28,7 +30,16 @@ func ListLabels(ctx *context.APIContext) { // GetLabel get label by repository and label id func GetLabel(ctx *context.APIContext) { - label, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")) + var ( + label *models.Label + err error + ) + strID := ctx.Params(":id") + if intID, err2 := strconv.ParseInt(strID, 10, 64); err2 != nil { + label, err = models.GetLabelInRepoByName(ctx.Repo.Repository.ID, strID) + } else { + label, err = models.GetLabelInRepoByID(ctx.Repo.Repository.ID, intID) + } if err != nil { if models.IsErrLabelNotExist(err) { ctx.Status(404) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 1fa0b14b40..0c5c1ef5fd 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -141,7 +141,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true})) } -// Create create one repository of mine +// Create one repository of mine // see https://github.com/gogits/go-gogs-client/wiki/Repositories#create func Create(ctx *context.APIContext, opt api.CreateRepoOption) { // Shouldn't reach this condition, but just in case. @@ -244,14 +244,29 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) { ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true})) } -// Get get one repository +// Get one repository // see https://github.com/gogits/go-gogs-client/wiki/Repositories#get func Get(ctx *context.APIContext) { repo := ctx.Repo.Repository ctx.JSON(200, repo.APIFormat(&api.Permission{true, true, true})) } -// Delete delete one repository +// GetByID returns a single Repository +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})) +} + +// Delete one repository // see https://github.com/gogits/go-gogs-client/wiki/Repositories#delete func Delete(ctx *context.APIContext) { owner := ctx.Repo.Owner |