]> source.dussan.org Git - gitea.git/commitdiff
Move code.gitea.io/gitea/routers/api/v1/convert to code.gitea.io/gitea/modules/conver...
authorLunny Xiao <xiaolunwen@gmail.com>
Sun, 10 Nov 2019 04:41:51 +0000 (12:41 +0800)
committerGitHub <noreply@github.com>
Sun, 10 Nov 2019 04:41:51 +0000 (12:41 +0800)
* Move code.gitea.io/gitea/routers/api/v1/convert to code.gitea.io/gitea/modules/convert

* fix fmt

28 files changed:
integrations/api_team_test.go
integrations/api_team_user_test.go
modules/convert/convert.go [new file with mode: 0644]
modules/convert/utils.go [new file with mode: 0644]
routers/api/v1/admin/org.go
routers/api/v1/admin/user.go
routers/api/v1/convert/convert.go [deleted file]
routers/api/v1/convert/utils.go [deleted file]
routers/api/v1/org/hook.go
routers/api/v1/org/member.go
routers/api/v1/org/org.go
routers/api/v1/org/team.go
routers/api/v1/repo/branch.go
routers/api/v1/repo/collaborators.go
routers/api/v1/repo/git_hook.go
routers/api/v1/repo/hook.go
routers/api/v1/repo/key.go
routers/api/v1/repo/repo.go
routers/api/v1/repo/star.go
routers/api/v1/repo/subscriber.go
routers/api/v1/repo/tag.go
routers/api/v1/repo/topic.go
routers/api/v1/user/email.go
routers/api/v1/user/follower.go
routers/api/v1/user/gpg_key.go
routers/api/v1/user/key.go
routers/api/v1/user/user.go
routers/api/v1/utils/hook.go

index e25ffdf7b12540269d11afa1cb841520b18fd2ae..3a27cd48659adb9d8b278acde7e176b1bced15b0 100644 (file)
@@ -11,8 +11,8 @@ import (
        "testing"
 
        "code.gitea.io/gitea/models"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 
        "github.com/stretchr/testify/assert"
 )
index 4df4dac016ad64ee070f0f7d8c4ed15f8e1b18a4..f847c7894962b6b21be8ac7fec93f07301e72262 100644 (file)
@@ -10,8 +10,8 @@ import (
        "time"
 
        "code.gitea.io/gitea/models"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
        "github.com/stretchr/testify/assert"
 )
 
diff --git a/modules/convert/convert.go b/modules/convert/convert.go
new file mode 100644 (file)
index 0000000..f52ed63
--- /dev/null
@@ -0,0 +1,312 @@
+// 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 convert
+
+import (
+       "fmt"
+       "time"
+
+       "code.gitea.io/gitea/models"
+       "code.gitea.io/gitea/modules/git"
+       "code.gitea.io/gitea/modules/log"
+       "code.gitea.io/gitea/modules/markup"
+       "code.gitea.io/gitea/modules/structs"
+       api "code.gitea.io/gitea/modules/structs"
+       "code.gitea.io/gitea/modules/util"
+       "code.gitea.io/gitea/modules/webhook"
+
+       "github.com/unknwon/com"
+)
+
+// ToEmail convert models.EmailAddress to api.Email
+func ToEmail(email *models.EmailAddress) *api.Email {
+       return &api.Email{
+               Email:    email.Email,
+               Verified: email.IsActivated,
+               Primary:  email.IsPrimary,
+       }
+}
+
+// ToBranch convert a git.Commit and git.Branch to an api.Branch
+func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit) *api.Branch {
+       return &api.Branch{
+               Name:   b.Name,
+               Commit: ToCommit(repo, c),
+       }
+}
+
+// ToTag convert a git.Tag to an api.Tag
+func ToTag(repo *models.Repository, t *git.Tag) *api.Tag {
+       return &api.Tag{
+               Name:       t.Name,
+               ID:         t.ID.String(),
+               Commit:     ToCommitMeta(repo, t),
+               ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"),
+               TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"),
+       }
+}
+
+// ToCommit convert a git.Commit to api.PayloadCommit
+func ToCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit {
+       authorUsername := ""
+       if author, err := models.GetUserByEmail(c.Author.Email); err == nil {
+               authorUsername = author.Name
+       } else if !models.IsErrUserNotExist(err) {
+               log.Error("GetUserByEmail: %v", err)
+       }
+
+       committerUsername := ""
+       if committer, err := models.GetUserByEmail(c.Committer.Email); err == nil {
+               committerUsername = committer.Name
+       } else if !models.IsErrUserNotExist(err) {
+               log.Error("GetUserByEmail: %v", err)
+       }
+
+       return &api.PayloadCommit{
+               ID:      c.ID.String(),
+               Message: c.Message(),
+               URL:     util.URLJoin(repo.HTMLURL(), "commit", c.ID.String()),
+               Author: &api.PayloadUser{
+                       Name:     c.Author.Name,
+                       Email:    c.Author.Email,
+                       UserName: authorUsername,
+               },
+               Committer: &api.PayloadUser{
+                       Name:     c.Committer.Name,
+                       Email:    c.Committer.Email,
+                       UserName: committerUsername,
+               },
+               Timestamp:    c.Author.When,
+               Verification: ToVerification(c),
+       }
+}
+
+// ToVerification convert a git.Commit.Signature to an api.PayloadCommitVerification
+func ToVerification(c *git.Commit) *api.PayloadCommitVerification {
+       verif := models.ParseCommitWithSignature(c)
+       commitVerification := &api.PayloadCommitVerification{
+               Verified: verif.Verified,
+               Reason:   verif.Reason,
+       }
+       if c.Signature != nil {
+               commitVerification.Signature = c.Signature.Signature
+               commitVerification.Payload = c.Signature.Payload
+       }
+       if verif.SigningUser != nil {
+               commitVerification.Signer = &structs.PayloadUser{
+                       Name:  verif.SigningUser.Name,
+                       Email: verif.SigningUser.Email,
+               }
+       }
+       return commitVerification
+}
+
+// ToPublicKey convert models.PublicKey to api.PublicKey
+func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
+       return &api.PublicKey{
+               ID:          key.ID,
+               Key:         key.Content,
+               URL:         apiLink + com.ToStr(key.ID),
+               Title:       key.Name,
+               Fingerprint: key.Fingerprint,
+               Created:     key.CreatedUnix.AsTime(),
+       }
+}
+
+// ToGPGKey converts models.GPGKey to api.GPGKey
+func ToGPGKey(key *models.GPGKey) *api.GPGKey {
+       subkeys := make([]*api.GPGKey, len(key.SubsKey))
+       for id, k := range key.SubsKey {
+               subkeys[id] = &api.GPGKey{
+                       ID:                k.ID,
+                       PrimaryKeyID:      k.PrimaryKeyID,
+                       KeyID:             k.KeyID,
+                       PublicKey:         k.Content,
+                       Created:           k.CreatedUnix.AsTime(),
+                       Expires:           k.ExpiredUnix.AsTime(),
+                       CanSign:           k.CanSign,
+                       CanEncryptComms:   k.CanEncryptComms,
+                       CanEncryptStorage: k.CanEncryptStorage,
+                       CanCertify:        k.CanSign,
+               }
+       }
+       emails := make([]*api.GPGKeyEmail, len(key.Emails))
+       for i, e := range key.Emails {
+               emails[i] = ToGPGKeyEmail(e)
+       }
+       return &api.GPGKey{
+               ID:                key.ID,
+               PrimaryKeyID:      key.PrimaryKeyID,
+               KeyID:             key.KeyID,
+               PublicKey:         key.Content,
+               Created:           key.CreatedUnix.AsTime(),
+               Expires:           key.ExpiredUnix.AsTime(),
+               Emails:            emails,
+               SubsKey:           subkeys,
+               CanSign:           key.CanSign,
+               CanEncryptComms:   key.CanEncryptComms,
+               CanEncryptStorage: key.CanEncryptStorage,
+               CanCertify:        key.CanSign,
+       }
+}
+
+// ToGPGKeyEmail convert models.EmailAddress to api.GPGKeyEmail
+func ToGPGKeyEmail(email *models.EmailAddress) *api.GPGKeyEmail {
+       return &api.GPGKeyEmail{
+               Email:    email.Email,
+               Verified: email.IsActivated,
+       }
+}
+
+// ToHook convert models.Webhook to api.Hook
+func ToHook(repoLink string, w *models.Webhook) *api.Hook {
+       config := map[string]string{
+               "url":          w.URL,
+               "content_type": w.ContentType.Name(),
+       }
+       if w.HookTaskType == models.SLACK {
+               s := webhook.GetSlackHook(w)
+               config["channel"] = s.Channel
+               config["username"] = s.Username
+               config["icon_url"] = s.IconURL
+               config["color"] = s.Color
+       }
+
+       return &api.Hook{
+               ID:      w.ID,
+               Type:    w.HookTaskType.Name(),
+               URL:     fmt.Sprintf("%s/settings/hooks/%d", repoLink, w.ID),
+               Active:  w.IsActive,
+               Config:  config,
+               Events:  w.EventsArray(),
+               Updated: w.UpdatedUnix.AsTime(),
+               Created: w.CreatedUnix.AsTime(),
+       }
+}
+
+// ToGitHook convert git.Hook to api.GitHook
+func ToGitHook(h *git.Hook) *api.GitHook {
+       return &api.GitHook{
+               Name:     h.Name(),
+               IsActive: h.IsActive,
+               Content:  h.Content,
+       }
+}
+
+// ToDeployKey convert models.DeployKey to api.DeployKey
+func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
+       return &api.DeployKey{
+               ID:          key.ID,
+               KeyID:       key.KeyID,
+               Key:         key.Content,
+               Fingerprint: key.Fingerprint,
+               URL:         apiLink + com.ToStr(key.ID),
+               Title:       key.Name,
+               Created:     key.CreatedUnix.AsTime(),
+               ReadOnly:    key.Mode == models.AccessModeRead, // All deploy keys are read-only.
+       }
+}
+
+// ToOrganization convert models.User to api.Organization
+func ToOrganization(org *models.User) *api.Organization {
+       return &api.Organization{
+               ID:                        org.ID,
+               AvatarURL:                 org.AvatarLink(),
+               UserName:                  org.Name,
+               FullName:                  org.FullName,
+               Description:               org.Description,
+               Website:                   org.Website,
+               Location:                  org.Location,
+               Visibility:                org.Visibility.String(),
+               RepoAdminChangeTeamAccess: org.RepoAdminChangeTeamAccess,
+       }
+}
+
+// ToTeam convert models.Team to api.Team
+func ToTeam(team *models.Team) *api.Team {
+       return &api.Team{
+               ID:                      team.ID,
+               Name:                    team.Name,
+               Description:             team.Description,
+               IncludesAllRepositories: team.IncludesAllRepositories,
+               Permission:              team.Authorize.String(),
+               Units:                   team.GetUnitNames(),
+       }
+}
+
+// ToUser convert models.User to api.User
+func ToUser(user *models.User, signed, authed bool) *api.User {
+       result := &api.User{
+               UserName:  user.Name,
+               AvatarURL: user.AvatarLink(),
+               FullName:  markup.Sanitize(user.FullName),
+               Created:   user.CreatedUnix.AsTime(),
+       }
+       // hide primary email if API caller isn't user itself or an admin
+       if !signed {
+               result.Email = ""
+       } else if user.KeepEmailPrivate && !authed {
+               result.Email = user.GetEmail()
+       } else { // only user himself and admin could visit these information
+               result.ID = user.ID
+               result.Email = user.Email
+               result.IsAdmin = user.IsAdmin
+               result.LastLogin = user.LastLoginUnix.AsTime()
+       }
+       return result
+}
+
+// ToAnnotatedTag convert git.Tag to api.AnnotatedTag
+func ToAnnotatedTag(repo *models.Repository, t *git.Tag, c *git.Commit) *api.AnnotatedTag {
+       return &api.AnnotatedTag{
+               Tag:          t.Name,
+               SHA:          t.ID.String(),
+               Object:       ToAnnotatedTagObject(repo, c),
+               Message:      t.Message,
+               URL:          util.URLJoin(repo.APIURL(), "git/tags", t.ID.String()),
+               Tagger:       ToCommitUser(t.Tagger),
+               Verification: ToVerification(c),
+       }
+}
+
+// ToAnnotatedTagObject convert a git.Commit to an api.AnnotatedTagObject
+func ToAnnotatedTagObject(repo *models.Repository, commit *git.Commit) *api.AnnotatedTagObject {
+       return &api.AnnotatedTagObject{
+               SHA:  commit.ID.String(),
+               Type: string(git.ObjectCommit),
+               URL:  util.URLJoin(repo.APIURL(), "git/commits", commit.ID.String()),
+       }
+}
+
+// ToCommitUser convert a git.Signature to an api.CommitUser
+func ToCommitUser(sig *git.Signature) *api.CommitUser {
+       return &api.CommitUser{
+               Identity: api.Identity{
+                       Name:  sig.Name,
+                       Email: sig.Email,
+               },
+               Date: sig.When.UTC().Format(time.RFC3339),
+       }
+}
+
+// ToCommitMeta convert a git.Tag to an api.CommitMeta
+func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta {
+       return &api.CommitMeta{
+               SHA: tag.Object.String(),
+               // TODO: Add the /commits API endpoint and use it here (https://developer.github.com/v3/repos/commits/#get-a-single-commit)
+               URL: util.URLJoin(repo.APIURL(), "git/commits", tag.ID.String()),
+       }
+}
+
+// ToTopicResponse convert from models.Topic to api.TopicResponse
+func ToTopicResponse(topic *models.Topic) *api.TopicResponse {
+       return &api.TopicResponse{
+               ID:        topic.ID,
+               Name:      topic.Name,
+               RepoCount: topic.RepoCount,
+               Created:   topic.CreatedUnix.AsTime(),
+               Updated:   topic.UpdatedUnix.AsTime(),
+       }
+}
diff --git a/modules/convert/utils.go b/modules/convert/utils.go
new file mode 100644 (file)
index 0000000..66fb21b
--- /dev/null
@@ -0,0 +1,19 @@
+// Copyright 2016 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 convert
+
+import (
+       "code.gitea.io/gitea/modules/setting"
+)
+
+// ToCorrectPageSize makes sure page size is in allowed range.
+func ToCorrectPageSize(size int) int {
+       if size <= 0 {
+               size = 10
+       } else if size > setting.API.MaxResponseItems {
+               size = setting.API.MaxResponseItems
+       }
+       return size
+}
index cdec9e7fad2084f3e1877c1267012e6f1acda8c5..8d3b0123c532c8bc7d4bf64009fcff7ba2604b4c 100644 (file)
@@ -8,8 +8,8 @@ package admin
 import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
        "code.gitea.io/gitea/routers/api/v1/user"
 )
 
index f35ad297b0ca44deb7fc9b6e73c3da7036ffc397..3a4750c6ba5a937f722a03e137c253abc775822c 100644 (file)
@@ -10,10 +10,10 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/password"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
        "code.gitea.io/gitea/routers/api/v1/user"
        "code.gitea.io/gitea/services/mailer"
 )
diff --git a/routers/api/v1/convert/convert.go b/routers/api/v1/convert/convert.go
deleted file mode 100644 (file)
index f52ed63..0000000
+++ /dev/null
@@ -1,312 +0,0 @@
-// 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 convert
-
-import (
-       "fmt"
-       "time"
-
-       "code.gitea.io/gitea/models"
-       "code.gitea.io/gitea/modules/git"
-       "code.gitea.io/gitea/modules/log"
-       "code.gitea.io/gitea/modules/markup"
-       "code.gitea.io/gitea/modules/structs"
-       api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/modules/util"
-       "code.gitea.io/gitea/modules/webhook"
-
-       "github.com/unknwon/com"
-)
-
-// ToEmail convert models.EmailAddress to api.Email
-func ToEmail(email *models.EmailAddress) *api.Email {
-       return &api.Email{
-               Email:    email.Email,
-               Verified: email.IsActivated,
-               Primary:  email.IsPrimary,
-       }
-}
-
-// ToBranch convert a git.Commit and git.Branch to an api.Branch
-func ToBranch(repo *models.Repository, b *git.Branch, c *git.Commit) *api.Branch {
-       return &api.Branch{
-               Name:   b.Name,
-               Commit: ToCommit(repo, c),
-       }
-}
-
-// ToTag convert a git.Tag to an api.Tag
-func ToTag(repo *models.Repository, t *git.Tag) *api.Tag {
-       return &api.Tag{
-               Name:       t.Name,
-               ID:         t.ID.String(),
-               Commit:     ToCommitMeta(repo, t),
-               ZipballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".zip"),
-               TarballURL: util.URLJoin(repo.HTMLURL(), "archive", t.Name+".tar.gz"),
-       }
-}
-
-// ToCommit convert a git.Commit to api.PayloadCommit
-func ToCommit(repo *models.Repository, c *git.Commit) *api.PayloadCommit {
-       authorUsername := ""
-       if author, err := models.GetUserByEmail(c.Author.Email); err == nil {
-               authorUsername = author.Name
-       } else if !models.IsErrUserNotExist(err) {
-               log.Error("GetUserByEmail: %v", err)
-       }
-
-       committerUsername := ""
-       if committer, err := models.GetUserByEmail(c.Committer.Email); err == nil {
-               committerUsername = committer.Name
-       } else if !models.IsErrUserNotExist(err) {
-               log.Error("GetUserByEmail: %v", err)
-       }
-
-       return &api.PayloadCommit{
-               ID:      c.ID.String(),
-               Message: c.Message(),
-               URL:     util.URLJoin(repo.HTMLURL(), "commit", c.ID.String()),
-               Author: &api.PayloadUser{
-                       Name:     c.Author.Name,
-                       Email:    c.Author.Email,
-                       UserName: authorUsername,
-               },
-               Committer: &api.PayloadUser{
-                       Name:     c.Committer.Name,
-                       Email:    c.Committer.Email,
-                       UserName: committerUsername,
-               },
-               Timestamp:    c.Author.When,
-               Verification: ToVerification(c),
-       }
-}
-
-// ToVerification convert a git.Commit.Signature to an api.PayloadCommitVerification
-func ToVerification(c *git.Commit) *api.PayloadCommitVerification {
-       verif := models.ParseCommitWithSignature(c)
-       commitVerification := &api.PayloadCommitVerification{
-               Verified: verif.Verified,
-               Reason:   verif.Reason,
-       }
-       if c.Signature != nil {
-               commitVerification.Signature = c.Signature.Signature
-               commitVerification.Payload = c.Signature.Payload
-       }
-       if verif.SigningUser != nil {
-               commitVerification.Signer = &structs.PayloadUser{
-                       Name:  verif.SigningUser.Name,
-                       Email: verif.SigningUser.Email,
-               }
-       }
-       return commitVerification
-}
-
-// ToPublicKey convert models.PublicKey to api.PublicKey
-func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
-       return &api.PublicKey{
-               ID:          key.ID,
-               Key:         key.Content,
-               URL:         apiLink + com.ToStr(key.ID),
-               Title:       key.Name,
-               Fingerprint: key.Fingerprint,
-               Created:     key.CreatedUnix.AsTime(),
-       }
-}
-
-// ToGPGKey converts models.GPGKey to api.GPGKey
-func ToGPGKey(key *models.GPGKey) *api.GPGKey {
-       subkeys := make([]*api.GPGKey, len(key.SubsKey))
-       for id, k := range key.SubsKey {
-               subkeys[id] = &api.GPGKey{
-                       ID:                k.ID,
-                       PrimaryKeyID:      k.PrimaryKeyID,
-                       KeyID:             k.KeyID,
-                       PublicKey:         k.Content,
-                       Created:           k.CreatedUnix.AsTime(),
-                       Expires:           k.ExpiredUnix.AsTime(),
-                       CanSign:           k.CanSign,
-                       CanEncryptComms:   k.CanEncryptComms,
-                       CanEncryptStorage: k.CanEncryptStorage,
-                       CanCertify:        k.CanSign,
-               }
-       }
-       emails := make([]*api.GPGKeyEmail, len(key.Emails))
-       for i, e := range key.Emails {
-               emails[i] = ToGPGKeyEmail(e)
-       }
-       return &api.GPGKey{
-               ID:                key.ID,
-               PrimaryKeyID:      key.PrimaryKeyID,
-               KeyID:             key.KeyID,
-               PublicKey:         key.Content,
-               Created:           key.CreatedUnix.AsTime(),
-               Expires:           key.ExpiredUnix.AsTime(),
-               Emails:            emails,
-               SubsKey:           subkeys,
-               CanSign:           key.CanSign,
-               CanEncryptComms:   key.CanEncryptComms,
-               CanEncryptStorage: key.CanEncryptStorage,
-               CanCertify:        key.CanSign,
-       }
-}
-
-// ToGPGKeyEmail convert models.EmailAddress to api.GPGKeyEmail
-func ToGPGKeyEmail(email *models.EmailAddress) *api.GPGKeyEmail {
-       return &api.GPGKeyEmail{
-               Email:    email.Email,
-               Verified: email.IsActivated,
-       }
-}
-
-// ToHook convert models.Webhook to api.Hook
-func ToHook(repoLink string, w *models.Webhook) *api.Hook {
-       config := map[string]string{
-               "url":          w.URL,
-               "content_type": w.ContentType.Name(),
-       }
-       if w.HookTaskType == models.SLACK {
-               s := webhook.GetSlackHook(w)
-               config["channel"] = s.Channel
-               config["username"] = s.Username
-               config["icon_url"] = s.IconURL
-               config["color"] = s.Color
-       }
-
-       return &api.Hook{
-               ID:      w.ID,
-               Type:    w.HookTaskType.Name(),
-               URL:     fmt.Sprintf("%s/settings/hooks/%d", repoLink, w.ID),
-               Active:  w.IsActive,
-               Config:  config,
-               Events:  w.EventsArray(),
-               Updated: w.UpdatedUnix.AsTime(),
-               Created: w.CreatedUnix.AsTime(),
-       }
-}
-
-// ToGitHook convert git.Hook to api.GitHook
-func ToGitHook(h *git.Hook) *api.GitHook {
-       return &api.GitHook{
-               Name:     h.Name(),
-               IsActive: h.IsActive,
-               Content:  h.Content,
-       }
-}
-
-// ToDeployKey convert models.DeployKey to api.DeployKey
-func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
-       return &api.DeployKey{
-               ID:          key.ID,
-               KeyID:       key.KeyID,
-               Key:         key.Content,
-               Fingerprint: key.Fingerprint,
-               URL:         apiLink + com.ToStr(key.ID),
-               Title:       key.Name,
-               Created:     key.CreatedUnix.AsTime(),
-               ReadOnly:    key.Mode == models.AccessModeRead, // All deploy keys are read-only.
-       }
-}
-
-// ToOrganization convert models.User to api.Organization
-func ToOrganization(org *models.User) *api.Organization {
-       return &api.Organization{
-               ID:                        org.ID,
-               AvatarURL:                 org.AvatarLink(),
-               UserName:                  org.Name,
-               FullName:                  org.FullName,
-               Description:               org.Description,
-               Website:                   org.Website,
-               Location:                  org.Location,
-               Visibility:                org.Visibility.String(),
-               RepoAdminChangeTeamAccess: org.RepoAdminChangeTeamAccess,
-       }
-}
-
-// ToTeam convert models.Team to api.Team
-func ToTeam(team *models.Team) *api.Team {
-       return &api.Team{
-               ID:                      team.ID,
-               Name:                    team.Name,
-               Description:             team.Description,
-               IncludesAllRepositories: team.IncludesAllRepositories,
-               Permission:              team.Authorize.String(),
-               Units:                   team.GetUnitNames(),
-       }
-}
-
-// ToUser convert models.User to api.User
-func ToUser(user *models.User, signed, authed bool) *api.User {
-       result := &api.User{
-               UserName:  user.Name,
-               AvatarURL: user.AvatarLink(),
-               FullName:  markup.Sanitize(user.FullName),
-               Created:   user.CreatedUnix.AsTime(),
-       }
-       // hide primary email if API caller isn't user itself or an admin
-       if !signed {
-               result.Email = ""
-       } else if user.KeepEmailPrivate && !authed {
-               result.Email = user.GetEmail()
-       } else { // only user himself and admin could visit these information
-               result.ID = user.ID
-               result.Email = user.Email
-               result.IsAdmin = user.IsAdmin
-               result.LastLogin = user.LastLoginUnix.AsTime()
-       }
-       return result
-}
-
-// ToAnnotatedTag convert git.Tag to api.AnnotatedTag
-func ToAnnotatedTag(repo *models.Repository, t *git.Tag, c *git.Commit) *api.AnnotatedTag {
-       return &api.AnnotatedTag{
-               Tag:          t.Name,
-               SHA:          t.ID.String(),
-               Object:       ToAnnotatedTagObject(repo, c),
-               Message:      t.Message,
-               URL:          util.URLJoin(repo.APIURL(), "git/tags", t.ID.String()),
-               Tagger:       ToCommitUser(t.Tagger),
-               Verification: ToVerification(c),
-       }
-}
-
-// ToAnnotatedTagObject convert a git.Commit to an api.AnnotatedTagObject
-func ToAnnotatedTagObject(repo *models.Repository, commit *git.Commit) *api.AnnotatedTagObject {
-       return &api.AnnotatedTagObject{
-               SHA:  commit.ID.String(),
-               Type: string(git.ObjectCommit),
-               URL:  util.URLJoin(repo.APIURL(), "git/commits", commit.ID.String()),
-       }
-}
-
-// ToCommitUser convert a git.Signature to an api.CommitUser
-func ToCommitUser(sig *git.Signature) *api.CommitUser {
-       return &api.CommitUser{
-               Identity: api.Identity{
-                       Name:  sig.Name,
-                       Email: sig.Email,
-               },
-               Date: sig.When.UTC().Format(time.RFC3339),
-       }
-}
-
-// ToCommitMeta convert a git.Tag to an api.CommitMeta
-func ToCommitMeta(repo *models.Repository, tag *git.Tag) *api.CommitMeta {
-       return &api.CommitMeta{
-               SHA: tag.Object.String(),
-               // TODO: Add the /commits API endpoint and use it here (https://developer.github.com/v3/repos/commits/#get-a-single-commit)
-               URL: util.URLJoin(repo.APIURL(), "git/commits", tag.ID.String()),
-       }
-}
-
-// ToTopicResponse convert from models.Topic to api.TopicResponse
-func ToTopicResponse(topic *models.Topic) *api.TopicResponse {
-       return &api.TopicResponse{
-               ID:        topic.ID,
-               Name:      topic.Name,
-               RepoCount: topic.RepoCount,
-               Created:   topic.CreatedUnix.AsTime(),
-               Updated:   topic.UpdatedUnix.AsTime(),
-       }
-}
diff --git a/routers/api/v1/convert/utils.go b/routers/api/v1/convert/utils.go
deleted file mode 100644 (file)
index 66fb21b..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-// Copyright 2016 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 convert
-
-import (
-       "code.gitea.io/gitea/modules/setting"
-)
-
-// ToCorrectPageSize makes sure page size is in allowed range.
-func ToCorrectPageSize(size int) int {
-       if size <= 0 {
-               size = 10
-       } else if size > setting.API.MaxResponseItems {
-               size = setting.API.MaxResponseItems
-       }
-       return size
-}
index 3f391e4b2bf2813263a041e120d48c679addadde..c7b0bd5b6b1545d1e9502859658fe474e0ce5efa 100644 (file)
@@ -7,8 +7,8 @@ package org
 import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
        "code.gitea.io/gitea/routers/api/v1/utils"
 )
 
index 370536d22f6400bfe7a944c927c622375eb69f39..be47b6963fb4929551b6d727cb58fdc53ab6fd7a 100644 (file)
@@ -9,9 +9,9 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
        "code.gitea.io/gitea/routers/api/v1/user"
 )
 
index 8a1a478ba18e6c718f2a9ca06780936ceb7c9dda..d698592361d224234ee2106654d6128adf033446 100644 (file)
@@ -8,8 +8,8 @@ package org
 import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
        "code.gitea.io/gitea/routers/api/v1/user"
 )
 
index a22b60a2c68039bf4b9debb05bd50aac11b6d7aa..b2b5fe6dadb389e17f2dc14596da9e680155104a 100644 (file)
@@ -10,9 +10,9 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/log"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
        "code.gitea.io/gitea/routers/api/v1/user"
 )
 
index 670123a858870d52998fa34b5792bff9d0acd2ec..9f6a2e6294f392a1794580eff1a689585e498054 100644 (file)
@@ -7,9 +7,9 @@ package repo
 
 import (
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/git"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 )
 
 // GetBranch get a branch of a repository
index 132652e2a991c80b6526e96c9515399fcd4ab29e..81d472dffb3aada66d9418718e8913473e1ebda9 100644 (file)
@@ -10,8 +10,8 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 )
 
 // ListCollaborators list a repository's collaborators
index 80610356dddfe3a075fadcf3bada5e00b2e61345..46651ef614065122b03381401e1adf8955e76058 100644 (file)
@@ -6,9 +6,9 @@ package repo
 
 import (
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/git"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 )
 
 // ListGitHooks list all Git hooks of a repository
index 18f1fba0562c0c78e43cf325998888f23390f03b..3666d79fa08bba3525d8be5c71dcd85ace5ae2ba 100644 (file)
@@ -7,10 +7,10 @@ package repo
 import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/git"
        api "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/modules/webhook"
-       "code.gitea.io/gitea/routers/api/v1/convert"
        "code.gitea.io/gitea/routers/api/v1/utils"
 )
 
index 42bf024a5fcb995000f88bd647218254873918bf..6b499d2fb11077f40a0b53bc00e1fc7e330cbb30 100644 (file)
@@ -9,9 +9,9 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 )
 
 // appendPrivateInformation appends the owner and key type information to api.PublicKey
index 7b752370d44e6e2df0bd67f4aa90db06301077dc..c907bba66bef520d355fc3bd09bedb5d18fe0ee3 100644 (file)
@@ -16,6 +16,7 @@ import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/auth"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/log"
        "code.gitea.io/gitea/modules/migrations"
        "code.gitea.io/gitea/modules/notification"
@@ -24,7 +25,6 @@ import (
        api "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/modules/util"
        "code.gitea.io/gitea/modules/validation"
-       "code.gitea.io/gitea/routers/api/v1/convert"
        mirror_service "code.gitea.io/gitea/services/mirror"
        repo_service "code.gitea.io/gitea/services/repository"
 )
index 2eb5daeced756854abdbaef48de50ac6afa94981..8fe5b17c5f2ecb6455b5edc4d368150bd5da1976 100644 (file)
@@ -6,8 +6,8 @@ package repo
 
 import (
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 )
 
 // ListStargazers list a repository's stargazers
index 79ad0e0221752b447786485936857d3f0d575a59..0e576b4ff0f5c2401c34ddd09458a3c3e1c3a87f 100644 (file)
@@ -6,8 +6,8 @@ package repo
 
 import (
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 )
 
 // ListSubscribers list a repo's subscribers (i.e. watchers)
index a802048285d69c55da4206231e474c2315d27c3d..6cfdb461ee261e40f56b6e6bb148da1f77aa8224 100644 (file)
@@ -8,8 +8,8 @@ import (
        "net/http"
 
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 )
 
 // ListTags list all the tags of a repository
index 6c3ac0020af192849d6a6447a121e43c4bddcbb7..1656fd1b16c768a35e52aaa30c9f5c0a03d61a6a 100644 (file)
@@ -10,9 +10,9 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/log"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 )
 
 // ListTopics returns list of current topics for repo
index 027f4e276300a59a5416aceb3ffbf0d1451a657b..8c0eb889ed12451ec4b9d4f3874634ffe6fe864d 100644 (file)
@@ -7,9 +7,9 @@ package user
 import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 )
 
 // ListEmails list all of the authenticated user's email addresses
index 59df9665f40622e0c897ed69b260d099778dc57a..ec512b9806e93f217ffa3a4f93318f8e7bb3477a 100644 (file)
@@ -7,8 +7,8 @@ package user
 import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 )
 
 func responseAPIUsers(ctx *context.APIContext, users []*models.User) {
index fa85e47a82aafcc0ca4fa8c7908109a2bf0a94b8..82113caf0cbc6258367cab8d4e093a641a48b035 100644 (file)
@@ -7,8 +7,8 @@ package user
 import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 )
 
 func listGPGKeys(ctx *context.APIContext, uid int64) {
index 8425535b108972e85867088d15035038df9e31e9..a812edfcc7a4877fd7bd33259adfa3502a1ea046 100644 (file)
@@ -7,9 +7,9 @@ package user
 import (
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        "code.gitea.io/gitea/modules/setting"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
        "code.gitea.io/gitea/routers/api/v1/repo"
 )
 
index 0639494c0edbde67d7461a15ebe52774e791bb41..6f3fc4d32bbbca52aab993dd8b8c4800da74e069 100644 (file)
@@ -10,8 +10,8 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
-       "code.gitea.io/gitea/routers/api/v1/convert"
 
        "github.com/unknwon/com"
 )
index 6f72e99b714a6b1cfabdc84f5323a2584fa89a51..f88b15200389ad50675e6cec6b39711d2d5dd640 100644 (file)
@@ -11,9 +11,9 @@ import (
 
        "code.gitea.io/gitea/models"
        "code.gitea.io/gitea/modules/context"
+       "code.gitea.io/gitea/modules/convert"
        api "code.gitea.io/gitea/modules/structs"
        "code.gitea.io/gitea/modules/webhook"
-       "code.gitea.io/gitea/routers/api/v1/convert"
        "code.gitea.io/gitea/routers/utils"
 
        "github.com/unknwon/com"