2015-12-04 17:16:42 -05:00
|
|
|
// Copyright 2015 The Gogs Authors. All rights reserved.
|
2020-09-17 17:33:23 -04:00
|
|
|
// Copyright 2018 The Gitea Authors. All rights reserved.
|
2015-12-04 17:16:42 -05:00
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2015-12-17 02:28:47 -05:00
|
|
|
package convert
|
2015-12-04 17:16:42 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2020-12-03 09:05:48 -05:00
|
|
|
"strconv"
|
2021-06-17 12:04:10 -04:00
|
|
|
"strings"
|
2020-12-03 09:05:48 -05:00
|
|
|
"time"
|
2015-12-04 17:16:42 -05:00
|
|
|
|
2016-11-10 11:24:48 -05:00
|
|
|
"code.gitea.io/gitea/models"
|
2021-12-10 03:14:24 -05:00
|
|
|
asymkey_model "code.gitea.io/gitea/models/asymkey"
|
2021-09-24 07:32:56 -04:00
|
|
|
"code.gitea.io/gitea/models/login"
|
2021-11-28 06:58:28 -05:00
|
|
|
"code.gitea.io/gitea/models/perm"
|
2021-12-09 20:27:50 -05:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-09 14:57:58 -05:00
|
|
|
"code.gitea.io/gitea/models/unit"
|
2021-11-11 02:03:30 -05:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2021-11-10 00:13:16 -05:00
|
|
|
"code.gitea.io/gitea/models/webhook"
|
2019-03-27 05:33:00 -04:00
|
|
|
"code.gitea.io/gitea/modules/git"
|
2018-02-20 07:50:42 -05:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2019-05-11 06:21:34 -04:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2018-02-20 07:50:42 -05:00
|
|
|
"code.gitea.io/gitea/modules/util"
|
2021-11-10 00:13:16 -05:00
|
|
|
webhook_service "code.gitea.io/gitea/services/webhook"
|
2015-12-04 17:16:42 -05:00
|
|
|
)
|
|
|
|
|
2016-11-24 02:04:31 -05:00
|
|
|
// ToEmail convert models.EmailAddress to api.Email
|
2021-11-11 02:03:30 -05:00
|
|
|
func ToEmail(email *user_model.EmailAddress) *api.Email {
|
2015-12-15 22:57:18 -05:00
|
|
|
return &api.Email{
|
|
|
|
Email: email.Email,
|
|
|
|
Verified: email.IsActivated,
|
|
|
|
Primary: email.IsPrimary,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-08 10:31:11 -04:00
|
|
|
// ToBranch convert a git.Commit and git.Branch to an api.Branch
|
2021-12-09 20:27:50 -05:00
|
|
|
func ToBranch(repo *repo_model.Repository, b *git.Branch, c *git.Commit, bp *models.ProtectedBranch, user *user_model.User, isRepoAdmin bool) (*api.Branch, error) {
|
2019-11-16 14:39:18 -05:00
|
|
|
if bp == nil {
|
2020-03-20 23:41:33 -04:00
|
|
|
var hasPerm bool
|
|
|
|
var err error
|
|
|
|
if user != nil {
|
2021-11-28 06:58:28 -05:00
|
|
|
hasPerm, err = models.HasAccessUnit(user, repo, unit.TypeCode, perm.AccessModeWrite)
|
2020-03-20 23:41:33 -04:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2019-11-16 14:39:18 -05:00
|
|
|
}
|
2020-03-20 23:41:33 -04:00
|
|
|
|
|
|
|
return &api.Branch{
|
|
|
|
Name: b.Name,
|
2020-09-18 08:09:26 -04:00
|
|
|
Commit: ToPayloadCommit(repo, c),
|
2020-03-20 23:41:33 -04:00
|
|
|
Protected: false,
|
|
|
|
RequiredApprovals: 0,
|
|
|
|
EnableStatusCheck: false,
|
|
|
|
StatusCheckContexts: []string{},
|
|
|
|
UserCanPush: hasPerm,
|
|
|
|
UserCanMerge: hasPerm,
|
|
|
|
}, nil
|
2020-02-12 18:19:35 -05:00
|
|
|
}
|
|
|
|
|
2020-03-19 11:39:08 -04:00
|
|
|
branch := &api.Branch{
|
2020-03-20 23:41:33 -04:00
|
|
|
Name: b.Name,
|
2020-09-18 08:09:26 -04:00
|
|
|
Commit: ToPayloadCommit(repo, c),
|
2020-03-20 23:41:33 -04:00
|
|
|
Protected: true,
|
|
|
|
RequiredApprovals: bp.RequiredApprovals,
|
|
|
|
EnableStatusCheck: bp.EnableStatusCheck,
|
|
|
|
StatusCheckContexts: bp.StatusCheckContexts,
|
|
|
|
}
|
|
|
|
|
|
|
|
if isRepoAdmin {
|
|
|
|
branch.EffectiveBranchProtectionName = bp.BranchName
|
2020-02-12 18:19:35 -05:00
|
|
|
}
|
2020-03-19 11:39:08 -04:00
|
|
|
|
|
|
|
if user != nil {
|
2020-08-20 03:48:40 -04:00
|
|
|
permission, err := models.GetUserRepoPermission(repo, user)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2020-03-19 11:39:08 -04:00
|
|
|
branch.UserCanPush = bp.CanUserPush(user.ID)
|
2021-12-09 20:27:50 -05:00
|
|
|
branch.UserCanMerge = models.IsUserMergeWhitelisted(bp, user.ID, permission)
|
2020-03-19 11:39:08 -04:00
|
|
|
}
|
2020-03-20 23:41:33 -04:00
|
|
|
|
|
|
|
return branch, nil
|
2020-02-12 18:19:35 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// ToBranchProtection convert a ProtectedBranch to api.BranchProtection
|
|
|
|
func ToBranchProtection(bp *models.ProtectedBranch) *api.BranchProtection {
|
2021-11-24 04:49:20 -05:00
|
|
|
pushWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.WhitelistUserIDs)
|
2020-02-12 18:19:35 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Error("GetUserNamesByIDs (WhitelistUserIDs): %v", err)
|
|
|
|
}
|
2021-11-24 04:49:20 -05:00
|
|
|
mergeWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.MergeWhitelistUserIDs)
|
2020-02-12 18:19:35 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Error("GetUserNamesByIDs (MergeWhitelistUserIDs): %v", err)
|
|
|
|
}
|
2021-11-24 04:49:20 -05:00
|
|
|
approvalsWhitelistUsernames, err := user_model.GetUserNamesByIDs(bp.ApprovalsWhitelistUserIDs)
|
2020-02-12 18:19:35 -05:00
|
|
|
if err != nil {
|
|
|
|
log.Error("GetUserNamesByIDs (ApprovalsWhitelistUserIDs): %v", err)
|
|
|
|
}
|
|
|
|
pushWhitelistTeams, err := models.GetTeamNamesByID(bp.WhitelistTeamIDs)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("GetTeamNamesByID (WhitelistTeamIDs): %v", err)
|
|
|
|
}
|
|
|
|
mergeWhitelistTeams, err := models.GetTeamNamesByID(bp.MergeWhitelistTeamIDs)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("GetTeamNamesByID (MergeWhitelistTeamIDs): %v", err)
|
|
|
|
}
|
|
|
|
approvalsWhitelistTeams, err := models.GetTeamNamesByID(bp.ApprovalsWhitelistTeamIDs)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("GetTeamNamesByID (ApprovalsWhitelistTeamIDs): %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &api.BranchProtection{
|
2020-11-28 14:30:46 -05:00
|
|
|
BranchName: bp.BranchName,
|
|
|
|
EnablePush: bp.CanPush,
|
|
|
|
EnablePushWhitelist: bp.EnableWhitelist,
|
|
|
|
PushWhitelistUsernames: pushWhitelistUsernames,
|
|
|
|
PushWhitelistTeams: pushWhitelistTeams,
|
|
|
|
PushWhitelistDeployKeys: bp.WhitelistDeployKeys,
|
|
|
|
EnableMergeWhitelist: bp.EnableMergeWhitelist,
|
|
|
|
MergeWhitelistUsernames: mergeWhitelistUsernames,
|
|
|
|
MergeWhitelistTeams: mergeWhitelistTeams,
|
|
|
|
EnableStatusCheck: bp.EnableStatusCheck,
|
|
|
|
StatusCheckContexts: bp.StatusCheckContexts,
|
|
|
|
RequiredApprovals: bp.RequiredApprovals,
|
|
|
|
EnableApprovalsWhitelist: bp.EnableApprovalsWhitelist,
|
|
|
|
ApprovalsWhitelistUsernames: approvalsWhitelistUsernames,
|
|
|
|
ApprovalsWhitelistTeams: approvalsWhitelistTeams,
|
|
|
|
BlockOnRejectedReviews: bp.BlockOnRejectedReviews,
|
|
|
|
BlockOnOfficialReviewRequests: bp.BlockOnOfficialReviewRequests,
|
|
|
|
BlockOnOutdatedBranch: bp.BlockOnOutdatedBranch,
|
|
|
|
DismissStaleApprovals: bp.DismissStaleApprovals,
|
|
|
|
RequireSignedCommits: bp.RequireSignedCommits,
|
|
|
|
ProtectedFilePatterns: bp.ProtectedFilePatterns,
|
2021-09-11 10:21:17 -04:00
|
|
|
UnprotectedFilePatterns: bp.UnprotectedFilePatterns,
|
2020-11-28 14:30:46 -05:00
|
|
|
Created: bp.CreatedUnix.AsTime(),
|
|
|
|
Updated: bp.UpdatedUnix.AsTime(),
|
2016-03-13 23:20:22 -04:00
|
|
|
}
|
2016-01-28 14:49:05 -05:00
|
|
|
}
|
|
|
|
|
2019-06-08 10:31:11 -04:00
|
|
|
// ToTag convert a git.Tag to an api.Tag
|
2021-12-09 20:27:50 -05:00
|
|
|
func ToTag(repo *repo_model.Repository, t *git.Tag) *api.Tag {
|
2019-02-07 07:00:52 -05:00
|
|
|
return &api.Tag{
|
2019-06-08 10:31:11 -04:00
|
|
|
Name: t.Name,
|
2021-06-17 12:04:10 -04:00
|
|
|
Message: strings.TrimSpace(t.Message),
|
2019-06-08 10:31:11 -04:00
|
|
|
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"),
|
2019-02-07 07:00:52 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-08 10:31:11 -04:00
|
|
|
// ToVerification convert a git.Commit.Signature to an api.PayloadCommitVerification
|
|
|
|
func ToVerification(c *git.Commit) *api.PayloadCommitVerification {
|
2021-12-10 03:14:24 -05:00
|
|
|
verif := asymkey_model.ParseCommitWithSignature(c)
|
2019-10-16 09:42:42 -04:00
|
|
|
commitVerification := &api.PayloadCommitVerification{
|
|
|
|
Verified: verif.Verified,
|
|
|
|
Reason: verif.Reason,
|
|
|
|
}
|
2019-06-08 10:31:11 -04:00
|
|
|
if c.Signature != nil {
|
2019-10-16 09:42:42 -04:00
|
|
|
commitVerification.Signature = c.Signature.Signature
|
|
|
|
commitVerification.Payload = c.Signature.Payload
|
2019-06-08 10:31:11 -04:00
|
|
|
}
|
2019-10-16 09:42:42 -04:00
|
|
|
if verif.SigningUser != nil {
|
2021-11-08 02:04:13 -05:00
|
|
|
commitVerification.Signer = &api.PayloadUser{
|
2019-10-16 09:42:42 -04:00
|
|
|
Name: verif.SigningUser.Name,
|
|
|
|
Email: verif.SigningUser.Email,
|
|
|
|
}
|
2016-01-28 14:49:05 -05:00
|
|
|
}
|
2019-10-16 09:42:42 -04:00
|
|
|
return commitVerification
|
2016-01-28 14:49:05 -05:00
|
|
|
}
|
|
|
|
|
2021-12-10 03:14:24 -05:00
|
|
|
// ToPublicKey convert asymkey_model.PublicKey to api.PublicKey
|
|
|
|
func ToPublicKey(apiLink string, key *asymkey_model.PublicKey) *api.PublicKey {
|
2015-12-04 17:16:42 -05:00
|
|
|
return &api.PublicKey{
|
2017-11-28 10:21:39 -05:00
|
|
|
ID: key.ID,
|
|
|
|
Key: key.Content,
|
2020-12-25 04:59:32 -05:00
|
|
|
URL: fmt.Sprintf("%s%d", apiLink, key.ID),
|
2017-11-28 10:21:39 -05:00
|
|
|
Title: key.Name,
|
|
|
|
Fingerprint: key.Fingerprint,
|
2017-12-10 23:37:04 -05:00
|
|
|
Created: key.CreatedUnix.AsTime(),
|
2015-12-04 17:16:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-15 21:27:35 -04:00
|
|
|
// ToGPGKey converts models.GPGKey to api.GPGKey
|
2021-12-10 03:14:24 -05:00
|
|
|
func ToGPGKey(key *asymkey_model.GPGKey) *api.GPGKey {
|
2017-03-15 21:27:35 -04:00
|
|
|
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,
|
2017-12-10 23:37:04 -05:00
|
|
|
Created: k.CreatedUnix.AsTime(),
|
|
|
|
Expires: k.ExpiredUnix.AsTime(),
|
2017-03-15 21:27:35 -04:00
|
|
|
CanSign: k.CanSign,
|
|
|
|
CanEncryptComms: k.CanEncryptComms,
|
|
|
|
CanEncryptStorage: k.CanEncryptStorage,
|
|
|
|
CanCertify: k.CanSign,
|
2021-07-13 09:28:07 -04:00
|
|
|
Verified: k.Verified,
|
2017-03-15 21:27:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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,
|
2017-12-10 23:37:04 -05:00
|
|
|
Created: key.CreatedUnix.AsTime(),
|
|
|
|
Expires: key.ExpiredUnix.AsTime(),
|
2017-03-15 21:27:35 -04:00
|
|
|
Emails: emails,
|
|
|
|
SubsKey: subkeys,
|
|
|
|
CanSign: key.CanSign,
|
|
|
|
CanEncryptComms: key.CanEncryptComms,
|
|
|
|
CanEncryptStorage: key.CanEncryptStorage,
|
|
|
|
CanCertify: key.CanSign,
|
2021-07-13 09:28:07 -04:00
|
|
|
Verified: key.Verified,
|
2017-03-15 21:27:35 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// ToGPGKeyEmail convert models.EmailAddress to api.GPGKeyEmail
|
2021-11-11 02:03:30 -05:00
|
|
|
func ToGPGKeyEmail(email *user_model.EmailAddress) *api.GPGKeyEmail {
|
2017-03-15 21:27:35 -04:00
|
|
|
return &api.GPGKeyEmail{
|
|
|
|
Email: email.Email,
|
|
|
|
Verified: email.IsActivated,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 02:04:31 -05:00
|
|
|
// ToHook convert models.Webhook to api.Hook
|
2021-11-10 00:13:16 -05:00
|
|
|
func ToHook(repoLink string, w *webhook.Webhook) *api.Hook {
|
2015-12-04 17:16:42 -05:00
|
|
|
config := map[string]string{
|
|
|
|
"url": w.URL,
|
|
|
|
"content_type": w.ContentType.Name(),
|
|
|
|
}
|
2021-11-10 00:13:16 -05:00
|
|
|
if w.Type == webhook.SLACK {
|
|
|
|
s := webhook_service.GetSlackHook(w)
|
2015-12-04 17:16:42 -05:00
|
|
|
config["channel"] = s.Channel
|
|
|
|
config["username"] = s.Username
|
|
|
|
config["icon_url"] = s.IconURL
|
|
|
|
config["color"] = s.Color
|
|
|
|
}
|
|
|
|
|
|
|
|
return &api.Hook{
|
|
|
|
ID: w.ID,
|
2020-12-09 12:20:13 -05:00
|
|
|
Type: string(w.Type),
|
2015-12-04 17:16:42 -05:00
|
|
|
URL: fmt.Sprintf("%s/settings/hooks/%d", repoLink, w.ID),
|
|
|
|
Active: w.IsActive,
|
|
|
|
Config: config,
|
|
|
|
Events: w.EventsArray(),
|
2017-12-10 23:37:04 -05:00
|
|
|
Updated: w.UpdatedUnix.AsTime(),
|
|
|
|
Created: w.CreatedUnix.AsTime(),
|
2015-12-04 17:16:42 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-04-17 01:31:08 -04:00
|
|
|
// 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,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-10 03:14:24 -05:00
|
|
|
// ToDeployKey convert asymkey_model.DeployKey to api.DeployKey
|
|
|
|
func ToDeployKey(apiLink string, key *asymkey_model.DeployKey) *api.DeployKey {
|
2015-12-04 17:16:42 -05:00
|
|
|
return &api.DeployKey{
|
2018-10-31 23:40:49 -04:00
|
|
|
ID: key.ID,
|
|
|
|
KeyID: key.KeyID,
|
|
|
|
Key: key.Content,
|
|
|
|
Fingerprint: key.Fingerprint,
|
2020-12-25 04:59:32 -05:00
|
|
|
URL: fmt.Sprintf("%s%d", apiLink, key.ID),
|
2018-10-31 23:40:49 -04:00
|
|
|
Title: key.Name,
|
|
|
|
Created: key.CreatedUnix.AsTime(),
|
2021-11-28 06:58:28 -05:00
|
|
|
ReadOnly: key.Mode == perm.AccessModeRead, // All deploy keys are read-only.
|
2015-12-04 17:16:42 -05:00
|
|
|
}
|
|
|
|
}
|
2015-12-17 02:28:47 -05:00
|
|
|
|
2021-11-24 04:49:20 -05:00
|
|
|
// ToOrganization convert user_model.User to api.Organization
|
2021-11-19 06:41:40 -05:00
|
|
|
func ToOrganization(org *models.Organization) *api.Organization {
|
2015-12-17 02:28:47 -05:00
|
|
|
return &api.Organization{
|
2019-09-23 16:08:03 -04:00
|
|
|
ID: org.ID,
|
2021-11-19 06:41:40 -05:00
|
|
|
AvatarURL: org.AsUser().AvatarLink(),
|
2019-09-23 16:08:03 -04:00
|
|
|
UserName: org.Name,
|
|
|
|
FullName: org.FullName,
|
|
|
|
Description: org.Description,
|
|
|
|
Website: org.Website,
|
|
|
|
Location: org.Location,
|
|
|
|
Visibility: org.Visibility.String(),
|
|
|
|
RepoAdminChangeTeamAccess: org.RepoAdminChangeTeamAccess,
|
2015-12-17 02:28:47 -05:00
|
|
|
}
|
|
|
|
}
|
2016-03-21 12:47:54 -04:00
|
|
|
|
2016-11-24 02:04:31 -05:00
|
|
|
// ToTeam convert models.Team to api.Team
|
2016-03-21 12:47:54 -04:00
|
|
|
func ToTeam(team *models.Team) *api.Team {
|
2020-10-20 14:18:25 -04:00
|
|
|
if team == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2016-03-21 12:47:54 -04:00
|
|
|
return &api.Team{
|
2019-11-06 04:37:14 -05:00
|
|
|
ID: team.ID,
|
|
|
|
Name: team.Name,
|
|
|
|
Description: team.Description,
|
|
|
|
IncludesAllRepositories: team.IncludesAllRepositories,
|
2019-11-20 06:27:49 -05:00
|
|
|
CanCreateOrgRepo: team.CanCreateOrgRepo,
|
2019-11-06 04:37:14 -05:00
|
|
|
Permission: team.Authorize.String(),
|
|
|
|
Units: team.GetUnitNames(),
|
2016-03-21 12:47:54 -04:00
|
|
|
}
|
|
|
|
}
|
2019-04-15 12:36:59 -04:00
|
|
|
|
2019-06-08 10:31:11 -04:00
|
|
|
// ToAnnotatedTag convert git.Tag to api.AnnotatedTag
|
2021-12-09 20:27:50 -05:00
|
|
|
func ToAnnotatedTag(repo *repo_model.Repository, t *git.Tag, c *git.Commit) *api.AnnotatedTag {
|
2019-06-08 10:31:11 -04:00
|
|
|
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
|
2021-12-09 20:27:50 -05:00
|
|
|
func ToAnnotatedTagObject(repo *repo_model.Repository, commit *git.Commit) *api.AnnotatedTagObject {
|
2019-06-08 10:31:11 -04:00
|
|
|
return &api.AnnotatedTagObject{
|
|
|
|
SHA: commit.ID.String(),
|
|
|
|
Type: string(git.ObjectCommit),
|
|
|
|
URL: util.URLJoin(repo.APIURL(), "git/commits", commit.ID.String()),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-03 11:46:24 -04:00
|
|
|
// 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(),
|
|
|
|
}
|
|
|
|
}
|
2020-02-29 01:19:32 -05:00
|
|
|
|
2021-09-24 07:32:56 -04:00
|
|
|
// ToOAuth2Application convert from login.OAuth2Application to api.OAuth2Application
|
|
|
|
func ToOAuth2Application(app *login.OAuth2Application) *api.OAuth2Application {
|
2020-02-29 01:19:32 -05:00
|
|
|
return &api.OAuth2Application{
|
|
|
|
ID: app.ID,
|
|
|
|
Name: app.Name,
|
|
|
|
ClientID: app.ClientID,
|
|
|
|
ClientSecret: app.ClientSecret,
|
|
|
|
RedirectURIs: app.RedirectURIs,
|
|
|
|
Created: app.CreatedUnix.AsTime(),
|
|
|
|
}
|
|
|
|
}
|
2020-10-17 00:23:08 -04:00
|
|
|
|
2020-12-03 09:05:48 -05:00
|
|
|
// ToLFSLock convert a LFSLock to api.LFSLock
|
|
|
|
func ToLFSLock(l *models.LFSLock) *api.LFSLock {
|
2021-11-24 04:49:20 -05:00
|
|
|
u, err := user_model.GetUserByID(l.OwnerID)
|
|
|
|
if err != nil {
|
|
|
|
return nil
|
|
|
|
}
|
2020-12-03 09:05:48 -05:00
|
|
|
return &api.LFSLock{
|
|
|
|
ID: strconv.FormatInt(l.ID, 10),
|
|
|
|
Path: l.Path,
|
|
|
|
LockedAt: l.Created.Round(time.Second),
|
|
|
|
Owner: &api.LFSLockOwner{
|
2021-11-24 04:49:20 -05:00
|
|
|
Name: u.DisplayName(),
|
2020-12-03 09:05:48 -05:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|