From 89a321435259afa911900c0047f2766d255d315b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Peter=20Gardfj=C3=A4ll?= Date: Tue, 18 Jan 2022 14:18:30 +0100 Subject: [PATCH] Add MirrorUpdated field to Repository API type (#18267) Add the last update time to the repository api type. Close #18266 --- modules/convert/repository.go | 5 +++++ modules/structs/repo.go | 4 +++- templates/swagger/v1_json.tmpl | 5 +++++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/convert/repository.go b/modules/convert/repository.go index 725b04e2ca..459f98f396 100644 --- a/modules/convert/repository.go +++ b/modules/convert/repository.go @@ -5,6 +5,8 @@ package convert import ( + "time" + "code.gitea.io/gitea/models" "code.gitea.io/gitea/models/db" "code.gitea.io/gitea/models/perm" @@ -99,11 +101,13 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo numReleases, _ := models.GetReleaseCountByRepoID(repo.ID, models.FindReleasesOptions{IncludeDrafts: false, IncludeTags: false}) mirrorInterval := "" + var mirrorUpdated time.Time if repo.IsMirror { var err error repo.Mirror, err = repo_model.GetMirrorByRepoID(repo.ID) if err == nil { mirrorInterval = repo.Mirror.Interval.String() + mirrorUpdated = repo.Mirror.UpdatedUnix.AsTime() } } @@ -166,6 +170,7 @@ func innerToRepo(repo *repo_model.Repository, mode perm.AccessMode, isParent boo AvatarURL: repo.AvatarLink(), Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate, MirrorInterval: mirrorInterval, + MirrorUpdated: mirrorUpdated, RepoTransfer: transfer, } } diff --git a/modules/structs/repo.go b/modules/structs/repo.go index 852af1f891..680277ea60 100644 --- a/modules/structs/repo.go +++ b/modules/structs/repo.go @@ -93,7 +93,9 @@ type Repository struct { AvatarURL string `json:"avatar_url"` Internal bool `json:"internal"` MirrorInterval string `json:"mirror_interval"` - RepoTransfer *RepoTransfer `json:"repo_transfer"` + // swagger:strfmt date-time + MirrorUpdated time.Time `json:"mirror_updated,omitempty"` + RepoTransfer *RepoTransfer `json:"repo_transfer"` } // CreateRepoOption options when creating repository diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 7588261256..bba728363a 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -17195,6 +17195,11 @@ "type": "string", "x-go-name": "MirrorInterval" }, + "mirror_updated": { + "type": "string", + "format": "date-time", + "x-go-name": "MirrorUpdated" + }, "name": { "type": "string", "x-go-name": "Name"