From 6f5bc5923e926d61d97e65d7b29fb3fc8c37c00f Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Thu, 19 Dec 2024 15:53:34 -0800 Subject: [PATCH] Add last commit when for contents API --- modules/structs/repo_file.go | 4 ++++ services/repository/files/content.go | 13 +++++++------ templates/swagger/v1_json.tmpl | 5 +++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/modules/structs/repo_file.go b/modules/structs/repo_file.go index 82bde96ab6..5c9b5c54df 100644 --- a/modules/structs/repo_file.go +++ b/modules/structs/repo_file.go @@ -4,6 +4,8 @@ package structs +import "time" + // FileOptions options for all file APIs type FileOptions struct { // message (optional) for the commit of this file. if not supplied, a default message will be used @@ -121,6 +123,8 @@ type ContentsResponse struct { Path string `json:"path"` SHA string `json:"sha"` LastCommitSHA string `json:"last_commit_sha"` + // swagger:strfmt date-time + LastCommitWhen time.Time `json:"last_commit_when"` // `type` will be `file`, `dir`, `symlink`, or `submodule` Type string `json:"type"` Size int64 `json:"size"` diff --git a/services/repository/files/content.go b/services/repository/files/content.go index 95e7c7087c..fa639a25b6 100644 --- a/services/repository/files/content.go +++ b/services/repository/files/content.go @@ -178,12 +178,13 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref // All content types have these fields in populated contentsResponse := &api.ContentsResponse{ - Name: entry.Name(), - Path: treePath, - SHA: entry.ID.String(), - LastCommitSHA: lastCommit.ID.String(), - Size: entry.Size(), - URL: &selfURLString, + Name: entry.Name(), + Path: treePath, + SHA: entry.ID.String(), + LastCommitSHA: lastCommit.ID.String(), + LastCommitWhen: lastCommit.Committer.When, + Size: entry.Size(), + URL: &selfURLString, Links: &api.FileLinksResponse{ Self: &selfURLString, }, diff --git a/templates/swagger/v1_json.tmpl b/templates/swagger/v1_json.tmpl index 82a301da2f..d023efc8e1 100644 --- a/templates/swagger/v1_json.tmpl +++ b/templates/swagger/v1_json.tmpl @@ -19515,6 +19515,11 @@ "type": "string", "x-go-name": "LastCommitSHA" }, + "last_commit_when": { + "type": "string", + "format": "date-time", + "x-go-name": "LastCommitWhen" + }, "name": { "type": "string", "x-go-name": "Name"