From 397474ecb19ddd7942df5432387e1221d35573c5 Mon Sep 17 00:00:00 2001 From: guyzmo Date: Fri, 12 May 2017 05:09:26 +0200 Subject: [PATCH] Added Parent property to the repo API (#1687) Signed-off-by: Guyzmo --- models/repo.go | 16 ++++++++++++++++ vendor/code.gitea.io/sdk/gitea/repo.go | 1 + vendor/vendor.json | 6 +++--- 3 files changed, 20 insertions(+), 3 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, diff --git a/vendor/code.gitea.io/sdk/gitea/repo.go b/vendor/code.gitea.io/sdk/gitea/repo.go index b2447618f6..7e997cd5d7 100644 --- a/vendor/code.gitea.io/sdk/gitea/repo.go +++ b/vendor/code.gitea.io/sdk/gitea/repo.go @@ -29,6 +29,7 @@ type Repository struct { Empty bool `json:"empty"` Private bool `json:"private"` Fork bool `json:"fork"` + Parent *Repository `json:"parent"` Mirror bool `json:"mirror"` Size int `json:"size"` HTMLURL string `json:"html_url"` diff --git a/vendor/vendor.json b/vendor/vendor.json index a28e71f3d3..93e8fa9d8b 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -9,10 +9,10 @@ "revisionTime": "2017-05-04T06:58:26Z" }, { - "checksumSHA1": "L58DGmGw5eZThPkaHEaY9vuz42g=", + "checksumSHA1": "nLhT+bLMj8uLICP+EZbrdoQe6mM=", "path": "code.gitea.io/sdk/gitea", - "revision": "1350cdb0d049083453c93dcabfcac2e7ba553951", - "revisionTime": "2017-05-04T17:35:58Z" + "revision": "8cff72208aa458f4efa8fdfbad29b03aee485b8c", + "revisionTime": "2017-05-06T01:37:21Z" }, { "checksumSHA1": "bOODD4Gbw3GfcuQPU2dI40crxxk=",