diff options
author | guyzmo <guyzmo+github+pub@m0g.net> | 2017-05-12 05:09:26 +0200 |
---|---|---|
committer | Bo-Yi Wu <appleboy.tw@gmail.com> | 2017-05-12 11:09:26 +0800 |
commit | 397474ecb19ddd7942df5432387e1221d35573c5 (patch) | |
tree | 8e272602586ede65c332c9f1a663db601bba358e /models | |
parent | 251fb935ff39520482a5436b19bc04352ea25db7 (diff) | |
download | gitea-397474ecb19ddd7942df5432387e1221d35573c5.tar.gz gitea-397474ecb19ddd7942df5432387e1221d35573c5.zip |
Added Parent property to the repo API (#1687)
Signed-off-by: Guyzmo <guyzmo+github+pub@m0g.net>
Diffstat (limited to 'models')
-rw-r--r-- | models/repo.go | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/models/repo.go b/models/repo.go index d29df1b24e..c8f7d949a7 100644 --- a/models/repo.go +++ b/models/repo.go @@ -272,12 +272,27 @@ func (repo *Repository) APIURL() string { // APIFormat converts a Repository to api.Repository func (repo *Repository) APIFormat(mode AccessMode) *api.Repository { + return repo.innerAPIFormat(mode, false) +} + +func (repo *Repository) innerAPIFormat(mode AccessMode, isParent bool) *api.Repository { + var parent *api.Repository + cloneLink := repo.CloneLink() permission := &api.Permission{ Admin: mode >= AccessModeAdmin, Push: mode >= AccessModeWrite, Pull: mode >= AccessModeRead, } + if !isParent { + err := repo.GetBaseRepo() + if err != nil { + log.Error(4, "APIFormat: %v", err) + } + if repo.BaseRepo != nil { + parent = repo.BaseRepo.innerAPIFormat(mode, true) + } + } return &api.Repository{ ID: repo.ID, Owner: repo.Owner.APIFormat(), @@ -288,6 +303,7 @@ func (repo *Repository) APIFormat(mode AccessMode) *api.Repository { Empty: repo.IsBare, Size: int(repo.Size/1024), Fork: repo.IsFork, + Parent: parent, Mirror: repo.IsMirror, HTMLURL: repo.HTMLURL(), SSHURL: cloneLink.SSH, |