aboutsummaryrefslogtreecommitdiff
path: root/routes/api/v1/convert
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2019-10-24 01:51:46 -0700
committerGitHub <noreply@github.com>2019-10-24 01:51:46 -0700
commit01c8df01ec0608f1f25b2f1444adabb98fa5ee8a (patch)
treef8a7e5dd8d2a8c51e1ce2cabb9d33571a93314dd /routes/api/v1/convert
parent613139e7bef81d3573e7988a47eb6765f3de347a (diff)
internal: move packages under this directory (#5836)
* Rename pkg -> internal * Rename routes -> route * Move route -> internal/route * Rename models -> db * Move db -> internal/db * Fix route2 -> route * Move cmd -> internal/cmd * Bump version
Diffstat (limited to 'routes/api/v1/convert')
-rw-r--r--routes/api/v1/convert/convert.go127
-rw-r--r--routes/api/v1/convert/utils.go19
2 files changed, 0 insertions, 146 deletions
diff --git a/routes/api/v1/convert/convert.go b/routes/api/v1/convert/convert.go
deleted file mode 100644
index 767fd7da..00000000
--- a/routes/api/v1/convert/convert.go
+++ /dev/null
@@ -1,127 +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"
-
- "github.com/unknwon/com"
-
- "github.com/gogs/git-module"
- api "github.com/gogs/go-gogs-client"
-
- "gogs.io/gogs/models"
-)
-
-func ToEmail(email *models.EmailAddress) *api.Email {
- return &api.Email{
- Email: email.Email,
- Verified: email.IsActivated,
- Primary: email.IsPrimary,
- }
-}
-
-func ToBranch(b *models.Branch, c *git.Commit) *api.Branch {
- return &api.Branch{
- Name: b.Name,
- Commit: ToCommit(c),
- }
-}
-
-func ToCommit(c *git.Commit) *api.PayloadCommit {
- authorUsername := ""
- author, err := models.GetUserByEmail(c.Author.Email)
- if err == nil {
- authorUsername = author.Name
- }
- committerUsername := ""
- committer, err := models.GetUserByEmail(c.Committer.Email)
- if err == nil {
- committerUsername = committer.Name
- }
- return &api.PayloadCommit{
- ID: c.ID.String(),
- Message: c.Message(),
- URL: "Not implemented",
- 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,
- }
-}
-
-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,
- Created: key.Created,
- }
-}
-
-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 := w.GetSlackHook()
- 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.Updated,
- Created: w.Created,
- }
-}
-
-func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
- return &api.DeployKey{
- ID: key.ID,
- Key: key.Content,
- URL: apiLink + com.ToStr(key.ID),
- Title: key.Name,
- Created: key.Created,
- ReadOnly: true, // All deploy keys are read-only.
- }
-}
-
-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,
- }
-}
-
-func ToTeam(team *models.Team) *api.Team {
- return &api.Team{
- ID: team.ID,
- Name: team.Name,
- Description: team.Description,
- Permission: team.Authorize.String(),
- }
-}
diff --git a/routes/api/v1/convert/utils.go b/routes/api/v1/convert/utils.go
deleted file mode 100644
index 08d6edad..00000000
--- a/routes/api/v1/convert/utils.go
+++ /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 (
- "gogs.io/gogs/pkg/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
-}