aboutsummaryrefslogtreecommitdiff
path: root/routers/api
diff options
context:
space:
mode:
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/admin/org.go12
-rw-r--r--routers/api/v1/admin/org_repo.go32
-rw-r--r--routers/api/v1/admin/org_team.go34
-rw-r--r--routers/api/v1/admin/repo.go8
-rw-r--r--routers/api/v1/admin/user.go64
-rw-r--r--routers/api/v1/api.go88
-rw-r--r--routers/api/v1/misc/markdown.go20
-rw-r--r--routers/api/v1/org/org.go34
-rw-r--r--routers/api/v1/org/team.go8
-rw-r--r--routers/api/v1/repo/branch.go28
-rw-r--r--routers/api/v1/repo/collaborators.go56
-rw-r--r--routers/api/v1/repo/file.go44
-rw-r--r--routers/api/v1/repo/hook.go56
-rw-r--r--routers/api/v1/repo/issue.go100
-rw-r--r--routers/api/v1/repo/issue_comment.go78
-rw-r--r--routers/api/v1/repo/issue_label.go96
-rw-r--r--routers/api/v1/repo/key.go62
-rw-r--r--routers/api/v1/repo/label.go58
-rw-r--r--routers/api/v1/repo/milestone.go48
-rw-r--r--routers/api/v1/repo/repo.go192
-rw-r--r--routers/api/v1/user/app.go16
-rw-r--r--routers/api/v1/user/email.go30
-rw-r--r--routers/api/v1/user/follower.go94
-rw-r--r--routers/api/v1/user/key.go62
-rw-r--r--routers/api/v1/user/user.go28
25 files changed, 674 insertions, 674 deletions
diff --git a/routers/api/v1/admin/org.go b/routers/api/v1/admin/org.go
index f5c4a95c..996a83bf 100644
--- a/routers/api/v1/admin/org.go
+++ b/routers/api/v1/admin/org.go
@@ -14,9 +14,9 @@ import (
)
// https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization
-func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
- u := user.GetUserByParams(ctx)
- if ctx.Written() {
+func CreateOrg(c *context.APIContext, form api.CreateOrgOption) {
+ u := user.GetUserByParams(c)
+ if c.Written() {
return
}
@@ -33,12 +33,12 @@ func CreateOrg(ctx *context.APIContext, form api.CreateOrgOption) {
if models.IsErrUserAlreadyExist(err) ||
models.IsErrNameReserved(err) ||
models.IsErrNamePatternNotAllowed(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "CreateOrganization", err)
+ c.Error(500, "CreateOrganization", err)
}
return
}
- ctx.JSON(201, convert.ToOrganization(org))
+ c.JSON(201, convert.ToOrganization(org))
}
diff --git a/routers/api/v1/admin/org_repo.go b/routers/api/v1/admin/org_repo.go
index 02ff35ba..7abad1a8 100644
--- a/routers/api/v1/admin/org_repo.go
+++ b/routers/api/v1/admin/org_repo.go
@@ -10,41 +10,41 @@ import (
"github.com/gogits/gogs/pkg/context"
)
-func GetRepositoryByParams(ctx *context.APIContext) *models.Repository {
- repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
+func GetRepositoryByParams(c *context.APIContext) *models.Repository {
+ repo, err := models.GetRepositoryByName(c.Org.Team.OrgID, c.Params(":reponame"))
if err != nil {
if errors.IsRepoNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetRepositoryByName", err)
+ c.Error(500, "GetRepositoryByName", err)
}
return nil
}
return repo
}
-func AddTeamRepository(ctx *context.APIContext) {
- repo := GetRepositoryByParams(ctx)
- if ctx.Written() {
+func AddTeamRepository(c *context.APIContext) {
+ repo := GetRepositoryByParams(c)
+ if c.Written() {
return
}
- if err := ctx.Org.Team.AddRepository(repo); err != nil {
- ctx.Error(500, "AddRepository", err)
+ if err := c.Org.Team.AddRepository(repo); err != nil {
+ c.Error(500, "AddRepository", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
-func RemoveTeamRepository(ctx *context.APIContext) {
- repo := GetRepositoryByParams(ctx)
- if ctx.Written() {
+func RemoveTeamRepository(c *context.APIContext) {
+ repo := GetRepositoryByParams(c)
+ if c.Written() {
return
}
- if err := ctx.Org.Team.RemoveRepository(repo.ID); err != nil {
- ctx.Error(500, "RemoveRepository", err)
+ if err := c.Org.Team.RemoveRepository(repo.ID); err != nil {
+ c.Error(500, "RemoveRepository", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/admin/org_team.go b/routers/api/v1/admin/org_team.go
index dfed0c86..7ec6c08a 100644
--- a/routers/api/v1/admin/org_team.go
+++ b/routers/api/v1/admin/org_team.go
@@ -13,48 +13,48 @@ import (
"github.com/gogits/gogs/routers/api/v1/user"
)
-func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
+func CreateTeam(c *context.APIContext, form api.CreateTeamOption) {
team := &models.Team{
- OrgID: ctx.Org.Organization.ID,
+ OrgID: c.Org.Organization.ID,
Name: form.Name,
Description: form.Description,
Authorize: models.ParseAccessMode(form.Permission),
}
if err := models.NewTeam(team); err != nil {
if models.IsErrTeamAlreadyExist(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "NewTeam", err)
+ c.Error(500, "NewTeam", err)
}
return
}
- ctx.JSON(201, convert.ToTeam(team))
+ c.JSON(201, convert.ToTeam(team))
}
-func AddTeamMember(ctx *context.APIContext) {
- u := user.GetUserByParams(ctx)
- if ctx.Written() {
+func AddTeamMember(c *context.APIContext) {
+ u := user.GetUserByParams(c)
+ if c.Written() {
return
}
- if err := ctx.Org.Team.AddMember(u.ID); err != nil {
- ctx.Error(500, "AddMember", err)
+ if err := c.Org.Team.AddMember(u.ID); err != nil {
+ c.Error(500, "AddMember", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
-func RemoveTeamMember(ctx *context.APIContext) {
- u := user.GetUserByParams(ctx)
- if ctx.Written() {
+func RemoveTeamMember(c *context.APIContext) {
+ u := user.GetUserByParams(c)
+ if c.Written() {
return
}
- if err := ctx.Org.Team.RemoveMember(u.ID); err != nil {
- ctx.Error(500, "RemoveMember", err)
+ if err := c.Org.Team.RemoveMember(u.ID); err != nil {
+ c.Error(500, "RemoveMember", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/admin/repo.go b/routers/api/v1/admin/repo.go
index 8b199937..6c8e8e8d 100644
--- a/routers/api/v1/admin/repo.go
+++ b/routers/api/v1/admin/repo.go
@@ -13,11 +13,11 @@ import (
)
// https://github.com/gogits/go-gogs-client/wiki/Administration-Repositories#create-a-new-repository
-func CreateRepo(ctx *context.APIContext, form api.CreateRepoOption) {
- owner := user.GetUserByParams(ctx)
- if ctx.Written() {
+func CreateRepo(c *context.APIContext, form api.CreateRepoOption) {
+ owner := user.GetUserByParams(c)
+ if c.Written() {
return
}
- repo.CreateUserRepo(ctx, owner, form)
+ repo.CreateUserRepo(c, owner, form)
}
diff --git a/routers/api/v1/admin/user.go b/routers/api/v1/admin/user.go
index 7565ab2c..8776217d 100644
--- a/routers/api/v1/admin/user.go
+++ b/routers/api/v1/admin/user.go
@@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/routers/api/v1/user"
)
-func parseLoginSource(ctx *context.APIContext, u *models.User, sourceID int64, loginName string) {
+func parseLoginSource(c *context.APIContext, u *models.User, sourceID int64, loginName string) {
if sourceID == 0 {
return
}
@@ -24,9 +24,9 @@ func parseLoginSource(ctx *context.APIContext, u *models.User, sourceID int64, l
source, err := models.GetLoginSourceByID(sourceID)
if err != nil {
if models.IsErrLoginSourceNotExist(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "GetLoginSourceByID", err)
+ c.Error(500, "GetLoginSourceByID", err)
}
return
}
@@ -37,7 +37,7 @@ func parseLoginSource(ctx *context.APIContext, u *models.User, sourceID int64, l
}
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-new-user
-func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
+func CreateUser(c *context.APIContext, form api.CreateUserOption) {
u := &models.User{
Name: form.Username,
FullName: form.FullName,
@@ -47,8 +47,8 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
LoginType: models.LOGIN_PLAIN,
}
- parseLoginSource(ctx, u, form.SourceID, form.LoginName)
- if ctx.Written() {
+ parseLoginSource(c, u, form.SourceID, form.LoginName)
+ if c.Written() {
return
}
@@ -57,31 +57,31 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
models.IsErrEmailAlreadyUsed(err) ||
models.IsErrNameReserved(err) ||
models.IsErrNamePatternNotAllowed(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "CreateUser", err)
+ c.Error(500, "CreateUser", err)
}
return
}
- log.Trace("Account created by admin (%s): %s", ctx.User.Name, u.Name)
+ log.Trace("Account created by admin (%s): %s", c.User.Name, u.Name)
// Send email notification.
if form.SendNotify && setting.MailService != nil {
- mailer.SendRegisterNotifyMail(ctx.Context.Context, models.NewMailerUser(u))
+ mailer.SendRegisterNotifyMail(c.Context.Context, models.NewMailerUser(u))
}
- ctx.JSON(201, u.APIFormat())
+ c.JSON(201, u.APIFormat())
}
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#edit-an-existing-user
-func EditUser(ctx *context.APIContext, form api.EditUserOption) {
- u := user.GetUserByParams(ctx)
- if ctx.Written() {
+func EditUser(c *context.APIContext, form api.EditUserOption) {
+ u := user.GetUserByParams(c)
+ if c.Written() {
return
}
- parseLoginSource(ctx, u, form.SourceID, form.LoginName)
- if ctx.Written() {
+ parseLoginSource(c, u, form.SourceID, form.LoginName)
+ if c.Written() {
return
}
@@ -89,7 +89,7 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
u.Passwd = form.Password
var err error
if u.Salt, err = models.GetUserSalt(); err != nil {
- ctx.Error(500, "UpdateUser", err)
+ c.Error(500, "UpdateUser", err)
return
}
u.EncodePasswd()
@@ -118,43 +118,43 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
if err := models.UpdateUser(u); err != nil {
if models.IsErrEmailAlreadyUsed(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "UpdateUser", err)
+ c.Error(500, "UpdateUser", err)
}
return
}
- log.Trace("Account profile updated by admin (%s): %s", ctx.User.Name, u.Name)
+ log.Trace("Account profile updated by admin (%s): %s", c.User.Name, u.Name)
- ctx.JSON(200, u.APIFormat())
+ c.JSON(200, u.APIFormat())
}
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user
-func DeleteUser(ctx *context.APIContext) {
- u := user.GetUserByParams(ctx)
- if ctx.Written() {
+func DeleteUser(c *context.APIContext) {
+ u := user.GetUserByParams(c)
+ if c.Written() {
return
}
if err := models.DeleteUser(u); err != nil {
if models.IsErrUserOwnRepos(err) ||
models.IsErrUserHasOrgs(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "DeleteUser", err)
+ c.Error(500, "DeleteUser", err)
}
return
}
- log.Trace("Account deleted by admin(%s): %s", ctx.User.Name, u.Name)
+ log.Trace("Account deleted by admin(%s): %s", c.User.Name, u.Name)
- ctx.Status(204)
+ c.Status(204)
}
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-public-key-for-user
-func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
- u := user.GetUserByParams(ctx)
- if ctx.Written() {
+func CreatePublicKey(c *context.APIContext, form api.CreateKeyOption) {
+ u := user.GetUserByParams(c)
+ if c.Written() {
return
}
- user.CreateUserPublicKey(ctx, form, u.ID)
+ user.CreateUserPublicKey(c, form, u.ID)
}
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index b54e47b7..35ca861a 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -24,9 +24,9 @@ import (
)
func repoAssignment() macaron.Handler {
- return func(ctx *context.APIContext) {
- userName := ctx.Params(":username")
- repoName := ctx.Params(":reponame")
+ return func(c *context.APIContext) {
+ userName := c.Params(":username")
+ repoName := c.Params(":reponame")
var (
owner *models.User
@@ -34,87 +34,87 @@ func repoAssignment() macaron.Handler {
)
// Check if the user is the same as the repository owner.
- if ctx.IsLogged && ctx.User.LowerName == strings.ToLower(userName) {
- owner = ctx.User
+ if c.IsLogged && c.User.LowerName == strings.ToLower(userName) {
+ owner = c.User
} else {
owner, err = models.GetUserByName(userName)
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetUserByName", err)
+ c.Error(500, "GetUserByName", err)
}
return
}
}
- ctx.Repo.Owner = owner
+ c.Repo.Owner = owner
// Get repository.
repo, err := models.GetRepositoryByName(owner.ID, repoName)
if err != nil {
if errors.IsRepoNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetRepositoryByName", err)
+ c.Error(500, "GetRepositoryByName", err)
}
return
} else if err = repo.GetOwner(); err != nil {
- ctx.Error(500, "GetOwner", err)
+ c.Error(500, "GetOwner", err)
return
}
- if ctx.IsLogged && ctx.User.IsAdmin {
- ctx.Repo.AccessMode = models.ACCESS_MODE_OWNER
+ if c.IsLogged && c.User.IsAdmin {
+ c.Repo.AccessMode = models.ACCESS_MODE_OWNER
} else {
- mode, err := models.AccessLevel(ctx.User.ID, repo)
+ mode, err := models.AccessLevel(c.User.ID, repo)
if err != nil {
- ctx.Error(500, "AccessLevel", err)
+ c.Error(500, "AccessLevel", err)
return
}
- ctx.Repo.AccessMode = mode
+ c.Repo.AccessMode = mode
}
- if !ctx.Repo.HasAccess() {
- ctx.Status(404)
+ if !c.Repo.HasAccess() {
+ c.Status(404)
return
}
- ctx.Repo.Repository = repo
+ c.Repo.Repository = repo
}
}
// Contexter middleware already checks token for user sign in process.
func reqToken() macaron.Handler {
- return func(ctx *context.Context) {
- if !ctx.IsLogged {
- ctx.Error(401)
+ return func(c *context.Context) {
+ if !c.IsLogged {
+ c.Error(401)
return
}
}
}
func reqBasicAuth() macaron.Handler {
- return func(ctx *context.Context) {
- if !ctx.IsBasicAuth {
- ctx.Error(401)
+ return func(c *context.Context) {
+ if !c.IsBasicAuth {
+ c.Error(401)
return
}
}
}
func reqAdmin() macaron.Handler {
- return func(ctx *context.Context) {
- if !ctx.IsLogged || !ctx.User.IsAdmin {
- ctx.Error(403)
+ return func(c *context.Context) {
+ if !c.IsLogged || !c.User.IsAdmin {
+ c.Error(403)
return
}
}
}
func reqRepoWriter() macaron.Handler {
- return func(ctx *context.Context) {
- if !ctx.Repo.IsWriter() {
- ctx.Error(403)
+ return func(c *context.Context) {
+ if !c.Repo.IsWriter() {
+ c.Error(403)
return
}
}
@@ -131,29 +131,29 @@ func orgAssignment(args ...bool) macaron.Handler {
if len(args) > 1 {
assignTeam = args[1]
}
- return func(ctx *context.APIContext) {
- ctx.Org = new(context.APIOrganization)
+ return func(c *context.APIContext) {
+ c.Org = new(context.APIOrganization)
var err error
if assignOrg {
- ctx.Org.Organization, err = models.GetUserByName(ctx.Params(":orgname"))
+ c.Org.Organization, err = models.GetUserByName(c.Params(":orgname"))
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetUserByName", err)
+ c.Error(500, "GetUserByName", err)
}
return
}
}
if assignTeam {
- ctx.Org.Team, err = models.GetTeamByID(ctx.ParamsInt64(":teamid"))
+ c.Org.Team, err = models.GetTeamByID(c.ParamsInt64(":teamid"))
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetTeamById", err)
+ c.Error(500, "GetTeamById", err)
}
return
}
@@ -161,9 +161,9 @@ func orgAssignment(args ...bool) macaron.Handler {
}
}
-func mustEnableIssues(ctx *context.APIContext) {
- if !ctx.Repo.Repository.EnableIssues || ctx.Repo.Repository.EnableExternalTracker {
- ctx.Status(404)
+func mustEnableIssues(c *context.APIContext) {
+ if !c.Repo.Repository.EnableIssues || c.Repo.Repository.EnableExternalTracker {
+ c.Status(404)
return
}
}
@@ -323,8 +323,8 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Combo("/teams").Get(org.ListTeams)
}, orgAssignment(true))
- m.Any("/*", func(ctx *context.Context) {
- ctx.Error(404)
+ m.Any("/*", func(c *context.Context) {
+ c.Error(404)
})
m.Group("/admin", func() {
diff --git a/routers/api/v1/misc/markdown.go b/routers/api/v1/misc/markdown.go
index d4419d57..98bfd7d0 100644
--- a/routers/api/v1/misc/markdown.go
+++ b/routers/api/v1/misc/markdown.go
@@ -12,31 +12,31 @@ import (
)
// https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-an-arbitrary-markdown-document
-func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
- if ctx.HasApiError() {
- ctx.Error(422, "", ctx.GetErrMsg())
+func Markdown(c *context.APIContext, form api.MarkdownOption) {
+ if c.HasApiError() {
+ c.Error(422, "", c.GetErrMsg())
return
}
if len(form.Text) == 0 {
- ctx.Write([]byte(""))
+ c.Write([]byte(""))
return
}
switch form.Mode {
case "gfm":
- ctx.Write(markup.Markdown([]byte(form.Text), form.Context, nil))
+ c.Write(markup.Markdown([]byte(form.Text), form.Context, nil))
default:
- ctx.Write(markup.RawMarkdown([]byte(form.Text), ""))
+ c.Write(markup.RawMarkdown([]byte(form.Text), ""))
}
}
// https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-a-markdown-document-in-raw-mode
-func MarkdownRaw(ctx *context.APIContext) {
- body, err := ctx.Req.Body().Bytes()
+func MarkdownRaw(c *context.APIContext) {
+ body, err := c.Req.Body().Bytes()
if err != nil {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
return
}
- ctx.Write(markup.RawMarkdown(body, ""))
+ c.Write(markup.RawMarkdown(body, ""))
}
diff --git a/routers/api/v1/org/org.go b/routers/api/v1/org/org.go
index 3b3576a7..107fc19c 100644
--- a/routers/api/v1/org/org.go
+++ b/routers/api/v1/org/org.go
@@ -13,9 +13,9 @@ import (
"github.com/gogits/gogs/routers/api/v1/user"
)
-func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) {
+func listUserOrgs(c *context.APIContext, u *models.User, all bool) {
if err := u.GetOrganizations(all); err != nil {
- ctx.Error(500, "GetOrganizations", err)
+ c.Error(500, "GetOrganizations", err)
return
}
@@ -23,33 +23,33 @@ func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) {
for i := range u.Orgs {
apiOrgs[i] = convert.ToOrganization(u.Orgs[i])
}
- ctx.JSON(200, &apiOrgs)
+ c.JSON(200, &apiOrgs)
}
// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-your-organizations
-func ListMyOrgs(ctx *context.APIContext) {
- listUserOrgs(ctx, ctx.User, true)
+func ListMyOrgs(c *context.APIContext) {
+ listUserOrgs(c, c.User, true)
}
// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-user-organizations
-func ListUserOrgs(ctx *context.APIContext) {
- u := user.GetUserByParams(ctx)
- if ctx.Written() {
+func ListUserOrgs(c *context.APIContext) {
+ u := user.GetUserByParams(c)
+ if c.Written() {
return
}
- listUserOrgs(ctx, u, false)
+ listUserOrgs(c, u, false)
}
// https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization
-func Get(ctx *context.APIContext) {
- ctx.JSON(200, convert.ToOrganization(ctx.Org.Organization))
+func Get(c *context.APIContext) {
+ c.JSON(200, convert.ToOrganization(c.Org.Organization))
}
// https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization
-func Edit(ctx *context.APIContext, form api.EditOrgOption) {
- org := ctx.Org.Organization
- if !org.IsOwnedBy(ctx.User.ID) {
- ctx.Status(403)
+func Edit(c *context.APIContext, form api.EditOrgOption) {
+ org := c.Org.Organization
+ if !org.IsOwnedBy(c.User.ID) {
+ c.Status(403)
return
}
@@ -58,9 +58,9 @@ func Edit(ctx *context.APIContext, form api.EditOrgOption) {
org.Website = form.Website
org.Location = form.Location
if err := models.UpdateUser(org); err != nil {
- ctx.Error(500, "UpdateUser", err)
+ c.Error(500, "UpdateUser", err)
return
}
- ctx.JSON(200, convert.ToOrganization(org))
+ c.JSON(200, convert.ToOrganization(org))
}
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go
index 8b0f4008..a952ea53 100644
--- a/routers/api/v1/org/team.go
+++ b/routers/api/v1/org/team.go
@@ -11,10 +11,10 @@ import (
"github.com/gogits/gogs/routers/api/v1/convert"
)
-func ListTeams(ctx *context.APIContext) {
- org := ctx.Org.Organization
+func ListTeams(c *context.APIContext) {
+ org := c.Org.Organization
if err := org.GetTeams(); err != nil {
- ctx.Error(500, "GetTeams", err)
+ c.Error(500, "GetTeams", err)
return
}
@@ -22,5 +22,5 @@ func ListTeams(ctx *context.APIContext) {
for i := range org.Teams {
apiTeams[i] = convert.ToTeam(org.Teams[i])
}
- ctx.JSON(200, apiTeams)
+ c.JSON(200, apiTeams)
}
diff --git a/routers/api/v1/repo/branch.go b/routers/api/v1/repo/branch.go
index df950040..3d5e646c 100644
--- a/routers/api/v1/repo/branch.go
+++ b/routers/api/v1/repo/branch.go
@@ -13,43 +13,43 @@ import (
)
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch
-func GetBranch(ctx *context.APIContext) {
- branch, err := ctx.Repo.Repository.GetBranch(ctx.Params("*"))
+func GetBranch(c *context.APIContext) {
+ branch, err := c.Repo.Repository.GetBranch(c.Params("*"))
if err != nil {
if models.IsErrBranchNotExist(err) {
- ctx.Error(404, "GetBranch", err)
+ c.Error(404, "GetBranch", err)
} else {
- ctx.Error(500, "GetBranch", err)
+ c.Error(500, "GetBranch", err)
}
return
}
- c, err := branch.GetCommit()
+ commit, err := branch.GetCommit()
if err != nil {
- ctx.Error(500, "GetCommit", err)
+ c.Error(500, "GetCommit", err)
return
}
- ctx.JSON(200, convert.ToBranch(branch, c))
+ c.JSON(200, convert.ToBranch(branch, commit))
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches
-func ListBranches(ctx *context.APIContext) {
- branches, err := ctx.Repo.Repository.GetBranches()
+func ListBranches(c *context.APIContext) {
+ branches, err := c.Repo.Repository.GetBranches()
if err != nil {
- ctx.Error(500, "GetBranches", err)
+ c.Error(500, "GetBranches", err)
return
}
apiBranches := make([]*api.Branch, len(branches))
for i := range branches {
- c, err := branches[i].GetCommit()
+ commit, err := branches[i].GetCommit()
if err != nil {
- ctx.Error(500, "GetCommit", err)
+ c.Error(500, "GetCommit", err)
return
}
- apiBranches[i] = convert.ToBranch(branches[i], c)
+ apiBranches[i] = convert.ToBranch(branches[i], commit)
}
- ctx.JSON(200, &apiBranches)
+ c.JSON(200, &apiBranches)
}
diff --git a/routers/api/v1/repo/collaborators.go b/routers/api/v1/repo/collaborators.go
index ff109be5..d295ac0f 100644
--- a/routers/api/v1/repo/collaborators.go
+++ b/routers/api/v1/repo/collaborators.go
@@ -12,13 +12,13 @@ import (
"github.com/gogits/gogs/pkg/context"
)
-func ListCollaborators(ctx *context.APIContext) {
- collaborators, err := ctx.Repo.Repository.GetCollaborators()
+func ListCollaborators(c *context.APIContext) {
+ collaborators, err := c.Repo.Repository.GetCollaborators()
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "GetCollaborators", err)
+ c.Error(500, "GetCollaborators", err)
}
return
}
@@ -27,68 +27,68 @@ func ListCollaborators(ctx *context.APIContext) {
for i := range collaborators {
apiCollaborators[i] = collaborators[i].APIFormat()
}
- ctx.JSON(200, &apiCollaborators)
+ c.JSON(200, &apiCollaborators)
}
-func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
- collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
+func AddCollaborator(c *context.APIContext, form api.AddCollaboratorOption) {
+ collaborator, err := models.GetUserByName(c.Params(":collaborator"))
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "GetUserByName", err)
+ c.Error(500, "GetUserByName", err)
}
return
}
- if err := ctx.Repo.Repository.AddCollaborator(collaborator); err != nil {
- ctx.Error(500, "AddCollaborator", err)
+ if err := c.Repo.Repository.AddCollaborator(collaborator); err != nil {
+ c.Error(500, "AddCollaborator", err)
return
}
if form.Permission != nil {
- if err := ctx.Repo.Repository.ChangeCollaborationAccessMode(collaborator.ID, models.ParseAccessMode(*form.Permission)); err != nil {
- ctx.Error(500, "ChangeCollaborationAccessMode", err)
+ if err := c.Repo.Repository.ChangeCollaborationAccessMode(collaborator.ID, models.ParseAccessMode(*form.Permission)); err != nil {
+ c.Error(500, "ChangeCollaborationAccessMode", err)
return
}
}
- ctx.Status(204)
+ c.Status(204)
}
-func IsCollaborator(ctx *context.APIContext) {
- collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
+func IsCollaborator(c *context.APIContext) {
+ collaborator, err := models.GetUserByName(c.Params(":collaborator"))
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "GetUserByName", err)
+ c.Error(500, "GetUserByName", err)
}
return
}
- if !ctx.Repo.Repository.IsCollaborator(collaborator.ID) {
- ctx.Status(404)
+ if !c.Repo.Repository.IsCollaborator(collaborator.ID) {
+ c.Status(404)
} else {
- ctx.Status(204)
+ c.Status(204)
}
}
-func DeleteCollaborator(ctx *context.APIContext) {
- collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
+func DeleteCollaborator(c *context.APIContext) {
+ collaborator, err := models.GetUserByName(c.Params(":collaborator"))
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "GetUserByName", err)
+ c.Error(500, "GetUserByName", err)
}
return
}
- if err := ctx.Repo.Repository.DeleteCollaboration(collaborator.ID); err != nil {
- ctx.Error(500, "DeleteCollaboration", err)
+ if err := c.Repo.Repository.DeleteCollaboration(collaborator.ID); err != nil {
+ c.Error(500, "DeleteCollaboration", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/repo/file.go b/routers/api/v1/repo/file.go
index 81c399f6..df6a4857 100644
--- a/routers/api/v1/repo/file.go
+++ b/routers/api/v1/repo/file.go
@@ -13,60 +13,60 @@ import (
)
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-raw-content
-func GetRawFile(ctx *context.APIContext) {
- if !ctx.Repo.HasAccess() {
- ctx.Status(404)
+func GetRawFile(c *context.APIContext) {
+ if !c.Repo.HasAccess() {
+ c.Status(404)
return
}
- if ctx.Repo.Repository.IsBare {
- ctx.Status(404)
+ if c.Repo.Repository.IsBare {
+ c.Status(404)
return
}
- blob, err := ctx.Repo.Commit.GetBlobByPath(ctx.Repo.TreePath)
+ blob, err := c.Repo.Commit.GetBlobByPath(c.Repo.TreePath)
if err != nil {
if git.IsErrNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetBlobByPath", err)
+ c.Error(500, "GetBlobByPath", err)
}
return
}
- if err = repo.ServeBlob(ctx.Context, blob); err != nil {
- ctx.Error(500, "ServeBlob", err)
+ if err = repo.ServeBlob(c.Context, blob); err != nil {
+ c.Error(500, "ServeBlob", err)
}
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive
-func GetArchive(ctx *context.APIContext) {
- repoPath := models.RepoPath(ctx.Params(":username"), ctx.Params(":reponame"))
+func GetArchive(c *context.APIContext) {
+ repoPath := models.RepoPath(c.Params(":username"), c.Params(":reponame"))
gitRepo, err := git.OpenRepository(repoPath)
if err != nil {
- ctx.Error(500, "OpenRepository", err)
+ c.Error(500, "OpenRepository", err)
return
}
- ctx.Repo.GitRepo = gitRepo
+ c.Repo.GitRepo = gitRepo
- repo.Download(ctx.Context)
+ repo.Download(c.Context)
}
-func GetEditorconfig(ctx *context.APIContext) {
- ec, err := ctx.Repo.GetEditorconfig()
+func GetEditorconfig(c *context.APIContext) {
+ ec, err := c.Repo.GetEditorconfig()
if err != nil {
if git.IsErrNotExist(err) {
- ctx.Error(404, "GetEditorconfig", err)
+ c.Error(404, "GetEditorconfig", err)
} else {
- ctx.Error(500, "GetEditorconfig", err)
+ c.Error(500, "GetEditorconfig", err)
}
return
}
- fileName := ctx.Params("filename")
+ fileName := c.Params("filename")
def := ec.GetDefinitionForFilename(fileName)
if def == nil {
- ctx.Error(404, "GetDefinitionForFilename", err)
+ c.Error(404, "GetDefinitionForFilename", err)
return
}
- ctx.JSON(200, def)
+ c.JSON(200, def)
}
diff --git a/routers/api/v1/repo/hook.go b/routers/api/v1/repo/hook.go
index 6a4ec85f..7c2b293e 100644
--- a/routers/api/v1/repo/hook.go
+++ b/routers/api/v1/repo/hook.go
@@ -18,34 +18,34 @@ import (
)
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks
-func ListHooks(ctx *context.APIContext) {
- hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
+func ListHooks(c *context.APIContext) {
+ hooks, err := models.GetWebhooksByRepoID(c.Repo.Repository.ID)
if err != nil {
- ctx.Error(500, "GetWebhooksByRepoID", err)
+ c.Error(500, "GetWebhooksByRepoID", err)
return
}
apiHooks := make([]*api.Hook, len(hooks))
for i := range hooks {
- apiHooks[i] = convert.ToHook(ctx.Repo.RepoLink, hooks[i])
+ apiHooks[i] = convert.ToHook(c.Repo.RepoLink, hooks[i])
}
- ctx.JSON(200, &apiHooks)
+ c.JSON(200, &apiHooks)
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook
-func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
+func CreateHook(c *context.APIContext, form api.CreateHookOption) {
if !models.IsValidHookTaskType(form.Type) {
- ctx.Error(422, "", "Invalid hook type")
+ c.Error(422, "", "Invalid hook type")
return
}
for _, name := range []string{"url", "content_type"} {
if _, ok := form.Config[name]; !ok {
- ctx.Error(422, "", "Missing config option: "+name)
+ c.Error(422, "", "Missing config option: "+name)
return
}
}
if !models.IsValidHookContentType(form.Config["content_type"]) {
- ctx.Error(422, "", "Invalid content type")
+ c.Error(422, "", "Invalid content type")
return
}
@@ -53,7 +53,7 @@ func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
form.Events = []string{"push"}
}
w := &models.Webhook{
- RepoID: ctx.Repo.Repository.ID,
+ RepoID: c.Repo.Repository.ID,
URL: form.Config["url"],
ContentType: models.ToHookContentType(form.Config["content_type"]),
Secret: form.Config["secret"],
@@ -76,7 +76,7 @@ func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
if w.HookTaskType == models.SLACK {
channel, ok := form.Config["channel"]
if !ok {
- ctx.Error(422, "", "Missing config option: channel")
+ c.Error(422, "", "Missing config option: channel")
return
}
meta, err := json.Marshal(&models.SlackMeta{
@@ -86,31 +86,31 @@ func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
Color: form.Config["color"],
})
if err != nil {
- ctx.Error(500, "slack: JSON marshal failed", err)
+ c.Error(500, "slack: JSON marshal failed", err)
return
}
w.Meta = string(meta)
}
if err := w.UpdateEvent(); err != nil {
- ctx.Error(500, "UpdateEvent", err)
+ c.Error(500, "UpdateEvent", err)
return
} else if err := models.CreateWebhook(w); err != nil {
- ctx.Error(500, "CreateWebhook", err)
+ c.Error(500, "CreateWebhook", err)
return
}
- ctx.JSON(201, convert.ToHook(ctx.Repo.RepoLink, w))
+ c.JSON(201, convert.ToHook(c.Repo.RepoLink, w))
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook
-func EditHook(ctx *context.APIContext, form api.EditHookOption) {
- w, err := models.GetWebhookOfRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
+func EditHook(c *context.APIContext, form api.EditHookOption) {
+ w, err := models.GetWebhookOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
if err != nil {
if errors.IsWebhookNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetWebhookOfRepoByID", err)
+ c.Error(500, "GetWebhookOfRepoByID", err)
}
return
}
@@ -121,7 +121,7 @@ func EditHook(ctx *context.APIContext, form api.EditHookOption) {
}
if ct, ok := form.Config["content_type"]; ok {
if !models.IsValidHookContentType(ct) {
- ctx.Error(422, "", "Invalid content type")
+ c.Error(422, "", "Invalid content type")
return
}
w.ContentType = models.ToHookContentType(ct)
@@ -136,7 +136,7 @@ func EditHook(ctx *context.APIContext, form api.EditHookOption) {
Color: form.Config["color"],
})
if err != nil {
- ctx.Error(500, "slack: JSON marshal failed", err)
+ c.Error(500, "slack: JSON marshal failed", err)
return
}
w.Meta = string(meta)
@@ -160,7 +160,7 @@ func EditHook(ctx *context.APIContext, form api.EditHookOption) {
w.PullRequest = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_PULL_REQUEST))
w.Release = com.IsSliceContainsStr(form.Events, string(models.HOOK_EVENT_RELEASE))
if err = w.UpdateEvent(); err != nil {
- ctx.Error(500, "UpdateEvent", err)
+ c.Error(500, "UpdateEvent", err)
return
}
@@ -169,18 +169,18 @@ func EditHook(ctx *context.APIContext, form api.EditHookOption) {
}
if err := models.UpdateWebhook(w); err != nil {
- ctx.Error(500, "UpdateWebhook", err)
+ c.Error(500, "UpdateWebhook", err)
return
}
- ctx.JSON(200, convert.ToHook(ctx.Repo.RepoLink, w))
+ c.JSON(200, convert.ToHook(c.Repo.RepoLink, w))
}
-func DeleteHook(ctx *context.APIContext) {
- if err := models.DeleteWebhookOfRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
- ctx.Error(500, "DeleteWebhookByRepoID", err)
+func DeleteHook(c *context.APIContext) {
+ if err := models.DeleteWebhookOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id")); err != nil {
+ c.Error(500, "DeleteWebhookByRepoID", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/repo/issue.go b/routers/api/v1/repo/issue.go
index 5e233a20..4a072633 100644
--- a/routers/api/v1/repo/issue.go
+++ b/routers/api/v1/repo/issue.go
@@ -16,16 +16,16 @@ import (
"github.com/gogits/gogs/pkg/setting"
)
-func listIssues(ctx *context.APIContext, opts *models.IssuesOptions) {
+func listIssues(c *context.APIContext, opts *models.IssuesOptions) {
issues, err := models.Issues(opts)
if err != nil {
- ctx.Error(500, "Issues", err)
+ c.Error(500, "Issues", err)
return
}
count, err := models.IssuesCount(opts)
if err != nil {
- ctx.Error(500, "IssuesCount", err)
+ c.Error(500, "IssuesCount", err)
return
}
@@ -33,64 +33,64 @@ func listIssues(ctx *context.APIContext, opts *models.IssuesOptions) {
apiIssues := make([]*api.Issue, len(issues))
for i := range issues {
if err = issues[i].LoadAttributes(); err != nil {
- ctx.Error(500, "LoadAttributes", err)
+ c.Error(500, "LoadAttributes", err)
return
}
apiIssues[i] = issues[i].APIFormat()
}
- ctx.SetLinkHeader(int(count), setting.UI.IssuePagingNum)
- ctx.JSON(200, &apiIssues)
+ c.SetLinkHeader(int(count), setting.UI.IssuePagingNum)
+ c.JSON(200, &apiIssues)
}
-func ListUserIssues(ctx *context.APIContext) {
+func ListUserIssues(c *context.APIContext) {
opts := models.IssuesOptions{
- AssigneeID: ctx.User.ID,
- Page: ctx.QueryInt("page"),
+ AssigneeID: c.User.ID,
+ Page: c.QueryInt("page"),
}
- listIssues(ctx, &opts)
+ listIssues(c, &opts)
}
-func ListIssues(ctx *context.APIContext) {
+func ListIssues(c *context.APIContext) {
opts := models.IssuesOptions{
- RepoID: ctx.Repo.Repository.ID,
- Page: ctx.QueryInt("page"),
+ RepoID: c.Repo.Repository.ID,
+ Page: c.QueryInt("page"),
}
- listIssues(ctx, &opts)
+ listIssues(c, &opts)
}
-func GetIssue(ctx *context.APIContext) {
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+func GetIssue(c *context.APIContext) {
+ issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
if err != nil {
if errors.IsIssueNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ c.Error(500, "GetIssueByIndex", err)
}
return
}
- ctx.JSON(200, issue.APIFormat())
+ c.JSON(200, issue.APIFormat())
}
-func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
+func CreateIssue(c *context.APIContext, form api.CreateIssueOption) {
issue := &models.Issue{
- RepoID: ctx.Repo.Repository.ID,
+ RepoID: c.Repo.Repository.ID,
Title: form.Title,
- PosterID: ctx.User.ID,
- Poster: ctx.User,
+ PosterID: c.User.ID,
+ Poster: c.User,
Content: form.Body,
}
- if ctx.Repo.IsWriter() {
+ if c.Repo.IsWriter() {
if len(form.Assignee) > 0 {
assignee, err := models.GetUserByName(form.Assignee)
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Error(422, "", fmt.Sprintf("Assignee does not exist: [name: %s]", form.Assignee))
+ c.Error(422, "", fmt.Sprintf("Assignee does not exist: [name: %s]", form.Assignee))
} else {
- ctx.Error(500, "GetUserByName", err)
+ c.Error(500, "GetUserByName", err)
}
return
}
@@ -101,14 +101,14 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
form.Labels = nil
}
- if err := models.NewIssue(ctx.Repo.Repository, issue, form.Labels, nil); err != nil {
- ctx.Error(500, "NewIssue", err)
+ if err := models.NewIssue(c.Repo.Repository, issue, form.Labels, nil); err != nil {
+ c.Error(500, "NewIssue", err)
return
}
if form.Closed {
- if err := issue.ChangeStatus(ctx.User, ctx.Repo.Repository, true); err != nil {
- ctx.Error(500, "ChangeStatus", err)
+ if err := issue.ChangeStatus(c.User, c.Repo.Repository, true); err != nil {
+ c.Error(500, "ChangeStatus", err)
return
}
}
@@ -117,25 +117,25 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
var err error
issue, err = models.GetIssueByID(issue.ID)
if err != nil {
- ctx.Error(500, "GetIssueByID", err)
+ c.Error(500, "GetIssueByID", err)
return
}
- ctx.JSON(201, issue.APIFormat())
+ c.JSON(201, issue.APIFormat())
}
-func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+func EditIssue(c *context.APIContext, form api.EditIssueOption) {
+ issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
if err != nil {
if errors.IsIssueNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ c.Error(500, "GetIssueByIndex", err)
}
return
}
- if !issue.IsPoster(ctx.User.ID) && !ctx.Repo.IsWriter() {
- ctx.Status(403)
+ if !issue.IsPoster(c.User.ID) && !c.Repo.IsWriter() {
+ c.Status(403)
return
}
@@ -146,7 +146,7 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
issue.Content = *form.Body
}
- if ctx.Repo.IsWriter() && form.Assignee != nil &&
+ if c.Repo.IsWriter() && form.Assignee != nil &&
(issue.Assignee == nil || issue.Assignee.LowerName != strings.ToLower(*form.Assignee)) {
if len(*form.Assignee) == 0 {
issue.AssigneeID = 0
@@ -154,9 +154,9 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
assignee, err := models.GetUserByName(*form.Assignee)
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Error(422, "", fmt.Sprintf("assignee does not exist: [name: %s]", *form.Assignee))
+ c.Error(422, "", fmt.Sprintf("assignee does not exist: [name: %s]", *form.Assignee))
} else {
- ctx.Error(500, "GetUserByName", err)
+ c.Error(500, "GetUserByName", err)
}
return
}
@@ -164,27 +164,27 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
}
if err = models.UpdateIssueUserByAssignee(issue); err != nil {
- ctx.Error(500, "UpdateIssueUserByAssignee", err)
+ c.Error(500, "UpdateIssueUserByAssignee", err)
return
}
}
- if ctx.Repo.IsWriter() && form.Milestone != nil &&
+ if c.Repo.IsWriter() && form.Milestone != nil &&
issue.MilestoneID != *form.Milestone {
oldMilestoneID := issue.MilestoneID
issue.MilestoneID = *form.Milestone
- if err = models.ChangeMilestoneAssign(ctx.User, issue, oldMilestoneID); err != nil {
- ctx.Error(500, "ChangeMilestoneAssign", err)
+ if err = models.ChangeMilestoneAssign(c.User, issue, oldMilestoneID); err != nil {
+ c.Error(500, "ChangeMilestoneAssign", err)
return
}
}
if err = models.UpdateIssue(issue); err != nil {
- ctx.Error(500, "UpdateIssue", err)
+ c.Error(500, "UpdateIssue", err)
return
}
if form.State != nil {
- if err = issue.ChangeStatus(ctx.User, ctx.Repo.Repository, api.STATE_CLOSED == api.StateType(*form.State)); err != nil {
- ctx.Error(500, "ChangeStatus", err)
+ if err = issue.ChangeStatus(c.User, c.Repo.Repository, api.STATE_CLOSED == api.StateType(*form.State)); err != nil {
+ c.Error(500, "ChangeStatus", err)
return
}
}
@@ -192,8 +192,8 @@ func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
// Refetch from database to assign some automatic values
issue, err = models.GetIssueByID(issue.ID)
if err != nil {
- ctx.Error(500, "GetIssueByID", err)
+ c.Error(500, "GetIssueByID", err)
return
}
- ctx.JSON(201, issue.APIFormat())
+ c.JSON(201, issue.APIFormat())
}
diff --git a/routers/api/v1/repo/issue_comment.go b/routers/api/v1/repo/issue_comment.go
index 04ecd216..4a057d76 100644
--- a/routers/api/v1/repo/issue_comment.go
+++ b/routers/api/v1/repo/issue_comment.go
@@ -12,22 +12,22 @@ import (
"github.com/gogits/gogs/pkg/context"
)
-func ListIssueComments(ctx *context.APIContext) {
+func ListIssueComments(c *context.APIContext) {
var since time.Time
- if len(ctx.Query("since")) > 0 {
- since, _ = time.Parse(time.RFC3339, ctx.Query("since"))
+ if len(c.Query("since")) > 0 {
+ since, _ = time.Parse(time.RFC3339, c.Query("since"))
}
// comments,err:=models.GetCommentsByIssueIDSince(, since)
- issue, err := models.GetRawIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ issue, err := models.GetRawIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
if err != nil {
- ctx.Error(500, "GetRawIssueByIndex", err)
+ c.Error(500, "GetRawIssueByIndex", err)
return
}
comments, err := models.GetCommentsByIssueIDSince(issue.ID, since.Unix())
if err != nil {
- ctx.Error(500, "GetCommentsByIssueIDSince", err)
+ c.Error(500, "GetCommentsByIssueIDSince", err)
return
}
@@ -35,18 +35,18 @@ func ListIssueComments(ctx *context.APIContext) {
for i := range comments {
apiComments[i] = comments[i].APIFormat()
}
- ctx.JSON(200, &apiComments)
+ c.JSON(200, &apiComments)
}
-func ListRepoIssueComments(ctx *context.APIContext) {
+func ListRepoIssueComments(c *context.APIContext) {
var since time.Time
- if len(ctx.Query("since")) > 0 {
- since, _ = time.Parse(time.RFC3339, ctx.Query("since"))
+ if len(c.Query("since")) > 0 {
+ since, _ = time.Parse(time.RFC3339, c.Query("since"))
}
- comments, err := models.GetCommentsByRepoIDSince(ctx.Repo.Repository.ID, since.Unix())
+ comments, err := models.GetCommentsByRepoIDSince(c.Repo.Repository.ID, since.Unix())
if err != nil {
- ctx.Error(500, "GetCommentsByRepoIDSince", err)
+ c.Error(500, "GetCommentsByRepoIDSince", err)
return
}
@@ -54,75 +54,75 @@ func ListRepoIssueComments(ctx *context.APIContext) {
for i := range comments {
apiComments[i] = comments[i].APIFormat()
}
- ctx.JSON(200, &apiComments)
+ c.JSON(200, &apiComments)
}
-func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOption) {
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+func CreateIssueComment(c *context.APIContext, form api.CreateIssueCommentOption) {
+ issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
if err != nil {
- ctx.Error(500, "GetIssueByIndex", err)
+ c.Error(500, "GetIssueByIndex", err)
return
}
- comment, err := models.CreateIssueComment(ctx.User, ctx.Repo.Repository, issue, form.Body, nil)
+ comment, err := models.CreateIssueComment(c.User, c.Repo.Repository, issue, form.Body, nil)
if err != nil {
- ctx.Error(500, "CreateIssueComment", err)
+ c.Error(500, "CreateIssueComment", err)
return
}
- ctx.JSON(201, comment.APIFormat())
+ c.JSON(201, comment.APIFormat())
}
-func EditIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) {
- comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
+func EditIssueComment(c *context.APIContext, form api.EditIssueCommentOption) {
+ comment, err := models.GetCommentByID(c.ParamsInt64(":id"))
if err != nil {
if models.IsErrCommentNotExist(err) {
- ctx.Error(404, "GetCommentByID", err)
+ c.Error(404, "GetCommentByID", err)
} else {
- ctx.Error(500, "GetCommentByID", err)
+ c.Error(500, "GetCommentByID", err)
}
return
}
- if ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin() {
- ctx.Status(403)
+ if c.User.ID != comment.PosterID && !c.Repo.IsAdmin() {
+ c.Status(403)
return
} else if comment.Type != models.COMMENT_TYPE_COMMENT {
- ctx.Status(204)
+ c.Status(204)
return
}
oldContent := comment.Content
comment.Content = form.Body
- if err := models.UpdateComment(ctx.User, comment, oldContent); err != nil {
- ctx.Error(500, "UpdateComment", err)
+ if err := models.UpdateComment(c.User, comment, oldContent); err != nil {
+ c.Error(500, "UpdateComment", err)
return
}
- ctx.JSON(200, comment.APIFormat())
+ c.JSON(200, comment.APIFormat())
}
-func DeleteIssueComment(ctx *context.APIContext) {
- comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
+func DeleteIssueComment(c *context.APIContext) {
+ comment, err := models.GetCommentByID(c.ParamsInt64(":id"))
if err != nil {
if models.IsErrCommentNotExist(err) {
- ctx.Error(404, "GetCommentByID", err)
+ c.Error(404, "GetCommentByID", err)
} else {
- ctx.Error(500, "GetCommentByID", err)
+ c.Error(500, "GetCommentByID", err)
}
return
}
- if ctx.User.ID != comment.PosterID && !ctx.Repo.IsAdmin() {
- ctx.Status(403)
+ if c.User.ID != comment.PosterID && !c.Repo.IsAdmin() {
+ c.Status(403)
return
} else if comment.Type != models.COMMENT_TYPE_COMMENT {
- ctx.Status(204)
+ c.Status(204)
return
}
- if err = models.DeleteCommentByID(ctx.User, comment.ID); err != nil {
- ctx.Error(500, "DeleteCommentByID", err)
+ if err = models.DeleteCommentByID(c.User, comment.ID); err != nil {
+ c.Error(500, "DeleteCommentByID", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/repo/issue_label.go b/routers/api/v1/repo/issue_label.go
index 06c52dc5..f3f2d730 100644
--- a/routers/api/v1/repo/issue_label.go
+++ b/routers/api/v1/repo/issue_label.go
@@ -12,13 +12,13 @@ import (
"github.com/gogits/gogs/pkg/context"
)
-func ListIssueLabels(ctx *context.APIContext) {
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+func ListIssueLabels(c *context.APIContext) {
+ issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
if err != nil {
if errors.IsIssueNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ c.Error(500, "GetIssueByIndex", err)
}
return
}
@@ -27,39 +27,39 @@ func ListIssueLabels(ctx *context.APIContext) {
for i := range issue.Labels {
apiLabels[i] = issue.Labels[i].APIFormat()
}
- ctx.JSON(200, &apiLabels)
+ c.JSON(200, &apiLabels)
}
-func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
- if !ctx.Repo.IsWriter() {
- ctx.Status(403)
+func AddIssueLabels(c *context.APIContext, form api.IssueLabelsOption) {
+ if !c.Repo.IsWriter() {
+ c.Status(403)
return
}
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
if err != nil {
if errors.IsIssueNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ c.Error(500, "GetIssueByIndex", err)
}
return
}
- labels, err := models.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
+ labels, err := models.GetLabelsInRepoByIDs(c.Repo.Repository.ID, form.Labels)
if err != nil {
- ctx.Error(500, "GetLabelsInRepoByIDs", err)
+ c.Error(500, "GetLabelsInRepoByIDs", err)
return
}
- if err = issue.AddLabels(ctx.User, labels); err != nil {
- ctx.Error(500, "AddLabels", err)
+ if err = issue.AddLabels(c.User, labels); err != nil {
+ c.Error(500, "AddLabels", err)
return
}
labels, err = models.GetLabelsByIssueID(issue.ID)
if err != nil {
- ctx.Error(500, "GetLabelsByIssueID", err)
+ c.Error(500, "GetLabelsByIssueID", err)
return
}
@@ -67,73 +67,73 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
for i := range labels {
apiLabels[i] = issue.Labels[i].APIFormat()
}
- ctx.JSON(200, &apiLabels)
+ c.JSON(200, &apiLabels)
}
-func DeleteIssueLabel(ctx *context.APIContext) {
- if !ctx.Repo.IsWriter() {
- ctx.Status(403)
+func DeleteIssueLabel(c *context.APIContext) {
+ if !c.Repo.IsWriter() {
+ c.Status(403)
return
}
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
if err != nil {
if errors.IsIssueNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ c.Error(500, "GetIssueByIndex", err)
}
return
}
- label, err := models.GetLabelOfRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
+ label, err := models.GetLabelOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
if err != nil {
if models.IsErrLabelNotExist(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "GetLabelInRepoByID", err)
+ c.Error(500, "GetLabelInRepoByID", err)
}
return
}
if err := models.DeleteIssueLabel(issue, label); err != nil {
- ctx.Error(500, "DeleteIssueLabel", err)
+ c.Error(500, "DeleteIssueLabel", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
-func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
- if !ctx.Repo.IsWriter() {
- ctx.Status(403)
+func ReplaceIssueLabels(c *context.APIContext, form api.IssueLabelsOption) {
+ if !c.Repo.IsWriter() {
+ c.Status(403)
return
}
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
if err != nil {
if errors.IsIssueNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ c.Error(500, "GetIssueByIndex", err)
}
return
}
- labels, err := models.GetLabelsInRepoByIDs(ctx.Repo.Repository.ID, form.Labels)
+ labels, err := models.GetLabelsInRepoByIDs(c.Repo.Repository.ID, form.Labels)
if err != nil {
- ctx.Error(500, "GetLabelsInRepoByIDs", err)
+ c.Error(500, "GetLabelsInRepoByIDs", err)
return
}
if err := issue.ReplaceLabels(labels); err != nil {
- ctx.Error(500, "ReplaceLabels", err)
+ c.Error(500, "ReplaceLabels", err)
return
}
labels, err = models.GetLabelsByIssueID(issue.ID)
if err != nil {
- ctx.Error(500, "GetLabelsByIssueID", err)
+ c.Error(500, "GetLabelsByIssueID", err)
return
}
@@ -141,29 +141,29 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
for i := range labels {
apiLabels[i] = issue.Labels[i].APIFormat()
}
- ctx.JSON(200, &apiLabels)
+ c.JSON(200, &apiLabels)
}
-func ClearIssueLabels(ctx *context.APIContext) {
- if !ctx.Repo.IsWriter() {
- ctx.Status(403)
+func ClearIssueLabels(c *context.APIContext) {
+ if !c.Repo.IsWriter() {
+ c.Status(403)
return
}
- issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
+ issue, err := models.GetIssueByIndex(c.Repo.Repository.ID, c.ParamsInt64(":index"))
if err != nil {
if errors.IsIssueNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetIssueByIndex", err)
+ c.Error(500, "GetIssueByIndex", err)
}
return
}
- if err := issue.ClearLabels(ctx.User); err != nil {
- ctx.Error(500, "ClearLabels", err)
+ if err := issue.ClearLabels(c.User); err != nil {
+ c.Error(500, "ClearLabels", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/repo/key.go b/routers/api/v1/repo/key.go
index 4ac180f1..901df4c7 100644
--- a/routers/api/v1/repo/key.go
+++ b/routers/api/v1/repo/key.go
@@ -20,95 +20,95 @@ func composeDeployKeysAPILink(repoPath string) string {
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#list-deploy-keys
-func ListDeployKeys(ctx *context.APIContext) {
- keys, err := models.ListDeployKeys(ctx.Repo.Repository.ID)
+func ListDeployKeys(c *context.APIContext) {
+ keys, err := models.ListDeployKeys(c.Repo.Repository.ID)
if err != nil {
- ctx.Error(500, "ListDeployKeys", err)
+ c.Error(500, "ListDeployKeys", err)
return
}
- apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name)
+ apiLink := composeDeployKeysAPILink(c.Repo.Owner.Name + "/" + c.Repo.Repository.Name)
apiKeys := make([]*api.DeployKey, len(keys))
for i := range keys {
if err = keys[i].GetContent(); err != nil {
- ctx.Error(500, "GetContent", err)
+ c.Error(500, "GetContent", err)
return
}
apiKeys[i] = convert.ToDeployKey(apiLink, keys[i])
}
- ctx.JSON(200, &apiKeys)
+ c.JSON(200, &apiKeys)
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#get-a-deploy-key
-func GetDeployKey(ctx *context.APIContext) {
- key, err := models.GetDeployKeyByID(ctx.ParamsInt64(":id"))
+func GetDeployKey(c *context.APIContext) {
+ key, err := models.GetDeployKeyByID(c.ParamsInt64(":id"))
if err != nil {
if models.IsErrDeployKeyNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetDeployKeyByID", err)
+ c.Error(500, "GetDeployKeyByID", err)
}
return
}
if err = key.GetContent(); err != nil {
- ctx.Error(500, "GetContent", err)
+ c.Error(500, "GetContent", err)
return
}
- apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name)
- ctx.JSON(200, convert.ToDeployKey(apiLink, key))
+ apiLink := composeDeployKeysAPILink(c.Repo.Owner.Name + "/" + c.Repo.Repository.Name)
+ c.JSON(200, convert.ToDeployKey(apiLink, key))
}
-func HandleCheckKeyStringError(ctx *context.APIContext, err error) {
+func HandleCheckKeyStringError(c *context.APIContext, err error) {
if models.IsErrKeyUnableVerify(err) {
- ctx.Error(422, "", "Unable to verify key content")
+ c.Error(422, "", "Unable to verify key content")
} else {
- ctx.Error(422, "", fmt.Errorf("Invalid key content: %v", err))
+ c.Error(422, "", fmt.Errorf("Invalid key content: %v", err))
}
}
-func HandleAddKeyError(ctx *context.APIContext, err error) {
+func HandleAddKeyError(c *context.APIContext, err error) {
switch {
case models.IsErrKeyAlreadyExist(err):
- ctx.Error(422, "", "Key content has been used as non-deploy key")
+ c.Error(422, "", "Key content has been used as non-deploy key")
case models.IsErrKeyNameAlreadyUsed(err):
- ctx.Error(422, "", "Key title has been used")
+ c.Error(422, "", "Key title has been used")
default:
- ctx.Error(500, "AddKey", err)
+ c.Error(500, "AddKey", err)
}
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#add-a-new-deploy-key
-func CreateDeployKey(ctx *context.APIContext, form api.CreateKeyOption) {
+func CreateDeployKey(c *context.APIContext, form api.CreateKeyOption) {
content, err := models.CheckPublicKeyString(form.Key)
if err != nil {
- HandleCheckKeyStringError(ctx, err)
+ HandleCheckKeyStringError(c, err)
return
}
- key, err := models.AddDeployKey(ctx.Repo.Repository.ID, form.Title, content)
+ key, err := models.AddDeployKey(c.Repo.Repository.ID, form.Title, content)
if err != nil {
- HandleAddKeyError(ctx, err)
+ HandleAddKeyError(c, err)
return
}
key.Content = content
- apiLink := composeDeployKeysAPILink(ctx.Repo.Owner.Name + "/" + ctx.Repo.Repository.Name)
- ctx.JSON(201, convert.ToDeployKey(apiLink, key))
+ apiLink := composeDeployKeysAPILink(c.Repo.Owner.Name + "/" + c.Repo.Repository.Name)
+ c.JSON(201, convert.ToDeployKey(apiLink, key))
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key
-func DeleteDeploykey(ctx *context.APIContext) {
- if err := models.DeleteDeployKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
+func DeleteDeploykey(c *context.APIContext) {
+ if err := models.DeleteDeployKey(c.User, c.ParamsInt64(":id")); err != nil {
if models.IsErrKeyAccessDenied(err) {
- ctx.Error(403, "", "You do not have access to this key")
+ c.Error(403, "", "You do not have access to this key")
} else {
- ctx.Error(500, "DeleteDeployKey", err)
+ c.Error(500, "DeleteDeployKey", err)
}
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/repo/label.go b/routers/api/v1/repo/label.go
index 32c1924b..289f40a4 100644
--- a/routers/api/v1/repo/label.go
+++ b/routers/api/v1/repo/label.go
@@ -11,10 +11,10 @@ import (
"github.com/gogits/gogs/pkg/context"
)
-func ListLabels(ctx *context.APIContext) {
- labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID)
+func ListLabels(c *context.APIContext) {
+ labels, err := models.GetLabelsByRepoID(c.Repo.Repository.ID)
if err != nil {
- ctx.Error(500, "GetLabelsByRepoID", err)
+ c.Error(500, "GetLabelsByRepoID", err)
return
}
@@ -22,53 +22,53 @@ func ListLabels(ctx *context.APIContext) {
for i := range labels {
apiLabels[i] = labels[i].APIFormat()
}
- ctx.JSON(200, &apiLabels)
+ c.JSON(200, &apiLabels)
}
-func GetLabel(ctx *context.APIContext) {
- label, err := models.GetLabelOfRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
+func GetLabel(c *context.APIContext) {
+ label, err := models.GetLabelOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
if err != nil {
if models.IsErrLabelNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetLabelByRepoID", err)
+ c.Error(500, "GetLabelByRepoID", err)
}
return
}
- ctx.JSON(200, label.APIFormat())
+ c.JSON(200, label.APIFormat())
}
-func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
- if !ctx.Repo.IsWriter() {
- ctx.Status(403)
+func CreateLabel(c *context.APIContext, form api.CreateLabelOption) {
+ if !c.Repo.IsWriter() {
+ c.Status(403)
return
}
label := &models.Label{
Name: form.Name,
Color: form.Color,
- RepoID: ctx.Repo.Repository.ID,
+ RepoID: c.Repo.Repository.ID,
}
if err := models.NewLabels(label); err != nil {
- ctx.Error(500, "NewLabel", err)
+ c.Error(500, "NewLabel", err)
return
}
- ctx.JSON(201, label.APIFormat())
+ c.JSON(201, label.APIFormat())
}
-func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
- if !ctx.Repo.IsWriter() {
- ctx.Status(403)
+func EditLabel(c *context.APIContext, form api.EditLabelOption) {
+ if !c.Repo.IsWriter() {
+ c.Status(403)
return
}
- label, err := models.GetLabelOfRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
+ label, err := models.GetLabelOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
if err != nil {
if models.IsErrLabelNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetLabelByRepoID", err)
+ c.Error(500, "GetLabelByRepoID", err)
}
return
}
@@ -80,22 +80,22 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
label.Color = *form.Color
}
if err := models.UpdateLabel(label); err != nil {
- ctx.Handle(500, "UpdateLabel", err)
+ c.Handle(500, "UpdateLabel", err)
return
}
- ctx.JSON(200, label.APIFormat())
+ c.JSON(200, label.APIFormat())
}
-func DeleteLabel(ctx *context.APIContext) {
- if !ctx.Repo.IsWriter() {
- ctx.Status(403)
+func DeleteLabel(c *context.APIContext) {
+ if !c.Repo.IsWriter() {
+ c.Status(403)
return
}
- if err := models.DeleteLabel(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
- ctx.Error(500, "DeleteLabel", err)
+ if err := models.DeleteLabel(c.Repo.Repository.ID, c.ParamsInt64(":id")); err != nil {
+ c.Error(500, "DeleteLabel", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/repo/milestone.go b/routers/api/v1/repo/milestone.go
index 5133d19b..baf8eb2f 100644
--- a/routers/api/v1/repo/milestone.go
+++ b/routers/api/v1/repo/milestone.go
@@ -13,10 +13,10 @@ import (
"github.com/gogits/gogs/pkg/context"
)
-func ListMilestones(ctx *context.APIContext) {
- milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID)
+func ListMilestones(c *context.APIContext) {
+ milestones, err := models.GetMilestonesByRepoID(c.Repo.Repository.ID)
if err != nil {
- ctx.Error(500, "GetMilestonesByRepoID", err)
+ c.Error(500, "GetMilestonesByRepoID", err)
return
}
@@ -24,49 +24,49 @@ func ListMilestones(ctx *context.APIContext) {
for i := range milestones {
apiMilestones[i] = milestones[i].APIFormat()
}
- ctx.JSON(200, &apiMilestones)
+ c.JSON(200, &apiMilestones)
}
-func GetMilestone(ctx *context.APIContext) {
- milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
+func GetMilestone(c *context.APIContext) {
+ milestone, err := models.GetMilestoneByRepoID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
if err != nil {
if models.IsErrMilestoneNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetMilestoneByRepoID", err)
+ c.Error(500, "GetMilestoneByRepoID", err)
}
return
}
- ctx.JSON(200, milestone.APIFormat())
+ c.JSON(200, milestone.APIFormat())
}
-func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
+func CreateMilestone(c *context.APIContext, form api.CreateMilestoneOption) {
if form.Deadline == nil {
defaultDeadline, _ := time.ParseInLocation("2006-01-02", "9999-12-31", time.Local)
form.Deadline = &defaultDeadline
}
milestone := &models.Milestone{
- RepoID: ctx.Repo.Repository.ID,
+ RepoID: c.Repo.Repository.ID,
Name: form.Title,
Content: form.Description,
Deadline: *form.Deadline,
}
if err := models.NewMilestone(milestone); err != nil {
- ctx.Error(500, "NewMilestone", err)
+ c.Error(500, "NewMilestone", err)
return
}
- ctx.JSON(201, milestone.APIFormat())
+ c.JSON(201, milestone.APIFormat())
}
-func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
- milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
+func EditMilestone(c *context.APIContext, form api.EditMilestoneOption) {
+ milestone, err := models.GetMilestoneByRepoID(c.Repo.Repository.ID, c.ParamsInt64(":id"))
if err != nil {
if models.IsErrMilestoneNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetMilestoneByRepoID", err)
+ c.Error(500, "GetMilestoneByRepoID", err)
}
return
}
@@ -83,21 +83,21 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
if form.State != nil {
if err = milestone.ChangeStatus(api.STATE_CLOSED == api.StateType(*form.State)); err != nil {
- ctx.Error(500, "ChangeStatus", err)
+ c.Error(500, "ChangeStatus", err)
return
}
} else if err = models.UpdateMilestone(milestone); err != nil {
- ctx.Handle(500, "UpdateMilestone", err)
+ c.Handle(500, "UpdateMilestone", err)
return
}
- ctx.JSON(200, milestone.APIFormat())
+ c.JSON(200, milestone.APIFormat())
}
-func DeleteMilestone(ctx *context.APIContext) {
- if err := models.DeleteMilestoneOfRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
- ctx.Error(500, "DeleteMilestoneByRepoID", err)
+func DeleteMilestone(c *context.APIContext) {
+ if err := models.DeleteMilestoneOfRepoByID(c.Repo.Repository.ID, c.ParamsInt64(":id")); err != nil {
+ c.Error(500, "DeleteMilestoneByRepoID", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go
index f86905d4..1095f08d 100644
--- a/routers/api/v1/repo/repo.go
+++ b/routers/api/v1/repo/repo.go
@@ -20,27 +20,27 @@ import (
)
// https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
-func Search(ctx *context.APIContext) {
+func Search(c *context.APIContext) {
opts := &models.SearchRepoOptions{
- Keyword: path.Base(ctx.Query("q")),
- OwnerID: ctx.QueryInt64("uid"),
- PageSize: convert.ToCorrectPageSize(ctx.QueryInt("limit")),
+ Keyword: path.Base(c.Query("q")),
+ OwnerID: c.QueryInt64("uid"),
+ PageSize: convert.ToCorrectPageSize(c.QueryInt("limit")),
}
// Check visibility.
- if ctx.IsLogged && opts.OwnerID > 0 {
- if ctx.User.ID == opts.OwnerID {
+ if c.IsLogged && opts.OwnerID > 0 {
+ if c.User.ID == opts.OwnerID {
opts.Private = true
} else {
u, err := models.GetUserByID(opts.OwnerID)
if err != nil {
- ctx.JSON(500, map[string]interface{}{
+ c.JSON(500, map[string]interface{}{
"ok": false,
"error": err.Error(),
})
return
}
- if u.IsOrganization() && u.IsOwnedBy(ctx.User.ID) {
+ if u.IsOrganization() && u.IsOwnedBy(c.User.ID) {
opts.Private = true
}
// FIXME: how about collaborators?
@@ -49,7 +49,7 @@ func Search(ctx *context.APIContext) {
repos, count, err := models.SearchRepositoryByName(opts)
if err != nil {
- ctx.JSON(500, map[string]interface{}{
+ c.JSON(500, map[string]interface{}{
"ok": false,
"error": err.Error(),
})
@@ -59,7 +59,7 @@ func Search(ctx *context.APIContext) {
results := make([]*api.Repository, len(repos))
for i := range repos {
if err = repos[i].GetOwner(); err != nil {
- ctx.JSON(500, map[string]interface{}{
+ c.JSON(500, map[string]interface{}{
"ok": false,
"error": err.Error(),
})
@@ -71,17 +71,17 @@ func Search(ctx *context.APIContext) {
}
}
- ctx.SetLinkHeader(int(count), setting.API.MaxResponseItems)
- ctx.JSON(200, map[string]interface{}{
+ c.SetLinkHeader(int(count), setting.API.MaxResponseItems)
+ c.JSON(200, map[string]interface{}{
"ok": true,
"data": results,
})
}
-func listUserRepositories(ctx *context.APIContext, username string) {
+func listUserRepositories(c *context.APIContext, username string) {
user, err := models.GetUserByName(username)
if err != nil {
- ctx.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
+ c.NotFoundOrServerError("GetUserByName", errors.IsUserNotExist, err)
return
}
@@ -89,32 +89,32 @@ func listUserRepositories(ctx *context.APIContext, username string) {
// or an organization isn't a member of.
var ownRepos []*models.Repository
if user.IsOrganization() {
- ownRepos, _, err = user.GetUserRepositories(ctx.User.ID, 1, user.NumRepos)
+ ownRepos, _, err = user.GetUserRepositories(c.User.ID, 1, user.NumRepos)
} else {
ownRepos, err = models.GetUserRepositories(&models.UserRepoOptions{
UserID: user.ID,
- Private: ctx.User.ID == user.ID,
+ Private: c.User.ID == user.ID,
Page: 1,
PageSize: user.NumRepos,
})
}
if err != nil {
- ctx.Error(500, "GetUserRepositories", err)
+ c.Error(500, "GetUserRepositories", err)
return
}
- if ctx.User.ID != user.ID {
+ if c.User.ID != user.ID {
repos := make([]*api.Repository, len(ownRepos))
for i := range ownRepos {
repos[i] = ownRepos[i].APIFormat(&api.Permission{true, true, true})
}
- ctx.JSON(200, &repos)
+ c.JSON(200, &repos)
return
}
accessibleRepos, err := user.GetRepositoryAccesses()
if err != nil {
- ctx.Error(500, "GetRepositoryAccesses", err)
+ c.Error(500, "GetRepositoryAccesses", err)
return
}
@@ -134,23 +134,23 @@ func listUserRepositories(ctx *context.APIContext, username string) {
i++
}
- ctx.JSON(200, &repos)
+ c.JSON(200, &repos)
}
-func ListMyRepos(ctx *context.APIContext) {
- listUserRepositories(ctx, ctx.User.Name)
+func ListMyRepos(c *context.APIContext) {
+ listUserRepositories(c, c.User.Name)
}
-func ListUserRepositories(ctx *context.APIContext) {
- listUserRepositories(ctx, ctx.Params(":username"))
+func ListUserRepositories(c *context.APIContext) {
+ listUserRepositories(c, c.Params(":username"))
}
-func ListOrgRepositories(ctx *context.APIContext) {
- listUserRepositories(ctx, ctx.Params(":org"))
+func ListOrgRepositories(c *context.APIContext) {
+ listUserRepositories(c, c.Params(":org"))
}
-func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateRepoOption) {
- repo, err := models.CreateRepository(ctx.User, owner, models.CreateRepoOptions{
+func CreateUserRepo(c *context.APIContext, owner *models.User, opt api.CreateRepoOption) {
+ repo, err := models.CreateRepository(c.User, owner, models.CreateRepoOptions{
Name: opt.Name,
Description: opt.Description,
Gitignores: opt.Gitignores,
@@ -163,104 +163,104 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
if models.IsErrRepoAlreadyExist(err) ||
models.IsErrNameReserved(err) ||
models.IsErrNamePatternNotAllowed(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
if repo != nil {
- if err = models.DeleteRepository(ctx.User.ID, repo.ID); err != nil {
+ if err = models.DeleteRepository(c.User.ID, repo.ID); err != nil {
log.Error(2, "DeleteRepository: %v", err)
}
}
- ctx.Error(500, "CreateRepository", err)
+ c.Error(500, "CreateRepository", err)
}
return
}
- ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
+ c.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create
-func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
+func Create(c *context.APIContext, opt api.CreateRepoOption) {
// Shouldn't reach this condition, but just in case.
- if ctx.User.IsOrganization() {
- ctx.Error(422, "", "not allowed creating repository for organization")
+ if c.User.IsOrganization() {
+ c.Error(422, "", "not allowed creating repository for organization")
return
}
- CreateUserRepo(ctx, ctx.User, opt)
+ CreateUserRepo(c, c.User, opt)
}
-func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
- org, err := models.GetOrgByName(ctx.Params(":org"))
+func CreateOrgRepo(c *context.APIContext, opt api.CreateRepoOption) {
+ org, err := models.GetOrgByName(c.Params(":org"))
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "GetOrgByName", err)
+ c.Error(500, "GetOrgByName", err)
}
return
}
- if !org.IsOwnedBy(ctx.User.ID) {
- ctx.Error(403, "", "Given user is not owner of organization.")
+ if !org.IsOwnedBy(c.User.ID) {
+ c.Error(403, "", "Given user is not owner of organization.")
return
}
- CreateUserRepo(ctx, org, opt)
+ CreateUserRepo(c, org, opt)
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate
-func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
- ctxUser := ctx.User
+func Migrate(c *context.APIContext, f form.MigrateRepo) {
+ ctxUser := c.User
// Not equal means context user is an organization,
// or is another user/organization if current user is admin.
if f.Uid != ctxUser.ID {
org, err := models.GetUserByID(f.Uid)
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "GetUserByID", err)
+ c.Error(500, "GetUserByID", err)
}
return
} else if !org.IsOrganization() {
- ctx.Error(403, "", "Given user is not an organization")
+ c.Error(403, "", "Given user is not an organization")
return
}
ctxUser = org
}
- if ctx.HasError() {
- ctx.Error(422, "", ctx.GetErrMsg())
+ if c.HasError() {
+ c.Error(422, "", c.GetErrMsg())
return
}
- if ctxUser.IsOrganization() && !ctx.User.IsAdmin {
+ if ctxUser.IsOrganization() && !c.User.IsAdmin {
// Check ownership of organization.
- if !ctxUser.IsOwnedBy(ctx.User.ID) {
- ctx.Error(403, "", "Given user is not owner of organization")
+ if !ctxUser.IsOwnedBy(c.User.ID) {
+ c.Error(403, "", "Given user is not owner of organization")
return
}
}
- remoteAddr, err := f.ParseRemoteAddr(ctx.User)
+ remoteAddr, err := f.ParseRemoteAddr(c.User)
if err != nil {
if models.IsErrInvalidCloneAddr(err) {
addrErr := err.(models.ErrInvalidCloneAddr)
switch {
case addrErr.IsURLError:
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
case addrErr.IsPermissionDenied:
- ctx.Error(422, "", "You are not allowed to import local repositories")
+ c.Error(422, "", "You are not allowed to import local repositories")
case addrErr.IsInvalidPath:
- ctx.Error(422, "", "Invalid local path, it does not exist or not a directory")
+ c.Error(422, "", "Invalid local path, it does not exist or not a directory")
default:
- ctx.Error(500, "ParseRemoteAddr", "Unknown error type (ErrInvalidCloneAddr): "+err.Error())
+ c.Error(500, "ParseRemoteAddr", "Unknown error type (ErrInvalidCloneAddr): "+err.Error())
}
} else {
- ctx.Error(500, "ParseRemoteAddr", err)
+ c.Error(500, "ParseRemoteAddr", err)
}
return
}
- repo, err := models.MigrateRepository(ctx.User, ctxUser, models.MigrateRepoOptions{
+ repo, err := models.MigrateRepository(c.User, ctxUser, models.MigrateRepoOptions{
Name: f.RepoName,
Description: f.Description,
IsPrivate: f.Private || setting.Repository.ForcePrivate,
@@ -275,34 +275,34 @@ func Migrate(ctx *context.APIContext, f form.MigrateRepo) {
}
if errors.IsReachLimitOfRepo(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "MigrateRepository", models.HandleMirrorCredentials(err.Error(), true))
+ c.Error(500, "MigrateRepository", models.HandleMirrorCredentials(err.Error(), true))
}
return
}
log.Trace("Repository migrated: %s/%s", ctxUser.Name, f.RepoName)
- ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
+ c.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
}
-func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repository) {
- owner, err := models.GetUserByName(ctx.Params(":username"))
+func parseOwnerAndRepo(c *context.APIContext) (*models.User, *models.Repository) {
+ owner, err := models.GetUserByName(c.Params(":username"))
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Error(422, "", err)
+ c.Error(422, "", err)
} else {
- ctx.Error(500, "GetUserByName", err)
+ c.Error(500, "GetUserByName", err)
}
return nil, nil
}
- repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame"))
+ repo, err := models.GetRepositoryByName(owner.ID, c.Params(":reponame"))
if err != nil {
if errors.IsRepoNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetRepositoryByName", err)
+ c.Error(500, "GetRepositoryByName", err)
}
return nil, nil
}
@@ -311,72 +311,72 @@ func parseOwnerAndRepo(ctx *context.APIContext) (*models.User, *models.Repositor
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get
-func Get(ctx *context.APIContext) {
- _, repo := parseOwnerAndRepo(ctx)
- if ctx.Written() {
+func Get(c *context.APIContext) {
+ _, repo := parseOwnerAndRepo(c)
+ if c.Written() {
return
}
- ctx.JSON(200, repo.APIFormat(&api.Permission{
- Admin: ctx.Repo.IsAdmin(),
- Push: ctx.Repo.IsWriter(),
+ c.JSON(200, repo.APIFormat(&api.Permission{
+ Admin: c.Repo.IsAdmin(),
+ Push: c.Repo.IsWriter(),
Pull: true,
}))
}
// https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
-func Delete(ctx *context.APIContext) {
- owner, repo := parseOwnerAndRepo(ctx)
- if ctx.Written() {
+func Delete(c *context.APIContext) {
+ owner, repo := parseOwnerAndRepo(c)
+ if c.Written() {
return
}
- if owner.IsOrganization() && !owner.IsOwnedBy(ctx.User.ID) {
- ctx.Error(403, "", "Given user is not owner of organization.")
+ if owner.IsOrganization() && !owner.IsOwnedBy(c.User.ID) {
+ c.Error(403, "", "Given user is not owner of organization.")
return
}
if err := models.DeleteRepository(owner.ID, repo.ID); err != nil {
- ctx.Error(500, "DeleteRepository", err)
+ c.Error(500, "DeleteRepository", err)
return
}
log.Trace("Repository deleted: %s/%s", owner.Name, repo.Name)
- ctx.Status(204)
+ c.Status(204)
}
-func ListForks(ctx *context.APIContext) {
- forks, err := ctx.Repo.Repository.GetForks()
+func ListForks(c *context.APIContext) {
+ forks, err := c.Repo.Repository.GetForks()
if err != nil {
- ctx.Error(500, "GetForks", err)
+ c.Error(500, "GetForks", err)
return
}
apiForks := make([]*api.Repository, len(forks))
for i := range forks {
if err := forks[i].GetOwner(); err != nil {
- ctx.Error(500, "GetOwner", err)
+ c.Error(500, "GetOwner", err)
return
}
apiForks[i] = forks[i].APIFormat(&api.Permission{
- Admin: ctx.User.IsAdminOfRepo(forks[i]),
- Push: ctx.User.IsWriterOfRepo(forks[i]),
+ Admin: c.User.IsAdminOfRepo(forks[i]),
+ Push: c.User.IsWriterOfRepo(forks[i]),
Pull: true,
})
}
- ctx.JSON(200, &apiForks)
+ c.JSON(200, &apiForks)
}
-func MirrorSync(ctx *context.APIContext) {
- _, repo := parseOwnerAndRepo(ctx)
- if ctx.Written() {
+func MirrorSync(c *context.APIContext) {
+ _, repo := parseOwnerAndRepo(c)
+ if c.Written() {
return
} else if !repo.IsMirror {
- ctx.Status(404)
+ c.Status(404)
return
}
go models.MirrorQueue.Add(repo.ID)
- ctx.Status(202)
+ c.Status(202)
}
diff --git a/routers/api/v1/user/app.go b/routers/api/v1/user/app.go
index ebba7f09..bda1e23f 100644
--- a/routers/api/v1/user/app.go
+++ b/routers/api/v1/user/app.go
@@ -12,10 +12,10 @@ import (
)
// https://github.com/gogits/go-gogs-client/wiki/Users#list-access-tokens-for-a-user
-func ListAccessTokens(ctx *context.APIContext) {
- tokens, err := models.ListAccessTokens(ctx.User.ID)
+func ListAccessTokens(c *context.APIContext) {
+ tokens, err := models.ListAccessTokens(c.User.ID)
if err != nil {
- ctx.Error(500, "ListAccessTokens", err)
+ c.Error(500, "ListAccessTokens", err)
return
}
@@ -23,18 +23,18 @@ func ListAccessTokens(ctx *context.APIContext) {
for i := range tokens {
apiTokens[i] = &api.AccessToken{tokens[i].Name, tokens[i].Sha1}
}
- ctx.JSON(200, &apiTokens)
+ c.JSON(200, &apiTokens)
}
// https://github.com/gogits/go-gogs-client/wiki/Users#create-a-access-token
-func CreateAccessToken(ctx *context.APIContext, form api.CreateAccessTokenOption) {
+func CreateAccessToken(c *context.APIContext, form api.CreateAccessTokenOption) {
t := &models.AccessToken{
- UID: ctx.User.ID,
+ UID: c.User.ID,
Name: form.Name,
}
if err := models.NewAccessToken(t); err != nil {
- ctx.Error(500, "NewAccessToken", err)
+ c.Error(500, "NewAccessToken", err)
return
}
- ctx.JSON(201, &api.AccessToken{t.Name, t.Sha1})
+ c.JSON(201, &api.AccessToken{t.Name, t.Sha1})
}
diff --git a/routers/api/v1/user/email.go b/routers/api/v1/user/email.go
index c8b4ce1b..7c527a1a 100644
--- a/routers/api/v1/user/email.go
+++ b/routers/api/v1/user/email.go
@@ -14,30 +14,30 @@ import (
)
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#list-email-addresses-for-a-user
-func ListEmails(ctx *context.APIContext) {
- emails, err := models.GetEmailAddresses(ctx.User.ID)
+func ListEmails(c *context.APIContext) {
+ emails, err := models.GetEmailAddresses(c.User.ID)
if err != nil {
- ctx.Error(500, "GetEmailAddresses", err)
+ c.Error(500, "GetEmailAddresses", err)
return
}
apiEmails := make([]*api.Email, len(emails))
for i := range emails {
apiEmails[i] = convert.ToEmail(emails[i])
}
- ctx.JSON(200, &apiEmails)
+ c.JSON(200, &apiEmails)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#add-email-addresses
-func AddEmail(ctx *context.APIContext, form api.CreateEmailOption) {
+func AddEmail(c *context.APIContext, form api.CreateEmailOption) {
if len(form.Emails) == 0 {
- ctx.Status(422)
+ c.Status(422)
return
}
emails := make([]*models.EmailAddress, len(form.Emails))
for i := range form.Emails {
emails[i] = &models.EmailAddress{
- UID: ctx.User.ID,
+ UID: c.User.ID,
Email: form.Emails[i],
IsActivated: !setting.Service.RegisterEmailConfirm,
}
@@ -45,9 +45,9 @@ func AddEmail(ctx *context.APIContext, form api.CreateEmailOption) {
if err := models.AddEmailAddresses(emails); err != nil {
if models.IsErrEmailAlreadyUsed(err) {
- ctx.Error(422, "", "Email address has been used: "+err.(models.ErrEmailAlreadyUsed).Email)
+ c.Error(422, "", "Email address has been used: "+err.(models.ErrEmailAlreadyUsed).Email)
} else {
- ctx.Error(500, "AddEmailAddresses", err)
+ c.Error(500, "AddEmailAddresses", err)
}
return
}
@@ -56,27 +56,27 @@ func AddEmail(ctx *context.APIContext, form api.CreateEmailOption) {
for i := range emails {
apiEmails[i] = convert.ToEmail(emails[i])
}
- ctx.JSON(201, &apiEmails)
+ c.JSON(201, &apiEmails)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Emails#delete-email-addresses
-func DeleteEmail(ctx *context.APIContext, form api.CreateEmailOption) {
+func DeleteEmail(c *context.APIContext, form api.CreateEmailOption) {
if len(form.Emails) == 0 {
- ctx.Status(204)
+ c.Status(204)
return
}
emails := make([]*models.EmailAddress, len(form.Emails))
for i := range form.Emails {
emails[i] = &models.EmailAddress{
- UID: ctx.User.ID,
+ UID: c.User.ID,
Email: form.Emails[i],
}
}
if err := models.DeleteEmailAddresses(emails); err != nil {
- ctx.Error(500, "DeleteEmailAddresses", err)
+ c.Error(500, "DeleteEmailAddresses", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/user/follower.go b/routers/api/v1/user/follower.go
index 814f10f4..6bbd4c7e 100644
--- a/routers/api/v1/user/follower.go
+++ b/routers/api/v1/user/follower.go
@@ -11,110 +11,110 @@ import (
"github.com/gogits/gogs/pkg/context"
)
-func responseApiUsers(ctx *context.APIContext, users []*models.User) {
+func responseApiUsers(c *context.APIContext, users []*models.User) {
apiUsers := make([]*api.User, len(users))
for i := range users {
apiUsers[i] = users[i].APIFormat()
}
- ctx.JSON(200, &apiUsers)
+ c.JSON(200, &apiUsers)
}
-func listUserFollowers(ctx *context.APIContext, u *models.User) {
- users, err := u.GetFollowers(ctx.QueryInt("page"))
+func listUserFollowers(c *context.APIContext, u *models.User) {
+ users, err := u.GetFollowers(c.QueryInt("page"))
if err != nil {
- ctx.Error(500, "GetUserFollowers", err)
+ c.Error(500, "GetUserFollowers", err)
return
}
- responseApiUsers(ctx, users)
+ responseApiUsers(c, users)
}
-func ListMyFollowers(ctx *context.APIContext) {
- listUserFollowers(ctx, ctx.User)
+func ListMyFollowers(c *context.APIContext) {
+ listUserFollowers(c, c.User)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-followers-of-a-user
-func ListFollowers(ctx *context.APIContext) {
- u := GetUserByParams(ctx)
- if ctx.Written() {
+func ListFollowers(c *context.APIContext) {
+ u := GetUserByParams(c)
+ if c.Written() {
return
}
- listUserFollowers(ctx, u)
+ listUserFollowers(c, u)
}
-func listUserFollowing(ctx *context.APIContext, u *models.User) {
- users, err := u.GetFollowing(ctx.QueryInt("page"))
+func listUserFollowing(c *context.APIContext, u *models.User) {
+ users, err := u.GetFollowing(c.QueryInt("page"))
if err != nil {
- ctx.Error(500, "GetFollowing", err)
+ c.Error(500, "GetFollowing", err)
return
}
- responseApiUsers(ctx, users)
+ responseApiUsers(c, users)
}
-func ListMyFollowing(ctx *context.APIContext) {
- listUserFollowing(ctx, ctx.User)
+func ListMyFollowing(c *context.APIContext) {
+ listUserFollowing(c, c.User)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#list-users-followed-by-another-user
-func ListFollowing(ctx *context.APIContext) {
- u := GetUserByParams(ctx)
- if ctx.Written() {
+func ListFollowing(c *context.APIContext) {
+ u := GetUserByParams(c)
+ if c.Written() {
return
}
- listUserFollowing(ctx, u)
+ listUserFollowing(c, u)
}
-func checkUserFollowing(ctx *context.APIContext, u *models.User, followID int64) {
+func checkUserFollowing(c *context.APIContext, u *models.User, followID int64) {
if u.IsFollowing(followID) {
- ctx.Status(204)
+ c.Status(204)
} else {
- ctx.Status(404)
+ c.Status(404)
}
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-you-are-following-a-user
-func CheckMyFollowing(ctx *context.APIContext) {
- target := GetUserByParams(ctx)
- if ctx.Written() {
+func CheckMyFollowing(c *context.APIContext) {
+ target := GetUserByParams(c)
+ if c.Written() {
return
}
- checkUserFollowing(ctx, ctx.User, target.ID)
+ checkUserFollowing(c, c.User, target.ID)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#check-if-one-user-follows-another
-func CheckFollowing(ctx *context.APIContext) {
- u := GetUserByParams(ctx)
- if ctx.Written() {
+func CheckFollowing(c *context.APIContext) {
+ u := GetUserByParams(c)
+ if c.Written() {
return
}
- target := GetUserByParamsName(ctx, ":target")
- if ctx.Written() {
+ target := GetUserByParamsName(c, ":target")
+ if c.Written() {
return
}
- checkUserFollowing(ctx, u, target.ID)
+ checkUserFollowing(c, u, target.ID)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#follow-a-user
-func Follow(ctx *context.APIContext) {
- target := GetUserByParams(ctx)
- if ctx.Written() {
+func Follow(c *context.APIContext) {
+ target := GetUserByParams(c)
+ if c.Written() {
return
}
- if err := models.FollowUser(ctx.User.ID, target.ID); err != nil {
- ctx.Error(500, "FollowUser", err)
+ if err := models.FollowUser(c.User.ID, target.ID); err != nil {
+ c.Error(500, "FollowUser", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Followers#unfollow-a-user
-func Unfollow(ctx *context.APIContext) {
- target := GetUserByParams(ctx)
- if ctx.Written() {
+func Unfollow(c *context.APIContext) {
+ target := GetUserByParams(c)
+ if c.Written() {
return
}
- if err := models.UnfollowUser(ctx.User.ID, target.ID); err != nil {
- ctx.Error(500, "UnfollowUser", err)
+ if err := models.UnfollowUser(c.User.ID, target.ID); err != nil {
+ c.Error(500, "UnfollowUser", err)
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/user/key.go b/routers/api/v1/user/key.go
index b9ede63f..f0c833f5 100644
--- a/routers/api/v1/user/key.go
+++ b/routers/api/v1/user/key.go
@@ -15,13 +15,13 @@ import (
"github.com/gogits/gogs/routers/api/v1/repo"
)
-func GetUserByParamsName(ctx *context.APIContext, name string) *models.User {
- user, err := models.GetUserByName(ctx.Params(name))
+func GetUserByParamsName(c *context.APIContext, name string) *models.User {
+ user, err := models.GetUserByName(c.Params(name))
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetUserByName", err)
+ c.Error(500, "GetUserByName", err)
}
return nil
}
@@ -29,18 +29,18 @@ func GetUserByParamsName(ctx *context.APIContext, name string) *models.User {
}
// GetUserByParams returns user whose name is presented in URL paramenter.
-func GetUserByParams(ctx *context.APIContext) *models.User {
- return GetUserByParamsName(ctx, ":username")
+func GetUserByParams(c *context.APIContext) *models.User {
+ return GetUserByParamsName(c, ":username")
}
func composePublicKeysAPILink() string {
return setting.AppURL + "api/v1/user/keys/"
}
-func listPublicKeys(ctx *context.APIContext, uid int64) {
+func listPublicKeys(c *context.APIContext, uid int64) {
keys, err := models.ListPublicKeys(uid)
if err != nil {
- ctx.Error(500, "ListPublicKeys", err)
+ c.Error(500, "ListPublicKeys", err)
return
}
@@ -50,71 +50,71 @@ func listPublicKeys(ctx *context.APIContext, uid int64) {
apiKeys[i] = convert.ToPublicKey(apiLink, keys[i])
}
- ctx.JSON(200, &apiKeys)
+ c.JSON(200, &apiKeys)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-your-public-keys
-func ListMyPublicKeys(ctx *context.APIContext) {
- listPublicKeys(ctx, ctx.User.ID)
+func ListMyPublicKeys(c *context.APIContext) {
+ listPublicKeys(c, c.User.ID)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#list-public-keys-for-a-user
-func ListPublicKeys(ctx *context.APIContext) {
- user := GetUserByParams(ctx)
- if ctx.Written() {
+func ListPublicKeys(c *context.APIContext) {
+ user := GetUserByParams(c)
+ if c.Written() {
return
}
- listPublicKeys(ctx, user.ID)
+ listPublicKeys(c, user.ID)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#get-a-single-public-key
-func GetPublicKey(ctx *context.APIContext) {
- key, err := models.GetPublicKeyByID(ctx.ParamsInt64(":id"))
+func GetPublicKey(c *context.APIContext) {
+ key, err := models.GetPublicKeyByID(c.ParamsInt64(":id"))
if err != nil {
if models.IsErrKeyNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetPublicKeyByID", err)
+ c.Error(500, "GetPublicKeyByID", err)
}
return
}
apiLink := composePublicKeysAPILink()
- ctx.JSON(200, convert.ToPublicKey(apiLink, key))
+ c.JSON(200, convert.ToPublicKey(apiLink, key))
}
// CreateUserPublicKey creates new public key to given user by ID.
-func CreateUserPublicKey(ctx *context.APIContext, form api.CreateKeyOption, uid int64) {
+func CreateUserPublicKey(c *context.APIContext, form api.CreateKeyOption, uid int64) {
content, err := models.CheckPublicKeyString(form.Key)
if err != nil {
- repo.HandleCheckKeyStringError(ctx, err)
+ repo.HandleCheckKeyStringError(c, err)
return
}
key, err := models.AddPublicKey(uid, form.Title, content)
if err != nil {
- repo.HandleAddKeyError(ctx, err)
+ repo.HandleAddKeyError(c, err)
return
}
apiLink := composePublicKeysAPILink()
- ctx.JSON(201, convert.ToPublicKey(apiLink, key))
+ c.JSON(201, convert.ToPublicKey(apiLink, key))
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#create-a-public-key
-func CreatePublicKey(ctx *context.APIContext, form api.CreateKeyOption) {
- CreateUserPublicKey(ctx, form, ctx.User.ID)
+func CreatePublicKey(c *context.APIContext, form api.CreateKeyOption) {
+ CreateUserPublicKey(c, form, c.User.ID)
}
// https://github.com/gogits/go-gogs-client/wiki/Users-Public-Keys#delete-a-public-key
-func DeletePublicKey(ctx *context.APIContext) {
- if err := models.DeletePublicKey(ctx.User, ctx.ParamsInt64(":id")); err != nil {
+func DeletePublicKey(c *context.APIContext) {
+ if err := models.DeletePublicKey(c.User, c.ParamsInt64(":id")); err != nil {
if models.IsErrKeyAccessDenied(err) {
- ctx.Error(403, "", "You do not have access to this key")
+ c.Error(403, "", "You do not have access to this key")
} else {
- ctx.Error(500, "DeletePublicKey", err)
+ c.Error(500, "DeletePublicKey", err)
}
return
}
- ctx.Status(204)
+ c.Status(204)
}
diff --git a/routers/api/v1/user/user.go b/routers/api/v1/user/user.go
index 11c3b8bb..dbf727de 100644
--- a/routers/api/v1/user/user.go
+++ b/routers/api/v1/user/user.go
@@ -14,11 +14,11 @@ import (
"github.com/gogits/gogs/pkg/context"
)
-func Search(ctx *context.APIContext) {
+func Search(c *context.APIContext) {
opts := &models.SearchUserOptions{
- Keyword: ctx.Query("q"),
+ Keyword: c.Query("q"),
Type: models.USER_TYPE_INDIVIDUAL,
- PageSize: com.StrTo(ctx.Query("limit")).MustInt(),
+ PageSize: com.StrTo(c.Query("limit")).MustInt(),
}
if opts.PageSize == 0 {
opts.PageSize = 10
@@ -26,7 +26,7 @@ func Search(ctx *context.APIContext) {
users, _, err := models.SearchUserByName(opts)
if err != nil {
- ctx.JSON(500, map[string]interface{}{
+ c.JSON(500, map[string]interface{}{
"ok": false,
"error": err.Error(),
})
@@ -41,35 +41,35 @@ func Search(ctx *context.APIContext) {
AvatarUrl: users[i].AvatarLink(),
FullName: users[i].FullName,
}
- if ctx.IsLogged {
+ if c.IsLogged {
results[i].Email = users[i].Email
}
}
- ctx.JSON(200, map[string]interface{}{
+ c.JSON(200, map[string]interface{}{
"ok": true,
"data": results,
})
}
-func GetInfo(ctx *context.APIContext) {
- u, err := models.GetUserByName(ctx.Params(":username"))
+func GetInfo(c *context.APIContext) {
+ u, err := models.GetUserByName(c.Params(":username"))
if err != nil {
if errors.IsUserNotExist(err) {
- ctx.Status(404)
+ c.Status(404)
} else {
- ctx.Error(500, "GetUserByName", err)
+ c.Error(500, "GetUserByName", err)
}
return
}
// Hide user e-mail when API caller isn't signed in.
- if !ctx.IsLogged {
+ if !c.IsLogged {
u.Email = ""
}
- ctx.JSON(200, u.APIFormat())
+ c.JSON(200, u.APIFormat())
}
-func GetAuthenticatedUser(ctx *context.APIContext) {
- ctx.JSON(200, ctx.User.APIFormat())
+func GetAuthenticatedUser(c *context.APIContext) {
+ c.JSON(200, c.User.APIFormat())
}