From 7cc44491fae1e5f00616a5b8d8da2934a8a619f8 Mon Sep 17 00:00:00 2001 From: qwerty287 <80460567+qwerty287@users.noreply.github.com> Date: Fri, 24 Dec 2021 05:26:52 +0100 Subject: Add API to manage repo tranfers (#17963) --- modules/convert/repository.go | 30 ++++++++++++++++++++++++++++++ modules/structs/repo.go | 8 ++++++++ 2 files changed, 38 insertions(+) (limited to 'modules') diff --git a/modules/convert/repository.go b/modules/convert/repository.go index 9859ea2674..725b04e2ca 100644 --- a/modules/convert/repository.go +++ b/modules/convert/repository.go @@ -10,6 +10,7 @@ import ( "code.gitea.io/gitea/models/perm" repo_model "code.gitea.io/gitea/models/repo" unit_model "code.gitea.io/gitea/models/unit" + "code.gitea.io/gitea/modules/log" api "code.gitea.io/gitea/modules/structs" ) @@ -106,6 +107,20 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo } } + var transfer *api.RepoTransfer + if repo.Status == repo_model.RepositoryPendingTransfer { + t, err := models.GetPendingRepositoryTransfer(repo) + if err != nil && !models.IsErrNoPendingTransfer(err) { + log.Warn("GetPendingRepositoryTransfer: %v", err) + } else { + if err := t.LoadAttributes(); err != nil { + log.Warn("LoadAttributes of RepoTransfer: %v", err) + } else { + transfer = ToRepoTransfer(t) + } + } + } + return &api.Repository{ ID: repo.ID, Owner: ToUserWithAccessMode(repo.Owner, mode), @@ -151,5 +166,20 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo AvatarURL: repo.AvatarLink(), Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate, MirrorInterval: mirrorInterval, + RepoTransfer: transfer, + } +} + +// ToRepoTransfer convert a models.RepoTransfer to a structs.RepeTransfer +func ToRepoTransfer(t *models.RepoTransfer) *api.RepoTransfer { + var teams []*api.Team + for _, v := range t.Teams { + teams = append(teams, ToTeam(v)) + } + + return &api.RepoTransfer{ + Doer: ToUser(t.Doer, nil), + Recipient: ToUser(t.Recipient, nil), + Teams: teams, } } diff --git a/modules/structs/repo.go b/modules/structs/repo.go index b1a3781d05..38d80db704 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -93,6 +93,7 @@ type Repository struct { AvatarURL string `json:"avatar_url"` Internal bool `json:"internal"` MirrorInterval string `json:"mirror_interval"` + RepoTransfer *RepoTransfer `json:"repo_transfer"` } // CreateRepoOption options when creating repository @@ -336,3 +337,10 @@ var ( CodebaseService, } ) + +// RepoTransfer represents a pending repo transfer +type RepoTransfer struct { + Doer *User `json:"doer"` + Recipient *User `json:"recipient"` + Teams []*Team `json:"teams"` +} -- cgit v1.2.3