mirror of
https://github.com/go-gitea/gitea.git
synced 2026-08-26 06:43:25 +00:00
fix(release): separate publication time from the release date (#36761)
`published_at` was an alias for `created_at`, so a release created from an existing tag reported that tag's commit date as its publication time, and drafts reported one despite never having been published. It is now stored separately, set when a release is published and null for drafts. `created_at` in turn means the date of the commit the release points at, matching what GitHub documents it to be, and the latest release is selected by it again. Publishing a release for an old commit no longer takes over the latest badge, and a tag created in the web UI is dated the same way as one pushed from the CLI. Fixes https://github.com/go-gitea/gitea/issues/11206 Fixes https://github.com/go-gitea/gitea/issues/38714 Fixes https://github.com/go-gitea/gitea/issues/31789 --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -423,6 +423,7 @@ func prepareMigrationTasks() []*migration {
|
||||
newMigration(347, "Add watch options", v28.AddWatchOptions),
|
||||
newMigration(348, "Recreate email_hash table for SHA256 avatar hashes", v28.RecreateEmailHashTable),
|
||||
newMigration(349, "Expand action_schedule content column", v28.ExpandActionScheduleContent),
|
||||
newMigration(350, "Add published_unix column to release", v28.AddPublishedUnixToRelease),
|
||||
}
|
||||
return preparedMigrations
|
||||
}
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v28
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"gitea.dev/modelmigration/base"
|
||||
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddPublishedUnixToRelease(_ context.Context, x base.EngineMigration) error {
|
||||
type Release struct {
|
||||
PublishedUnix int64 `xorm:"NOT NULL DEFAULT 0"`
|
||||
}
|
||||
if _, err := x.SyncWithOptions(xorm.SyncOptions{
|
||||
IgnoreConstrains: true,
|
||||
IgnoreDropIndices: true,
|
||||
}, new(Release)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// existing rows have no recorded publication time, so fall back to their creation time
|
||||
_, err := x.Exec("UPDATE `release` SET published_unix = created_unix WHERE published_unix = 0 AND is_draft = ?", false)
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
// Copyright 2026 The Gitea Authors. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v28
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"gitea.dev/modelmigration/migrationtest"
|
||||
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestAddPublishedUnixToRelease(t *testing.T) {
|
||||
type Release struct {
|
||||
ID int64 `xorm:"pk autoincr"`
|
||||
IsDraft bool `xorm:"NOT NULL DEFAULT false"`
|
||||
IsTag bool `xorm:"NOT NULL DEFAULT false"`
|
||||
CreatedUnix int64 `xorm:"INDEX"`
|
||||
}
|
||||
|
||||
x, deferable := migrationtest.PrepareTestEnv(t, 0, new(Release))
|
||||
defer deferable()
|
||||
if x == nil || t.Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
_, err := x.Insert(
|
||||
&Release{CreatedUnix: 1000000},
|
||||
&Release{IsDraft: true, CreatedUnix: 2000000},
|
||||
&Release{IsTag: true, CreatedUnix: 3000000},
|
||||
)
|
||||
require.NoError(t, err)
|
||||
|
||||
require.NoError(t, AddPublishedUnixToRelease(t.Context(), x))
|
||||
|
||||
var got []struct{ PublishedUnix int64 }
|
||||
require.NoError(t, x.Table("release").OrderBy("id").Find(&got))
|
||||
require.Equal(t, []int64{1000000, 0, 3000000}, []int64{got[0].PublishedUnix, got[1].PublishedUnix, got[2].PublishedUnix},
|
||||
"everything but drafts is backfilled")
|
||||
}
|
||||
Reference in New Issue
Block a user