From 584f9f929c4a9418b9c9b2631b40b4d845c94151 Mon Sep 17 00:00:00 2001 From: kilimnik Date: Wed, 20 Sep 2023 19:29:34 +0200 Subject: [PATCH 1/3] Fix push mirror, wrong timestamp format --- modules/structs/mirror.go | 18 ++++++++++-------- services/convert/mirror.go | 4 ++-- templates/swagger/v1_json.tmpl | 2 ++ 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/modules/structs/mirror.go b/modules/structs/mirror.go index 55cd133a4fc7b..1eeff288a97b2 100644 --- a/modules/structs/mirror.go +++ b/modules/structs/mirror.go @@ -3,6 +3,8 @@ package structs +import "time" + // CreatePushMirrorOption represents need information to create a push mirror of a repository. type CreatePushMirrorOption struct { RemoteAddress string `json:"remote_address"` @@ -15,12 +17,12 @@ type CreatePushMirrorOption struct { // PushMirror represents information of a push mirror // swagger:model type PushMirror struct { - RepoName string `json:"repo_name"` - RemoteName string `json:"remote_name"` - RemoteAddress string `json:"remote_address"` - CreatedUnix string `json:"created"` - LastUpdateUnix string `json:"last_update"` - LastError string `json:"last_error"` - Interval string `json:"interval"` - SyncOnCommit bool `json:"sync_on_commit"` + RepoName string `json:"repo_name"` + RemoteName string `json:"remote_name"` + RemoteAddress string `json:"remote_address"` + CreatedUnix time.Time `json:"created"` + LastUpdateUnix time.Time `json:"last_update"` + LastError string `json:"last_error"` + Interval string `json:"interval"` + SyncOnCommit bool `json:"sync_on_commit"` } diff --git a/services/convert/mirror.go b/services/convert/mirror.go index 505110452616a..f72e418c98dc7 100644 --- a/services/convert/mirror.go +++ b/services/convert/mirror.go @@ -15,8 +15,8 @@ func ToPushMirror(pm *repo_model.PushMirror) (*api.PushMirror, error) { RepoName: repo.Name, RemoteName: pm.RemoteName, RemoteAddress: pm.RemoteAddress, - CreatedUnix: pm.CreatedUnix.FormatLong(), - LastUpdateUnix: pm.LastUpdateUnix.FormatLong(), + CreatedUnix: pm.CreatedUnix.AsTime(), + LastUpdateUnix: pm.LastUpdateUnix.AsTime(), LastError: pm.LastError, Interval: pm.Interval.String(), SyncOnCommit: pm.SyncOnCommit, diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 39c5a7fe117df..e409cc76e208f 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -21562,6 +21562,7 @@ "properties": { "created": { "type": "string", + "format": "date-time", "x-go-name": "CreatedUnix" }, "interval": { @@ -21574,6 +21575,7 @@ }, "last_update": { "type": "string", + "format": "date-time", "x-go-name": "LastUpdateUnix" }, "remote_address": { From e427793fe2f64a4e82ddf658d9ef734e735680f5 Mon Sep 17 00:00:00 2001 From: kilimnik Date: Thu, 21 Sep 2023 09:09:35 +0200 Subject: [PATCH 2/3] mirror struct add swagger documentation --- modules/structs/mirror.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/modules/structs/mirror.go b/modules/structs/mirror.go index 1eeff288a97b2..74016e0cd2957 100644 --- a/modules/structs/mirror.go +++ b/modules/structs/mirror.go @@ -17,10 +17,12 @@ type CreatePushMirrorOption struct { // PushMirror represents information of a push mirror // swagger:model type PushMirror struct { - RepoName string `json:"repo_name"` - RemoteName string `json:"remote_name"` - RemoteAddress string `json:"remote_address"` - CreatedUnix time.Time `json:"created"` + RepoName string `json:"repo_name"` + RemoteName string `json:"remote_name"` + RemoteAddress string `json:"remote_address"` + // swagger:strfmt date-time + CreatedUnix time.Time `json:"created"` + // swagger:strfmt date-time LastUpdateUnix time.Time `json:"last_update"` LastError string `json:"last_error"` Interval string `json:"interval"` From db6812230cfac93d593d990e0bccf9d6522b0f14 Mon Sep 17 00:00:00 2001 From: kilimnik Date: Thu, 21 Sep 2023 09:20:58 +0200 Subject: [PATCH 3/3] mirror struct make LastUpdateUnix nullable --- modules/structs/mirror.go | 8 ++++---- services/convert/mirror.go | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/structs/mirror.go b/modules/structs/mirror.go index 74016e0cd2957..8259583cdeddc 100644 --- a/modules/structs/mirror.go +++ b/modules/structs/mirror.go @@ -23,8 +23,8 @@ type PushMirror struct { // swagger:strfmt date-time CreatedUnix time.Time `json:"created"` // swagger:strfmt date-time - LastUpdateUnix time.Time `json:"last_update"` - LastError string `json:"last_error"` - Interval string `json:"interval"` - SyncOnCommit bool `json:"sync_on_commit"` + LastUpdateUnix *time.Time `json:"last_update"` + LastError string `json:"last_error"` + Interval string `json:"interval"` + SyncOnCommit bool `json:"sync_on_commit"` } diff --git a/services/convert/mirror.go b/services/convert/mirror.go index f72e418c98dc7..dade6142a2e0a 100644 --- a/services/convert/mirror.go +++ b/services/convert/mirror.go @@ -16,7 +16,7 @@ func ToPushMirror(pm *repo_model.PushMirror) (*api.PushMirror, error) { RemoteName: pm.RemoteName, RemoteAddress: pm.RemoteAddress, CreatedUnix: pm.CreatedUnix.AsTime(), - LastUpdateUnix: pm.LastUpdateUnix.AsTime(), + LastUpdateUnix: pm.LastUpdateUnix.AsTimePtr(), LastError: pm.LastError, Interval: pm.Interval.String(), SyncOnCommit: pm.SyncOnCommit,