2015-12-04 17:16:42 -05:00
|
|
|
// Copyright 2015 The Gogs Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
|
|
package v1
|
|
|
|
|
|
|
|
|
|
import (
|
2018-12-01 21:41:30 -05:00
|
|
|
"net/http"
|
2015-12-04 17:16:42 -05:00
|
|
|
"strings"
|
|
|
|
|
|
|
|
|
|
"github.com/go-macaron/binding"
|
|
|
|
|
"gopkg.in/macaron.v1"
|
|
|
|
|
|
2018-05-27 08:53:48 +08:00
|
|
|
api "github.com/gogs/go-gogs-client"
|
2015-12-04 17:16:42 -05:00
|
|
|
|
2019-10-24 01:51:46 -07:00
|
|
|
"gogs.io/gogs/internal/context"
|
|
|
|
|
"gogs.io/gogs/internal/db"
|
|
|
|
|
"gogs.io/gogs/internal/db/errors"
|
|
|
|
|
"gogs.io/gogs/internal/form"
|
2020-03-10 22:15:55 +08:00
|
|
|
"gogs.io/gogs/internal/route/api/v1/admin"
|
|
|
|
|
"gogs.io/gogs/internal/route/api/v1/misc"
|
|
|
|
|
"gogs.io/gogs/internal/route/api/v1/org"
|
|
|
|
|
"gogs.io/gogs/internal/route/api/v1/repo"
|
|
|
|
|
"gogs.io/gogs/internal/route/api/v1/user"
|
2015-12-04 17:16:42 -05:00
|
|
|
)
|
|
|
|
|
|
2019-08-08 23:53:43 -07:00
|
|
|
// repoAssignment extracts information from URL parameters to retrieve the repository,
|
|
|
|
|
// and makes sure the context user has at least the read access to the repository.
|
2016-08-04 17:08:01 -07:00
|
|
|
func repoAssignment() macaron.Handler {
|
2017-06-03 07:26:09 -04:00
|
|
|
return func(c *context.APIContext) {
|
2019-08-08 23:53:43 -07:00
|
|
|
username := c.Params(":username")
|
|
|
|
|
reponame := c.Params(":reponame")
|
2015-12-04 17:16:42 -05:00
|
|
|
|
2019-08-08 23:53:43 -07:00
|
|
|
var err error
|
2019-10-24 01:51:46 -07:00
|
|
|
var owner *db.User
|
2015-12-04 17:16:42 -05:00
|
|
|
|
2019-08-08 23:53:43 -07:00
|
|
|
// Check if the context user is the repository owner.
|
|
|
|
|
if c.IsLogged && c.User.LowerName == strings.ToLower(username) {
|
2017-06-03 07:26:09 -04:00
|
|
|
owner = c.User
|
2015-12-04 17:16:42 -05:00
|
|
|
} else {
|
2019-10-24 01:51:46 -07:00
|
|
|
owner, err = db.GetUserByName(username)
|
2015-12-04 17:16:42 -05:00
|
|
|
if err != nil {
|
2018-12-01 21:41:30 -05:00
|
|
|
c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
|
2015-12-04 17:16:42 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-06-03 07:26:09 -04:00
|
|
|
c.Repo.Owner = owner
|
2015-12-04 17:16:42 -05:00
|
|
|
|
2019-10-24 01:51:46 -07:00
|
|
|
r, err := db.GetRepositoryByName(owner.ID, reponame)
|
2015-12-04 17:16:42 -05:00
|
|
|
if err != nil {
|
2018-12-01 21:41:30 -05:00
|
|
|
c.NotFoundOrServerError("GetRepositoryByName", errors.IsRepoNotExist, err)
|
2015-12-04 17:16:42 -05:00
|
|
|
return
|
2019-08-08 23:53:43 -07:00
|
|
|
} else if err = r.GetOwner(); err != nil {
|
2018-12-01 21:41:30 -05:00
|
|
|
c.ServerError("GetOwner", err)
|
2015-12-04 17:16:42 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-01 21:40:19 -05:00
|
|
|
if c.IsTokenAuth && c.User.IsAdmin {
|
2019-10-24 01:51:46 -07:00
|
|
|
c.Repo.AccessMode = db.ACCESS_MODE_OWNER
|
2016-03-13 23:20:22 -04:00
|
|
|
} else {
|
2019-10-24 01:51:46 -07:00
|
|
|
mode, err := db.UserAccessMode(c.UserID(), r)
|
2016-03-13 23:20:22 -04:00
|
|
|
if err != nil {
|
2019-08-08 23:53:43 -07:00
|
|
|
c.ServerError("UserAccessMode", err)
|
2016-03-13 23:20:22 -04:00
|
|
|
return
|
|
|
|
|
}
|
2017-06-03 07:26:09 -04:00
|
|
|
c.Repo.AccessMode = mode
|
2015-12-04 17:16:42 -05:00
|
|
|
}
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
if !c.Repo.HasAccess() {
|
2018-12-01 21:41:30 -05:00
|
|
|
c.NotFound()
|
2015-12-04 17:16:42 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 23:53:43 -07:00
|
|
|
c.Repo.Repository = r
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// orgAssignment extracts information from URL parameters to retrieve the organization or team.
|
|
|
|
|
func orgAssignment(args ...bool) macaron.Handler {
|
|
|
|
|
var (
|
|
|
|
|
assignOrg bool
|
|
|
|
|
assignTeam bool
|
|
|
|
|
)
|
|
|
|
|
if len(args) > 0 {
|
|
|
|
|
assignOrg = args[0]
|
|
|
|
|
}
|
|
|
|
|
if len(args) > 1 {
|
|
|
|
|
assignTeam = args[1]
|
|
|
|
|
}
|
|
|
|
|
return func(c *context.APIContext) {
|
|
|
|
|
c.Org = new(context.APIOrganization)
|
|
|
|
|
|
|
|
|
|
var err error
|
|
|
|
|
if assignOrg {
|
2019-10-24 01:51:46 -07:00
|
|
|
c.Org.Organization, err = db.GetUserByName(c.Params(":orgname"))
|
2019-08-08 23:53:43 -07:00
|
|
|
if err != nil {
|
|
|
|
|
c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if assignTeam {
|
2019-10-24 01:51:46 -07:00
|
|
|
c.Org.Team, err = db.GetTeamByID(c.ParamsInt64(":teamid"))
|
2019-08-08 23:53:43 -07:00
|
|
|
if err != nil {
|
|
|
|
|
c.NotFoundOrServerError("GetTeamByID", errors.IsTeamNotExist, err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-12-04 17:16:42 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 23:53:43 -07:00
|
|
|
// reqToken makes sure the context user is authorized via access token.
|
2016-08-04 17:08:01 -07:00
|
|
|
func reqToken() macaron.Handler {
|
2017-06-03 07:26:09 -04:00
|
|
|
return func(c *context.Context) {
|
2018-11-28 21:05:58 -05:00
|
|
|
if !c.IsTokenAuth {
|
2018-12-01 21:41:30 -05:00
|
|
|
c.Error(http.StatusUnauthorized)
|
2015-12-04 17:16:42 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 23:53:43 -07:00
|
|
|
// reqBasicAuth makes sure the context user is authorized via HTTP Basic Auth.
|
2016-08-04 17:08:01 -07:00
|
|
|
func reqBasicAuth() macaron.Handler {
|
2017-06-03 07:26:09 -04:00
|
|
|
return func(c *context.Context) {
|
|
|
|
|
if !c.IsBasicAuth {
|
2018-12-01 21:41:30 -05:00
|
|
|
c.Error(http.StatusUnauthorized)
|
2015-12-04 17:16:42 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 23:53:43 -07:00
|
|
|
// reqAdmin makes sure the context user is a site admin.
|
2016-08-04 17:08:01 -07:00
|
|
|
func reqAdmin() macaron.Handler {
|
2017-06-03 07:26:09 -04:00
|
|
|
return func(c *context.Context) {
|
|
|
|
|
if !c.IsLogged || !c.User.IsAdmin {
|
2018-12-01 21:41:30 -05:00
|
|
|
c.Error(http.StatusForbidden)
|
2015-12-04 17:16:42 -05:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 23:53:43 -07:00
|
|
|
// reqRepoWriter makes sure the context user has at least write access to the repository.
|
2016-08-24 16:05:56 -07:00
|
|
|
func reqRepoWriter() macaron.Handler {
|
2017-06-03 07:26:09 -04:00
|
|
|
return func(c *context.Context) {
|
|
|
|
|
if !c.Repo.IsWriter() {
|
2018-12-01 21:41:30 -05:00
|
|
|
c.Error(http.StatusForbidden)
|
2016-08-24 16:05:56 -07:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-08-08 23:53:43 -07:00
|
|
|
// reqRepoWriter makes sure the context user has at least admin access to the repository.
|
2019-08-01 18:36:05 -07:00
|
|
|
func reqRepoAdmin() macaron.Handler {
|
|
|
|
|
return func(c *context.Context) {
|
|
|
|
|
if !c.Repo.IsAdmin() {
|
|
|
|
|
c.Error(http.StatusForbidden)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-03 07:26:09 -04:00
|
|
|
func mustEnableIssues(c *context.APIContext) {
|
|
|
|
|
if !c.Repo.Repository.EnableIssues || c.Repo.Repository.EnableExternalTracker {
|
2018-12-01 21:41:30 -05:00
|
|
|
c.NotFound()
|
2016-08-04 16:32:02 -07:00
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2019-10-24 01:51:46 -07:00
|
|
|
// RegisterRoutes registers all route in API v1 to the web application.
|
2015-12-04 17:16:42 -05:00
|
|
|
// FIXME: custom form error response
|
|
|
|
|
func RegisterRoutes(m *macaron.Macaron) {
|
|
|
|
|
bind := binding.Bind
|
|
|
|
|
|
|
|
|
|
m.Group("/v1", func() {
|
2017-03-11 13:31:59 +05:30
|
|
|
// Handle preflight OPTIONS request
|
|
|
|
|
m.Options("/*", func() {})
|
|
|
|
|
|
2015-12-04 17:16:42 -05:00
|
|
|
// Miscellaneous
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown)
|
|
|
|
|
m.Post("/markdown/raw", misc.MarkdownRaw)
|
2015-12-04 17:16:42 -05:00
|
|
|
|
|
|
|
|
// Users
|
|
|
|
|
m.Group("/users", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/search", user.Search)
|
2015-12-04 17:16:42 -05:00
|
|
|
|
|
|
|
|
m.Group("/:username", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("", user.GetInfo)
|
2015-12-04 17:16:42 -05:00
|
|
|
|
|
|
|
|
m.Group("/tokens", func() {
|
2019-08-08 23:53:43 -07:00
|
|
|
m.Combo("").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(user.ListAccessTokens).
|
|
|
|
|
Post(bind(api.CreateAccessTokenOption{}), user.CreateAccessToken)
|
2016-08-04 17:08:01 -07:00
|
|
|
}, reqBasicAuth())
|
2015-12-04 17:16:42 -05:00
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
m.Group("/users", func() {
|
|
|
|
|
m.Group("/:username", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/keys", user.ListPublicKeys)
|
2015-12-21 04:24:11 -08:00
|
|
|
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/followers", user.ListFollowers)
|
2015-12-21 04:24:11 -08:00
|
|
|
m.Group("/following", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("", user.ListFollowing)
|
|
|
|
|
m.Get("/:target", user.CheckFollowing)
|
2015-12-21 04:24:11 -08:00
|
|
|
})
|
2015-12-04 17:16:42 -05:00
|
|
|
})
|
2016-08-04 17:08:01 -07:00
|
|
|
}, reqToken())
|
2015-12-04 17:16:42 -05:00
|
|
|
|
|
|
|
|
m.Group("/user", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("", user.GetAuthenticatedUser)
|
2019-08-08 23:53:43 -07:00
|
|
|
m.Combo("/emails").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(user.ListEmails).
|
|
|
|
|
Post(bind(api.CreateEmailOption{}), user.AddEmail).
|
|
|
|
|
Delete(bind(api.CreateEmailOption{}), user.DeleteEmail)
|
2015-12-21 04:24:11 -08:00
|
|
|
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/followers", user.ListMyFollowers)
|
2015-12-21 04:24:11 -08:00
|
|
|
m.Group("/following", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("", user.ListMyFollowing)
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("/:username").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(user.CheckMyFollowing).
|
|
|
|
|
Put(user.Follow).
|
|
|
|
|
Delete(user.Unfollow)
|
2015-12-21 04:24:11 -08:00
|
|
|
})
|
|
|
|
|
|
2015-12-04 17:16:42 -05:00
|
|
|
m.Group("/keys", func() {
|
2019-08-08 23:53:43 -07:00
|
|
|
m.Combo("").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(user.ListMyPublicKeys).
|
|
|
|
|
Post(bind(api.CreateKeyOption{}), user.CreatePublicKey)
|
2019-08-08 23:53:43 -07:00
|
|
|
m.Combo("/:id").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(user.GetPublicKey).
|
|
|
|
|
Delete(user.DeletePublicKey)
|
2015-12-04 17:16:42 -05:00
|
|
|
})
|
2017-02-13 01:42:28 +01:00
|
|
|
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/issues", repo.ListUserIssues)
|
2016-08-04 17:08:01 -07:00
|
|
|
}, reqToken())
|
2015-12-04 17:16:42 -05:00
|
|
|
|
|
|
|
|
// Repositories
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/users/:username/repos", reqToken(), repo.ListUserRepositories)
|
|
|
|
|
m.Get("/orgs/:org/repos", reqToken(), repo.ListOrgRepositories)
|
2019-08-08 23:53:43 -07:00
|
|
|
m.Combo("/user/repos", reqToken()).
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(repo.ListMyRepos).
|
|
|
|
|
Post(bind(api.CreateRepoOption{}), repo.Create)
|
|
|
|
|
m.Post("/org/:org/repos", reqToken(), bind(api.CreateRepoOption{}), repo.CreateOrgRepo)
|
2015-12-04 17:16:42 -05:00
|
|
|
|
|
|
|
|
m.Group("/repos", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/search", repo.Search)
|
2018-12-01 21:40:19 -05:00
|
|
|
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/:username/:reponame", repoAssignment(), repo.Get)
|
2015-12-04 17:16:42 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
m.Group("/repos", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Post("/migrate", bind(form.MigrateRepo{}), repo.Migrate)
|
|
|
|
|
m.Delete("/:username/:reponame", repoAssignment(), repo.Delete)
|
2015-12-04 17:16:42 -05:00
|
|
|
|
|
|
|
|
m.Group("/:username/:reponame", func() {
|
2016-07-16 19:08:38 -05:00
|
|
|
m.Group("/hooks", func() {
|
2019-08-08 23:53:43 -07:00
|
|
|
m.Combo("").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(repo.ListHooks).
|
|
|
|
|
Post(bind(api.CreateHookOption{}), repo.CreateHook)
|
2019-08-08 23:53:43 -07:00
|
|
|
m.Combo("/:id").
|
2020-03-10 22:15:55 +08:00
|
|
|
Patch(bind(api.EditHookOption{}), repo.EditHook).
|
|
|
|
|
Delete(repo.DeleteHook)
|
2019-08-01 18:36:05 -07:00
|
|
|
}, reqRepoAdmin())
|
2019-08-08 23:53:43 -07:00
|
|
|
|
2017-02-15 00:45:08 +01:00
|
|
|
m.Group("/collaborators", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("", repo.ListCollaborators)
|
2019-08-08 23:53:43 -07:00
|
|
|
m.Combo("/:collaborator").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(repo.IsCollaborator).
|
|
|
|
|
Put(bind(api.AddCollaboratorOption{}), repo.AddCollaborator).
|
|
|
|
|
Delete(repo.DeleteCollaborator)
|
2019-08-01 18:36:05 -07:00
|
|
|
}, reqRepoAdmin())
|
2019-08-08 23:53:43 -07:00
|
|
|
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/raw/*", context.RepoRef(), repo.GetRawFile)
|
|
|
|
|
m.Get("/contents/*", repo.GetContents)
|
|
|
|
|
m.Get("/archive/*", repo.GetArchive)
|
api: support getting repository Git tree (#5934) (#5937)
* add basic git repository tree api (#5934)
This PR adds the tree api endpoint to gogs api:
`GET/repos/:owner/:repo/git/trees/:tree_sha`
This new api endpoint that is being added is in conformance to
the GitHub REST API v3 specification. Documentation can be found
here: developer.github.com/v3/git/trees/#get-a-tree
For a given user, repo and sha value, this api (currently) returns
a single tree using the SHA1 value for that tree.
- Recursive implementation is yet to be implemented.
- Creating a Tree using POST is yet to be implemented.
Example curl:
```
l curl -H "Authorization: token REDACTED" http://localhost:3000/api/v1/repos/root/testrepo/git/trees/c59441ded1549b149def0d4c54594d31a7f3718f -X GET | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 940 100 940 0 0 12034 0 --:--:-- --:--:-- --:--:-- 12051
[
{
"sha": "c59441ded1549b149def0d4c54594d31a7f3718f",
"tree": [
{
"mode": "120000",
"path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
"sha": "472ac2361b65136b393d652de25341e2ea44f299",
"size": 1077,
"type": "blob",
"url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/472ac2361b65136b393d652de25341e2ea44f299"
},
{
"mode": "120000",
"path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
"sha": "70fcb456d436f08462602f26df6fb7e167e7a916",
"size": 12,
"type": "blob",
"url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/70fcb456d436f08462602f26df6fb7e167e7a916"
},
{
"mode": "120000",
"path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
"sha": "092c58d4b63df5779a4d020b1fdbb762421bbb4f",
"size": 380,
"type": "blob",
"url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/092c58d4b63df5779a4d020b1fdbb762421bbb4f"
}
],
"url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/c59441ded1549b149def0d4c54594d31a7f3718f"
}
]
```
* remove vertical space
* make go.mod to be same as in master
* rename structs to sound better
* simplify expressions and fix error msg
* Update tree.go
* Update tree.go
* display file name instead of repo path
* Update tree.go
Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
2020-02-25 06:19:42 -08:00
|
|
|
m.Group("/git/trees", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/:sha", context.RepoRef(), repo.GetRepoGitTree)
|
api: support getting repository Git tree (#5934) (#5937)
* add basic git repository tree api (#5934)
This PR adds the tree api endpoint to gogs api:
`GET/repos/:owner/:repo/git/trees/:tree_sha`
This new api endpoint that is being added is in conformance to
the GitHub REST API v3 specification. Documentation can be found
here: developer.github.com/v3/git/trees/#get-a-tree
For a given user, repo and sha value, this api (currently) returns
a single tree using the SHA1 value for that tree.
- Recursive implementation is yet to be implemented.
- Creating a Tree using POST is yet to be implemented.
Example curl:
```
l curl -H "Authorization: token REDACTED" http://localhost:3000/api/v1/repos/root/testrepo/git/trees/c59441ded1549b149def0d4c54594d31a7f3718f -X GET | jq .
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 940 100 940 0 0 12034 0 --:--:-- --:--:-- --:--:-- 12051
[
{
"sha": "c59441ded1549b149def0d4c54594d31a7f3718f",
"tree": [
{
"mode": "120000",
"path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
"sha": "472ac2361b65136b393d652de25341e2ea44f299",
"size": 1077,
"type": "blob",
"url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/472ac2361b65136b393d652de25341e2ea44f299"
},
{
"mode": "120000",
"path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
"sha": "70fcb456d436f08462602f26df6fb7e167e7a916",
"size": 12,
"type": "blob",
"url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/70fcb456d436f08462602f26df6fb7e167e7a916"
},
{
"mode": "120000",
"path": "/home/bharatnc/gogs-repositories/root/testrepo.git",
"sha": "092c58d4b63df5779a4d020b1fdbb762421bbb4f",
"size": 380,
"type": "blob",
"url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/092c58d4b63df5779a4d020b1fdbb762421bbb4f"
}
],
"url": "http://localhost:3000/api/v1/repos/root/testrepo/git/trees/c59441ded1549b149def0d4c54594d31a7f3718f"
}
]
```
* remove vertical space
* make go.mod to be same as in master
* rename structs to sound better
* simplify expressions and fix error msg
* Update tree.go
* Update tree.go
* display file name instead of repo path
* Update tree.go
Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
2020-02-25 06:19:42 -08:00
|
|
|
})
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/forks", repo.ListForks)
|
2016-01-15 19:24:03 +01:00
|
|
|
m.Group("/branches", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("", repo.ListBranches)
|
|
|
|
|
m.Get("/*", repo.GetBranch)
|
2016-01-15 19:24:03 +01:00
|
|
|
})
|
2018-12-15 00:24:41 -05:00
|
|
|
m.Group("/commits", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/:sha", repo.GetSingleCommit)
|
|
|
|
|
m.Get("/*", repo.GetReferenceSHA)
|
2018-12-15 00:24:41 -05:00
|
|
|
})
|
|
|
|
|
|
2015-12-04 17:16:42 -05:00
|
|
|
m.Group("/keys", func() {
|
2019-08-08 23:53:43 -07:00
|
|
|
m.Combo("").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(repo.ListDeployKeys).
|
|
|
|
|
Post(bind(api.CreateKeyOption{}), repo.CreateDeployKey)
|
2019-08-08 23:53:43 -07:00
|
|
|
m.Combo("/:id").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(repo.GetDeployKey).
|
|
|
|
|
Delete(repo.DeleteDeploykey)
|
2019-08-01 18:36:05 -07:00
|
|
|
}, reqRepoAdmin())
|
2019-08-08 23:53:43 -07:00
|
|
|
|
2016-03-13 23:20:22 -04:00
|
|
|
m.Group("/issues", func() {
|
2019-08-08 23:53:43 -07:00
|
|
|
m.Combo("").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(repo.ListIssues).
|
|
|
|
|
Post(bind(api.CreateIssueOption{}), repo.CreateIssue)
|
2016-12-21 07:21:15 +01:00
|
|
|
m.Group("/comments", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("", repo.ListRepoIssueComments)
|
|
|
|
|
m.Patch("/:id", bind(api.EditIssueCommentOption{}), repo.EditIssueComment)
|
2016-12-21 07:21:15 +01:00
|
|
|
})
|
2016-08-03 09:24:16 -07:00
|
|
|
m.Group("/:index", func() {
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(repo.GetIssue).
|
|
|
|
|
Patch(bind(api.EditIssueOption{}), repo.EditIssue)
|
2016-08-27 01:23:21 +07:00
|
|
|
|
|
|
|
|
m.Group("/comments", func() {
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(repo.ListIssueComments).
|
|
|
|
|
Post(bind(api.CreateIssueCommentOption{}), repo.CreateIssueComment)
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("/:id").
|
2020-03-10 22:15:55 +08:00
|
|
|
Patch(bind(api.EditIssueCommentOption{}), repo.EditIssueComment).
|
|
|
|
|
Delete(repo.DeleteIssueComment)
|
2016-08-27 01:23:21 +07:00
|
|
|
})
|
|
|
|
|
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/labels", repo.ListIssueLabels)
|
2016-08-03 09:24:16 -07:00
|
|
|
m.Group("/labels", func() {
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("").
|
2020-03-10 22:15:55 +08:00
|
|
|
Post(bind(api.IssueLabelsOption{}), repo.AddIssueLabels).
|
|
|
|
|
Put(bind(api.IssueLabelsOption{}), repo.ReplaceIssueLabels).
|
|
|
|
|
Delete(repo.ClearIssueLabels)
|
|
|
|
|
m.Delete("/:id", repo.DeleteIssueLabel)
|
2019-08-10 13:40:48 -07:00
|
|
|
}, reqRepoWriter())
|
2016-08-03 09:24:16 -07:00
|
|
|
})
|
2016-08-04 17:08:01 -07:00
|
|
|
}, mustEnableIssues)
|
2019-08-10 13:40:48 -07:00
|
|
|
|
2016-08-03 09:24:16 -07:00
|
|
|
m.Group("/labels", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("", repo.ListLabels)
|
|
|
|
|
m.Get("/:id", repo.GetLabel)
|
2016-03-13 18:49:16 -04:00
|
|
|
})
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Group("/labels", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Post("", bind(api.CreateLabelOption{}), repo.CreateLabel)
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("/:id").
|
2020-03-10 22:15:55 +08:00
|
|
|
Patch(bind(api.EditLabelOption{}), repo.EditLabel).
|
|
|
|
|
Delete(repo.DeleteLabel)
|
2019-08-10 13:40:48 -07:00
|
|
|
}, reqRepoWriter())
|
|
|
|
|
|
2016-08-24 15:18:56 -07:00
|
|
|
m.Group("/milestones", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("", repo.ListMilestones)
|
|
|
|
|
m.Get("/:id", repo.GetMilestone)
|
2016-08-24 15:18:56 -07:00
|
|
|
})
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Group("/milestones", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Post("", bind(api.CreateMilestoneOption{}), repo.CreateMilestone)
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("/:id").
|
2020-03-10 22:15:55 +08:00
|
|
|
Patch(bind(api.EditMilestoneOption{}), repo.EditMilestone).
|
|
|
|
|
Delete(repo.DeleteMilestone)
|
2019-08-10 13:40:48 -07:00
|
|
|
}, reqRepoWriter())
|
2018-12-02 12:55:05 -05:00
|
|
|
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Patch("/issue-tracker", reqRepoWriter(), bind(api.EditIssueTrackerOption{}), repo.IssueTracker)
|
|
|
|
|
m.Post("/mirror-sync", reqRepoWriter(), repo.MirrorSync)
|
|
|
|
|
m.Get("/editorconfig/:filename", context.RepoRef(), repo.GetEditorconfig)
|
2016-08-04 17:08:01 -07:00
|
|
|
}, repoAssignment())
|
|
|
|
|
}, reqToken())
|
2015-12-04 17:16:42 -05:00
|
|
|
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/issues", reqToken(), repo.ListUserIssues)
|
2017-02-13 01:42:28 +01:00
|
|
|
|
2015-12-17 02:28:47 -05:00
|
|
|
// Organizations
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("/user/orgs", reqToken()).
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(org.ListMyOrgs).
|
|
|
|
|
Post(bind(api.CreateOrgOption{}), org.CreateMyOrg)
|
2017-11-14 05:27:30 +02:00
|
|
|
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Get("/users/:username/orgs", org.ListUserOrgs)
|
2016-03-21 12:53:04 -04:00
|
|
|
m.Group("/orgs/:orgname", func() {
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("").
|
2020-03-10 22:15:55 +08:00
|
|
|
Get(org.Get).
|
|
|
|
|
Patch(bind(api.EditOrgOption{}), org.Edit)
|
|
|
|
|
m.Get("/teams", org.ListTeams)
|
2016-08-04 17:08:01 -07:00
|
|
|
}, orgAssignment(true))
|
2015-12-17 02:28:47 -05:00
|
|
|
|
2015-12-05 17:13:13 -05:00
|
|
|
m.Group("/admin", func() {
|
|
|
|
|
m.Group("/users", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Post("", bind(api.CreateUserOption{}), admin.CreateUser)
|
2015-12-05 17:13:13 -05:00
|
|
|
|
|
|
|
|
m.Group("/:username", func() {
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("").
|
2020-03-10 22:15:55 +08:00
|
|
|
Patch(bind(api.EditUserOption{}), admin.EditUser).
|
|
|
|
|
Delete(admin.DeleteUser)
|
|
|
|
|
m.Post("/keys", bind(api.CreateKeyOption{}), admin.CreatePublicKey)
|
|
|
|
|
m.Post("/orgs", bind(api.CreateOrgOption{}), admin.CreateOrg)
|
|
|
|
|
m.Post("/repos", bind(api.CreateRepoOption{}), admin.CreateRepo)
|
2015-12-05 17:13:13 -05:00
|
|
|
})
|
|
|
|
|
})
|
2016-03-21 12:47:54 -04:00
|
|
|
|
|
|
|
|
m.Group("/orgs/:orgname", func() {
|
2016-03-25 18:04:02 -04:00
|
|
|
m.Group("/teams", func() {
|
2020-03-10 22:15:55 +08:00
|
|
|
m.Post("", orgAssignment(true), bind(api.CreateTeamOption{}), admin.CreateTeam)
|
2016-03-25 18:04:02 -04:00
|
|
|
})
|
2016-03-21 12:47:54 -04:00
|
|
|
})
|
2019-08-10 13:40:48 -07:00
|
|
|
|
2016-04-04 19:41:34 -04:00
|
|
|
m.Group("/teams", func() {
|
|
|
|
|
m.Group("/:teamid", func() {
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("/members/:username").
|
2020-03-10 22:15:55 +08:00
|
|
|
Put(admin.AddTeamMember).
|
|
|
|
|
Delete(admin.RemoveTeamMember)
|
2019-08-10 13:40:48 -07:00
|
|
|
m.Combo("/repos/:reponame").
|
2020-03-10 22:15:55 +08:00
|
|
|
Put(admin.AddTeamRepository).
|
|
|
|
|
Delete(admin.RemoveTeamRepository)
|
2016-08-04 17:08:01 -07:00
|
|
|
}, orgAssignment(false, true))
|
2016-04-04 19:41:34 -04:00
|
|
|
})
|
2016-08-04 17:08:01 -07:00
|
|
|
}, reqAdmin())
|
2019-08-10 13:40:48 -07:00
|
|
|
|
|
|
|
|
m.Any("/*", func(c *context.Context) {
|
|
|
|
|
c.NotFound()
|
|
|
|
|
})
|
2016-03-13 18:49:16 -04:00
|
|
|
}, context.APIContexter())
|
2015-12-04 17:16:42 -05:00
|
|
|
}
|