[API] Extend contents with dates (#9464)

* extend CommitTree func

* make sure Date NOT nil

* spell corection

Co-Authored-By: zeripath <art27@cantab.net>

* add TEST

Co-authored-by: zeripath <art27@cantab.net>
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
This commit is contained in:
6543 2019-12-24 03:33:52 +01:00 committed by Lunny Xiao
parent 017f314b5a
commit 40e99ea010
9 changed files with 114 additions and 7 deletions

View file

@ -8,6 +8,7 @@ package repo
import (
"encoding/base64"
"net/http"
"time"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/context"
@ -213,6 +214,16 @@ func CreateFile(ctx *context.APIContext, apiOpts api.CreateFileOptions) {
Name: apiOpts.Author.Name,
Email: apiOpts.Author.Email,
},
Dates: &repofiles.CommitDateOptions{
Author: apiOpts.Dates.Author,
Committer: apiOpts.Dates.Committer,
},
}
if opts.Dates.Author.IsZero() {
opts.Dates.Author = time.Now()
}
if opts.Dates.Committer.IsZero() {
opts.Dates.Committer = time.Now()
}
if opts.Message == "" {
@ -277,6 +288,16 @@ func UpdateFile(ctx *context.APIContext, apiOpts api.UpdateFileOptions) {
Name: apiOpts.Author.Name,
Email: apiOpts.Author.Email,
},
Dates: &repofiles.CommitDateOptions{
Author: apiOpts.Dates.Author,
Committer: apiOpts.Dates.Committer,
},
}
if opts.Dates.Author.IsZero() {
opts.Dates.Author = time.Now()
}
if opts.Dates.Committer.IsZero() {
opts.Dates.Committer = time.Now()
}
if opts.Message == "" {
@ -364,6 +385,16 @@ func DeleteFile(ctx *context.APIContext, apiOpts api.DeleteFileOptions) {
Name: apiOpts.Author.Name,
Email: apiOpts.Author.Email,
},
Dates: &repofiles.CommitDateOptions{
Author: apiOpts.Dates.Author,
Committer: apiOpts.Dates.Committer,
},
}
if opts.Dates.Author.IsZero() {
opts.Dates.Author = time.Now()
}
if opts.Dates.Committer.IsZero() {
opts.Dates.Committer = time.Now()
}
if opts.Message == "" {

View file

@ -118,6 +118,9 @@ type swaggerParameterBodies struct {
// in:body
DeleteFileOptions api.DeleteFileOptions
// in:body
CommitDateOptions api.CommitDateOptions
// in:body
RepoTopicOptions api.RepoTopicOptions
}