mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
golint fixed for routers (#208)
This commit is contained in:
@@ -11,7 +11,8 @@ import (
|
||||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch
|
||||
// GetBranch get a branch of a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#get-branch
|
||||
func GetBranch(ctx *context.APIContext) {
|
||||
branch, err := ctx.Repo.Repository.GetBranch(ctx.Params(":branchname"))
|
||||
if err != nil {
|
||||
@@ -28,7 +29,8 @@ func GetBranch(ctx *context.APIContext) {
|
||||
ctx.JSON(200, convert.ToBranch(branch, c))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches
|
||||
// ListBranches list all the branches of a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#list-branches
|
||||
func ListBranches(ctx *context.APIContext) {
|
||||
branches, err := ctx.Repo.Repository.GetBranches()
|
||||
if err != nil {
|
||||
|
@@ -11,6 +11,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// AddCollaborator add a collaborator of a repository
|
||||
func AddCollaborator(ctx *context.APIContext, form api.AddCollaboratorOption) {
|
||||
collaborator, err := models.GetUserByName(ctx.Params(":collaborator"))
|
||||
if err != nil {
|
||||
|
@@ -12,7 +12,8 @@ import (
|
||||
"code.gitea.io/gitea/routers/repo"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-raw-content
|
||||
// GetRawFile get a file by path on a repository
|
||||
// see 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)
|
||||
@@ -33,7 +34,8 @@ func GetRawFile(ctx *context.APIContext) {
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Contents#download-archive
|
||||
// GetArchive get archive of a repository
|
||||
// see 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"))
|
||||
gitRepo, err := git.OpenRepository(repoPath)
|
||||
@@ -46,6 +48,7 @@ func GetArchive(ctx *context.APIContext) {
|
||||
repo.Download(ctx.Context)
|
||||
}
|
||||
|
||||
// GetEditorconfig get editor config of a repository
|
||||
func GetEditorconfig(ctx *context.APIContext) {
|
||||
ec, err := ctx.Repo.GetEditorconfig()
|
||||
if err != nil {
|
||||
|
@@ -16,7 +16,8 @@ import (
|
||||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks
|
||||
// ListHooks list all hooks of a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#list-hooks
|
||||
func ListHooks(ctx *context.APIContext) {
|
||||
hooks, err := models.GetWebhooksByRepoID(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
@@ -31,7 +32,8 @@ func ListHooks(ctx *context.APIContext) {
|
||||
ctx.JSON(200, &apiHooks)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook
|
||||
// CreateHook create a hook for a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#create-a-hook
|
||||
func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
|
||||
if !models.IsValidHookTaskType(form.Type) {
|
||||
ctx.Error(422, "", "Invalid hook type")
|
||||
@@ -97,7 +99,8 @@ func CreateHook(ctx *context.APIContext, form api.CreateHookOption) {
|
||||
ctx.JSON(201, convert.ToHook(ctx.Repo.RepoLink, w))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook
|
||||
// EditHook modify a hook of a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#edit-a-hook
|
||||
func EditHook(ctx *context.APIContext, form api.EditHookOption) {
|
||||
w, err := models.GetWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
@@ -165,6 +168,7 @@ func EditHook(ctx *context.APIContext, form api.EditHookOption) {
|
||||
ctx.JSON(200, convert.ToHook(ctx.Repo.RepoLink, w))
|
||||
}
|
||||
|
||||
// DeleteHook delete a hook of a repository
|
||||
func DeleteHook(ctx *context.APIContext) {
|
||||
if err := models.DeleteWebhookByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
|
||||
ctx.Error(500, "DeleteWebhookByRepoID", err)
|
||||
|
@@ -15,6 +15,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/setting"
|
||||
)
|
||||
|
||||
// ListIssues list the issues of a repository
|
||||
func ListIssues(ctx *context.APIContext) {
|
||||
issues, err := models.Issues(&models.IssuesOptions{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
@@ -39,6 +40,7 @@ func ListIssues(ctx *context.APIContext) {
|
||||
ctx.JSON(200, &apiIssues)
|
||||
}
|
||||
|
||||
// GetIssue get an issue of a repository
|
||||
func GetIssue(ctx *context.APIContext) {
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
@@ -52,6 +54,7 @@ func GetIssue(ctx *context.APIContext) {
|
||||
ctx.JSON(200, issue.APIFormat())
|
||||
}
|
||||
|
||||
// CreateIssue create an issue of a repository
|
||||
func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
||||
issue := &models.Issue{
|
||||
RepoID: ctx.Repo.Repository.ID,
|
||||
@@ -101,6 +104,7 @@ func CreateIssue(ctx *context.APIContext, form api.CreateIssueOption) {
|
||||
ctx.JSON(201, issue.APIFormat())
|
||||
}
|
||||
|
||||
// EditIssue modify an issue of a repository
|
||||
func EditIssue(ctx *context.APIContext, form api.EditIssueOption) {
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
|
@@ -1,6 +1,7 @@
|
||||
// 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 repo
|
||||
|
||||
import (
|
||||
@@ -12,6 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// ListIssueComments list all the comments of an issue
|
||||
func ListIssueComments(ctx *context.APIContext) {
|
||||
var since time.Time
|
||||
if len(ctx.Query("since")) > 0 {
|
||||
@@ -38,6 +40,7 @@ func ListIssueComments(ctx *context.APIContext) {
|
||||
ctx.JSON(200, &apiComments)
|
||||
}
|
||||
|
||||
// CreateIssueComment create a comment for an issue
|
||||
func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOption) {
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
@@ -54,6 +57,7 @@ func CreateIssueComment(ctx *context.APIContext, form api.CreateIssueCommentOpti
|
||||
ctx.JSON(201, comment.APIFormat())
|
||||
}
|
||||
|
||||
// EditIssueComment modify a comment of an issue
|
||||
func EditIssueComment(ctx *context.APIContext, form api.EditIssueCommentOption) {
|
||||
comment, err := models.GetCommentByID(ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
|
@@ -11,6 +11,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// ListIssueLabels list all the labels of an issue
|
||||
func ListIssueLabels(ctx *context.APIContext) {
|
||||
issue, err := models.GetIssueByIndex(ctx.Repo.Repository.ID, ctx.ParamsInt64(":index"))
|
||||
if err != nil {
|
||||
@@ -29,6 +30,7 @@ func ListIssueLabels(ctx *context.APIContext) {
|
||||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
||||
// AddIssueLabels add labels for an issue
|
||||
func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
@@ -69,6 +71,7 @@ func AddIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
||||
// DeleteIssueLabel delete a label for an issue
|
||||
func DeleteIssueLabel(ctx *context.APIContext) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
@@ -103,6 +106,7 @@ func DeleteIssueLabel(ctx *context.APIContext) {
|
||||
ctx.Status(204)
|
||||
}
|
||||
|
||||
// ReplaceIssueLabels replace labels for an issue
|
||||
func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
@@ -143,6 +147,7 @@ func ReplaceIssueLabels(ctx *context.APIContext, form api.IssueLabelsOption) {
|
||||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
||||
// ClearIssueLabels delete all the labels for an issue
|
||||
func ClearIssueLabels(ctx *context.APIContext) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
|
@@ -19,7 +19,8 @@ func composeDeployKeysAPILink(repoPath string) string {
|
||||
return setting.AppUrl + "api/v1/repos/" + repoPath + "/keys/"
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#list-deploy-keys
|
||||
// ListDeployKeys list all the deploy keys of a repository
|
||||
// see 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)
|
||||
if err != nil {
|
||||
@@ -40,7 +41,8 @@ func ListDeployKeys(ctx *context.APIContext) {
|
||||
ctx.JSON(200, &apiKeys)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#get-a-deploy-key
|
||||
// GetDeployKey get a deploy key by id
|
||||
// see 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"))
|
||||
if err != nil {
|
||||
@@ -61,6 +63,7 @@ func GetDeployKey(ctx *context.APIContext) {
|
||||
ctx.JSON(200, convert.ToDeployKey(apiLink, key))
|
||||
}
|
||||
|
||||
// HandleCheckKeyStringError handle check key error
|
||||
func HandleCheckKeyStringError(ctx *context.APIContext, err error) {
|
||||
if models.IsErrKeyUnableVerify(err) {
|
||||
ctx.Error(422, "", "Unable to verify key content")
|
||||
@@ -69,6 +72,7 @@ func HandleCheckKeyStringError(ctx *context.APIContext, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// HandleAddKeyError handle add key error
|
||||
func HandleAddKeyError(ctx *context.APIContext, err error) {
|
||||
switch {
|
||||
case models.IsErrKeyAlreadyExist(err):
|
||||
@@ -80,7 +84,8 @@ func HandleAddKeyError(ctx *context.APIContext, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#add-a-new-deploy-key
|
||||
// CreateDeployKey create deploy key for a repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#add-a-new-deploy-key
|
||||
func CreateDeployKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
||||
content, err := models.CheckPublicKeyString(form.Key)
|
||||
if err != nil {
|
||||
@@ -99,7 +104,8 @@ func CreateDeployKey(ctx *context.APIContext, form api.CreateKeyOption) {
|
||||
ctx.JSON(201, convert.ToDeployKey(apiLink, key))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories-Deploy-Keys#remove-a-deploy-key
|
||||
// DeleteDeploykey delete deploy key for a repository
|
||||
// see 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 {
|
||||
if models.IsErrKeyAccessDenied(err) {
|
||||
|
@@ -11,6 +11,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// ListLabels list all the labels of a repository
|
||||
func ListLabels(ctx *context.APIContext) {
|
||||
labels, err := models.GetLabelsByRepoID(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
@@ -25,6 +26,7 @@ func ListLabels(ctx *context.APIContext) {
|
||||
ctx.JSON(200, &apiLabels)
|
||||
}
|
||||
|
||||
// GetLabel get label by repository and label id
|
||||
func GetLabel(ctx *context.APIContext) {
|
||||
label, err := models.GetLabelInRepoByID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
@@ -39,6 +41,7 @@ func GetLabel(ctx *context.APIContext) {
|
||||
ctx.JSON(200, label.APIFormat())
|
||||
}
|
||||
|
||||
// CreateLabel create a label for a repository
|
||||
func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
@@ -57,6 +60,7 @@ func CreateLabel(ctx *context.APIContext, form api.CreateLabelOption) {
|
||||
ctx.JSON(201, label.APIFormat())
|
||||
}
|
||||
|
||||
// EditLabel modify a label for a repository
|
||||
func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
@@ -86,6 +90,7 @@ func EditLabel(ctx *context.APIContext, form api.EditLabelOption) {
|
||||
ctx.JSON(200, label.APIFormat())
|
||||
}
|
||||
|
||||
// DeleteLabel delete a label for a repository
|
||||
func DeleteLabel(ctx *context.APIContext) {
|
||||
if !ctx.Repo.IsWriter() {
|
||||
ctx.Status(403)
|
||||
|
@@ -13,6 +13,7 @@ import (
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// ListMilestones list all the milestones for a repository
|
||||
func ListMilestones(ctx *context.APIContext) {
|
||||
milestones, err := models.GetMilestonesByRepoID(ctx.Repo.Repository.ID)
|
||||
if err != nil {
|
||||
@@ -27,6 +28,7 @@ func ListMilestones(ctx *context.APIContext) {
|
||||
ctx.JSON(200, &apiMilestones)
|
||||
}
|
||||
|
||||
// GetMilestone get a milestone for a repository
|
||||
func GetMilestone(ctx *context.APIContext) {
|
||||
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
@@ -40,6 +42,7 @@ func GetMilestone(ctx *context.APIContext) {
|
||||
ctx.JSON(200, milestone.APIFormat())
|
||||
}
|
||||
|
||||
// CreateMilestone create a milestone for a repository
|
||||
func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
|
||||
if form.Deadline == nil {
|
||||
defaultDeadline, _ := time.ParseInLocation("2006-01-02", "9999-12-31", time.Local)
|
||||
@@ -60,6 +63,7 @@ func CreateMilestone(ctx *context.APIContext, form api.CreateMilestoneOption) {
|
||||
ctx.JSON(201, milestone.APIFormat())
|
||||
}
|
||||
|
||||
// EditMilestone modify a milestone for a repository
|
||||
func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
|
||||
milestone, err := models.GetMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id"))
|
||||
if err != nil {
|
||||
@@ -88,6 +92,7 @@ func EditMilestone(ctx *context.APIContext, form api.EditMilestoneOption) {
|
||||
ctx.JSON(200, milestone.APIFormat())
|
||||
}
|
||||
|
||||
// DeleteMilestone delete a milestone for a repository
|
||||
func DeleteMilestone(ctx *context.APIContext) {
|
||||
if err := models.DeleteMilestoneByRepoID(ctx.Repo.Repository.ID, ctx.ParamsInt64(":id")); err != nil {
|
||||
ctx.Error(500, "DeleteMilestoneByRepoID", err)
|
||||
|
@@ -17,7 +17,8 @@ import (
|
||||
"code.gitea.io/gitea/routers/api/v1/convert"
|
||||
)
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
|
||||
// Search repositories via options
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#search-repositories
|
||||
func Search(ctx *context.APIContext) {
|
||||
opts := &models.SearchRepoOptions{
|
||||
Keyword: path.Base(ctx.Query("q")),
|
||||
@@ -76,7 +77,8 @@ func Search(ctx *context.APIContext) {
|
||||
})
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
|
||||
// ListMyRepos list all my repositories
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#list-your-repositories
|
||||
func ListMyRepos(ctx *context.APIContext) {
|
||||
ownRepos, err := models.GetUserRepositories(ctx.User.ID, true, 1, ctx.User.NumRepos)
|
||||
if err != nil {
|
||||
@@ -109,6 +111,7 @@ func ListMyRepos(ctx *context.APIContext) {
|
||||
ctx.JSON(200, &repos)
|
||||
}
|
||||
|
||||
// CreateUserRepo create a repository for a user
|
||||
func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateRepoOption) {
|
||||
repo, err := models.CreateRepository(owner, models.CreateRepoOptions{
|
||||
Name: opt.Name,
|
||||
@@ -138,7 +141,8 @@ func CreateUserRepo(ctx *context.APIContext, owner *models.User, opt api.CreateR
|
||||
ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#create
|
||||
// Create create one repository of mine
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#create
|
||||
func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
// Shouldn't reach this condition, but just in case.
|
||||
if ctx.User.IsOrganization() {
|
||||
@@ -148,6 +152,7 @@ func Create(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
CreateUserRepo(ctx, ctx.User, opt)
|
||||
}
|
||||
|
||||
// CreateOrgRepo create one repository of the organization
|
||||
func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
org, err := models.GetOrgByName(ctx.Params(":org"))
|
||||
if err != nil {
|
||||
@@ -166,7 +171,8 @@ func CreateOrgRepo(ctx *context.APIContext, opt api.CreateRepoOption) {
|
||||
CreateUserRepo(ctx, org, opt)
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate
|
||||
// Migrate migrate remote git repository to gitea
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#migrate
|
||||
func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
||||
ctxUser := ctx.User
|
||||
// Not equal means context user is an organization,
|
||||
@@ -238,13 +244,15 @@ func Migrate(ctx *context.APIContext, form auth.MigrateRepoForm) {
|
||||
ctx.JSON(201, repo.APIFormat(&api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#get
|
||||
// Get get one repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#get
|
||||
func Get(ctx *context.APIContext) {
|
||||
repo := ctx.Repo.Repository
|
||||
ctx.JSON(200, repo.APIFormat(&api.Permission{true, true, true}))
|
||||
}
|
||||
|
||||
// https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
|
||||
// Delete delete one repository
|
||||
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
|
||||
func Delete(ctx *context.APIContext) {
|
||||
owner := ctx.Repo.Owner
|
||||
repo := ctx.Repo.Repository
|
||||
|
Reference in New Issue
Block a user