2015-12-05 03:46:42 +05:30
|
|
|
// 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.
|
|
|
|
|
2015-12-17 12:58:47 +05:30
|
|
|
package convert
|
2015-12-05 03:46:42 +05:30
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/Unknwon/com"
|
|
|
|
|
2016-11-06 18:48:34 +05:30
|
|
|
"github.com/go-gitea/git"
|
2016-11-07 20:32:19 +05:30
|
|
|
api "github.com/go-gitea/go-sdk/gitea"
|
2015-12-05 03:46:42 +05:30
|
|
|
|
2016-11-03 17:59:56 +05:30
|
|
|
"github.com/go-gitea/gitea/models"
|
2015-12-05 03:46:42 +05:30
|
|
|
)
|
|
|
|
|
2016-03-14 08:50:22 +05:30
|
|
|
func ToEmail(email *models.EmailAddress) *api.Email {
|
2015-12-16 09:27:18 +05:30
|
|
|
return &api.Email{
|
|
|
|
Email: email.Email,
|
|
|
|
Verified: email.IsActivated,
|
|
|
|
Primary: email.IsPrimary,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-14 08:50:22 +05:30
|
|
|
func ToBranch(b *models.Branch, c *git.Commit) *api.Branch {
|
2016-01-29 01:19:05 +05:30
|
|
|
return &api.Branch{
|
2016-03-14 08:50:22 +05:30
|
|
|
Name: b.Name,
|
|
|
|
Commit: ToCommit(c),
|
|
|
|
}
|
2016-01-29 01:19:05 +05:30
|
|
|
}
|
|
|
|
|
2016-03-14 08:50:22 +05:30
|
|
|
func ToCommit(c *git.Commit) *api.PayloadCommit {
|
2016-08-10 10:31:57 +05:30
|
|
|
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
|
|
|
|
}
|
2016-01-29 01:19:05 +05:30
|
|
|
return &api.PayloadCommit{
|
2016-03-14 08:50:22 +05:30
|
|
|
ID: c.ID.String(),
|
2016-01-29 01:19:05 +05:30
|
|
|
Message: c.Message(),
|
2016-03-14 08:50:22 +05:30
|
|
|
URL: "Not implemented",
|
2016-08-14 16:47:26 +05:30
|
|
|
Author: &api.PayloadUser{
|
2016-08-10 10:31:57 +05:30
|
|
|
Name: c.Author.Name,
|
|
|
|
Email: c.Author.Email,
|
|
|
|
UserName: authorUsername,
|
|
|
|
},
|
2016-08-14 16:47:26 +05:30
|
|
|
Committer: &api.PayloadUser{
|
2016-08-10 10:31:57 +05:30
|
|
|
Name: c.Committer.Name,
|
|
|
|
Email: c.Committer.Email,
|
|
|
|
UserName: committerUsername,
|
2016-01-29 01:19:05 +05:30
|
|
|
},
|
2016-08-10 10:31:57 +05:30
|
|
|
Timestamp: c.Author.When,
|
2016-01-29 01:19:05 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-14 08:50:22 +05:30
|
|
|
func ToPublicKey(apiLink string, key *models.PublicKey) *api.PublicKey {
|
2015-12-05 03:46:42 +05:30
|
|
|
return &api.PublicKey{
|
|
|
|
ID: key.ID,
|
|
|
|
Key: key.Content,
|
|
|
|
URL: apiLink + com.ToStr(key.ID),
|
|
|
|
Title: key.Name,
|
|
|
|
Created: key.Created,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-14 08:50:22 +05:30
|
|
|
func ToHook(repoLink string, w *models.Webhook) *api.Hook {
|
2015-12-05 03:46:42 +05:30
|
|
|
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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-03-14 08:50:22 +05:30
|
|
|
func ToDeployKey(apiLink string, key *models.DeployKey) *api.DeployKey {
|
2015-12-05 03:46:42 +05:30
|
|
|
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.
|
|
|
|
}
|
|
|
|
}
|
2015-12-17 12:58:47 +05:30
|
|
|
|
2016-03-14 08:50:22 +05:30
|
|
|
func ToOrganization(org *models.User) *api.Organization {
|
2015-12-17 12:58:47 +05:30
|
|
|
return &api.Organization{
|
2016-07-23 22:38:22 +05:30
|
|
|
ID: org.ID,
|
2015-12-17 12:58:47 +05:30
|
|
|
AvatarUrl: org.AvatarLink(),
|
|
|
|
UserName: org.Name,
|
|
|
|
FullName: org.FullName,
|
|
|
|
Description: org.Description,
|
|
|
|
Website: org.Website,
|
|
|
|
Location: org.Location,
|
|
|
|
}
|
|
|
|
}
|
2016-03-21 22:17:54 +05:30
|
|
|
|
|
|
|
func ToTeam(team *models.Team) *api.Team {
|
|
|
|
return &api.Team{
|
|
|
|
ID: team.ID,
|
|
|
|
Name: team.Name,
|
|
|
|
Description: team.Description,
|
|
|
|
Permission: team.Authorize.String(),
|
|
|
|
}
|
|
|
|
}
|