From 30fda0f1aecbb45b0abc67e0fb9fdb806a52cb8c Mon Sep 17 00:00:00 2001 From: Thibault Meyer <0xbaadf00d@users.noreply.github.com> Date: Sat, 6 Aug 2016 19:02:15 +0200 Subject: [PATCH] Fix #3315: Release dont use tag creation date (#3374) * Fix #3315: Release dont use tag creation date * Simplify code and apply gofmt * remove useless block (ctx.Repo.GitRepo.GetTag) on EditReleasePost * apply gofmt on modified files --- models/release.go | 4 +++- routers/repo/release.go | 10 ++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/models/release.go b/models/release.go index b38c2f525..c79ff222e 100644 --- a/models/release.go +++ b/models/release.go @@ -39,7 +39,9 @@ type Release struct { } func (r *Release) BeforeInsert() { - r.CreatedUnix = time.Now().Unix() + if r.CreatedUnix == 0 { + r.CreatedUnix = time.Now().Unix() + } } func (r *Release) AfterSet(colName string, _ xorm.Cell) { diff --git a/routers/repo/release.go b/routers/repo/release.go index 672741c5b..efbe6c982 100644 --- a/routers/repo/release.go +++ b/routers/repo/release.go @@ -167,6 +167,15 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) { return } + var tagCreatedUnix int64 + tag, err := ctx.Repo.GitRepo.GetTag(form.TagName) + if err == nil { + commit, err := tag.Commit() + if err == nil { + tagCreatedUnix = commit.Author.When.Unix() + } + } + commit, err := ctx.Repo.GitRepo.GetBranchCommit(form.Target) if err != nil { ctx.Handle(500, "GetBranchCommit", err) @@ -190,6 +199,7 @@ func NewReleasePost(ctx *context.Context, form auth.NewReleaseForm) { Note: form.Content, IsDraft: len(form.Draft) > 0, IsPrerelease: form.Prerelease, + CreatedUnix: tagCreatedUnix, } if err = models.CreateRelease(ctx.Repo.GitRepo, rel); err != nil {