Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add last commit when for contents API #32921

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions modules/structs/repo_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"`
Expand Down
13 changes: 7 additions & 6 deletions services/repository/files/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
26 changes: 14 additions & 12 deletions services/repository/files/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package files

import (
"testing"
"time"

"code.gitea.io/gitea/models/unittest"
"code.gitea.io/gitea/modules/gitrepo"
Expand Down Expand Up @@ -42,18 +43,19 @@ func getExpectedFileResponse() *api.FileResponse {
downloadURL := setting.AppURL + "user2/repo1/raw/branch/master/" + treePath
return &api.FileResponse{
Content: &api.ContentsResponse{
Name: treePath,
Path: treePath,
SHA: sha,
LastCommitSHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
Type: "file",
Size: 30,
Encoding: &encoding,
Content: &content,
URL: &selfURL,
HTMLURL: &htmlURL,
GitURL: &gitURL,
DownloadURL: &downloadURL,
Name: treePath,
Path: treePath,
SHA: sha,
LastCommitSHA: "65f1bf27bc3bf70f64657658635e66094edbcb4d",
LastCommitWhen: time.Date(2017, 3, 19, 20, 47, 59, 0, time.UTC),
Type: "file",
Size: 30,
Encoding: &encoding,
Content: &content,
URL: &selfURL,
HTMLURL: &htmlURL,
GitURL: &gitURL,
DownloadURL: &downloadURL,
Links: &api.FileLinksResponse{
Self: &selfURL,
GitURL: &gitURL,
Expand Down
5 changes: 5 additions & 0 deletions templates/swagger/v1_json.tmpl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading