Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

golint fixed for routers #208

Merged
merged 1 commit into from
Nov 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion routers/api/v1/admin/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
"code.gitea.io/gitea/routers/api/v1/user"
)

// https://github.com/gogits/go-gogs-client/wiki/Administration-Organizations#create-a-new-organization
// CreateOrg api for create organization
// see 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() {
Expand Down
3 changes: 3 additions & 0 deletions routers/api/v1/admin/org_repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"code.gitea.io/gitea/modules/context"
)

// GetRepositoryByParams api for getting repository by orgnizition ID and repo name
func GetRepositoryByParams(ctx *context.APIContext) *models.Repository {
repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
if err != nil {
Expand All @@ -22,6 +23,7 @@ func GetRepositoryByParams(ctx *context.APIContext) *models.Repository {
return repo
}

// AddTeamRepository api for adding a repository to a team
func AddTeamRepository(ctx *context.APIContext) {
repo := GetRepositoryByParams(ctx)
if ctx.Written() {
Expand All @@ -35,6 +37,7 @@ func AddTeamRepository(ctx *context.APIContext) {
ctx.Status(204)
}

// RemoveTeamRepository api for removing a repository from a team
func RemoveTeamRepository(ctx *context.APIContext) {
repo := GetRepositoryByParams(ctx)
if ctx.Written() {
Expand Down
3 changes: 3 additions & 0 deletions routers/api/v1/admin/org_team.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"code.gitea.io/gitea/routers/api/v1/user"
)

// CreateTeam api for create a team
func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
team := &models.Team{
OrgID: ctx.Org.Organization.ID,
Expand All @@ -32,6 +33,7 @@ func CreateTeam(ctx *context.APIContext, form api.CreateTeamOption) {
ctx.JSON(201, convert.ToTeam(team))
}

// AddTeamMember api for add a member to a team
func AddTeamMember(ctx *context.APIContext) {
u := user.GetUserByParams(ctx)
if ctx.Written() {
Expand All @@ -45,6 +47,7 @@ func AddTeamMember(ctx *context.APIContext) {
ctx.Status(204)
}

// RemoveTeamMember api for remove one member from a team
func RemoveTeamMember(ctx *context.APIContext) {
u := user.GetUserByParams(ctx)
if ctx.Written() {
Expand Down
3 changes: 2 additions & 1 deletion routers/api/v1/admin/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (
"code.gitea.io/gitea/routers/api/v1/user"
)

// https://github.com/gogits/go-gogs-client/wiki/Administration-Repositories#create-a-new-repository
// CreateRepo api for creating a repository
// see 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() {
Expand Down
10 changes: 7 additions & 3 deletions routers/api/v1/admin/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ func parseLoginSource(ctx *context.APIContext, u *models.User, sourceID int64, l
u.LoginName = loginName
}

// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-new-user
// CreateUser api for creating a user
// see https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-new-user
func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
u := &models.User{
Name: form.Username,
Expand Down Expand Up @@ -71,7 +72,8 @@ func CreateUser(ctx *context.APIContext, form api.CreateUserOption) {
ctx.JSON(201, u.APIFormat())
}

// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#edit-an-existing-user
// EditUser api for modifying a user's information
// see 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() {
Expand Down Expand Up @@ -123,6 +125,7 @@ func EditUser(ctx *context.APIContext, form api.EditUserOption) {
ctx.JSON(200, u.APIFormat())
}

// DeleteUser api for deleting a user
// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#delete-a-user
func DeleteUser(ctx *context.APIContext) {
u := user.GetUserByParams(ctx)
Expand All @@ -144,7 +147,8 @@ func DeleteUser(ctx *context.APIContext) {
ctx.Status(204)
}

// https://github.com/gogits/go-gogs-client/wiki/Administration-Users#create-a-public-key-for-user
// CreatePublicKey api for creating a public key to a user
// see 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() {
Expand Down
10 changes: 9 additions & 1 deletion routers/api/v1/convert/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ import (

"github.com/Unknwon/com"

"code.gitea.io/git"
api "code.gitea.io/sdk/gitea"

"code.gitea.io/git"
"code.gitea.io/gitea/models"
)

// ToEmail convert models.EmailAddress to api.Email
func ToEmail(email *models.EmailAddress) *api.Email {
return &api.Email{
Email: email.Email,
Expand All @@ -23,13 +24,15 @@ func ToEmail(email *models.EmailAddress) *api.Email {
}
}

// ToBranch convert a commit and branch to an api.Branch
func ToBranch(b *models.Branch, c *git.Commit) *api.Branch {
return &api.Branch{
Name: b.Name,
Commit: ToCommit(c),
}
}

// ToCommit convert a commit to api.PayloadCommit
func ToCommit(c *git.Commit) *api.PayloadCommit {
authorUsername := ""
author, err := models.GetUserByEmail(c.Author.Email)
Expand Down Expand Up @@ -59,6 +62,7 @@ func ToCommit(c *git.Commit) *api.PayloadCommit {
}
}

// ToPublicKey convert models.PublicKey to api.PublicKey
func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
return &api.PublicKey{
ID: key.ID,
Expand All @@ -69,6 +73,7 @@ func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
}
}

// ToHook convert models.Webhook to api.Hook
func ToHook(repoLink string, w *models.Webhook) *api.Hook {
config := map[string]string{
"url": w.URL,
Expand All @@ -94,6 +99,7 @@ func ToHook(repoLink string, w *models.Webhook) *api.Hook {
}
}

// ToDeployKey convert models.DeployKey to api.DeployKey
func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
return &api.DeployKey{
ID: key.ID,
Expand All @@ -105,6 +111,7 @@ func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
}
}

// ToOrganization convert models.User to api.Organization
func ToOrganization(org *models.User) *api.Organization {
return &api.Organization{
ID: org.ID,
Expand All @@ -117,6 +124,7 @@ func ToOrganization(org *models.User) *api.Organization {
}
}

// ToTeam convert models.Team to api.Team
func ToTeam(team *models.Team) *api.Team {
return &api.Team{
ID: team.ID,
Expand Down
6 changes: 4 additions & 2 deletions routers/api/v1/misc/markdown.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ import (
"code.gitea.io/gitea/modules/markdown"
)

// https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-an-arbitrary-markdown-document
// Markdown render markdown document to HTML
// see 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())
Expand All @@ -31,7 +32,8 @@ func Markdown(ctx *context.APIContext, form api.MarkdownOption) {
}
}

// https://github.com/gogits/go-gogs-client/wiki/Miscellaneous#render-a-markdown-document-in-raw-mode
// MarkdownRaw render raw markdown HTML
// see 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()
if err != nil {
Expand Down
12 changes: 8 additions & 4 deletions routers/api/v1/org/org.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,14 @@ func listUserOrgs(ctx *context.APIContext, u *models.User, all bool) {
ctx.JSON(200, &apiOrgs)
}

// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-your-organizations
// ListMyOrgs list all my orgs
// see https://github.com/gogits/go-gogs-client/wiki/Organizations#list-your-organizations
func ListMyOrgs(ctx *context.APIContext) {
listUserOrgs(ctx, ctx.User, true)
}

// https://github.com/gogits/go-gogs-client/wiki/Organizations#list-user-organizations
// ListUserOrgs list user's orgs
// see https://github.com/gogits/go-gogs-client/wiki/Organizations#list-user-organizations
func ListUserOrgs(ctx *context.APIContext) {
u := user.GetUserByParams(ctx)
if ctx.Written() {
Expand All @@ -40,12 +42,14 @@ func ListUserOrgs(ctx *context.APIContext) {
listUserOrgs(ctx, u, false)
}

// https://github.com/gogits/go-gogs-client/wiki/Organizations#get-an-organization
// Get get an organization
// see 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))
}

// https://github.com/gogits/go-gogs-client/wiki/Organizations#edit-an-organization
// Edit change an organization's information
// see 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) {
Expand Down
1 change: 1 addition & 0 deletions routers/api/v1/org/team.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"code.gitea.io/gitea/routers/api/v1/convert"
)

// ListTeams list all the teams of an organization
func ListTeams(ctx *context.APIContext) {
org := ctx.Org.Organization
if err := org.GetTeams(); err != nil {
Expand Down
6 changes: 4 additions & 2 deletions routers/api/v1/repo/branch.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions routers/api/v1/repo/collaborators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 5 additions & 2 deletions routers/api/v1/repo/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 {
Expand Down
10 changes: 7 additions & 3 deletions routers/api/v1/repo/hook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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")
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions routers/api/v1/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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 {
Expand All @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 4 additions & 0 deletions routers/api/v1/repo/issue_comment.go
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down
Loading