summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorqwerty287 <80460567+qwerty287@users.noreply.github.com>2021-12-24 05:26:52 +0100
committerGitHub <noreply@github.com>2021-12-23 23:26:52 -0500
commit7cc44491fae1e5f00616a5b8d8da2934a8a619f8 (patch)
tree076c8d2bb9d706ce77356378547bfeb4dc83a510 /modules
parent5754080eb9b13e3446443bc7c17cd53d160dfdf2 (diff)
downloadgitea-7cc44491fae1e5f00616a5b8d8da2934a8a619f8.tar.gz
gitea-7cc44491fae1e5f00616a5b8d8da2934a8a619f8.zip
Add API to manage repo tranfers (#17963)
Diffstat (limited to 'modules')
-rw-r--r--modules/convert/repository.go30
-rw-r--r--modules/structs/repo.go8
2 files changed, 38 insertions, 0 deletions
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"`
+}