Fix missing repository id when migrating release attachments (#36389)

This PR fixes missed repo_id on the migration of attachments to Gitea.
It also provides a doctor check to fix the dirty data on the database.
This commit is contained in:
Lunny Xiao
2026-01-20 10:05:51 -08:00
committed by GitHub
parent 987d82b038
commit f6db180a80
9 changed files with 138 additions and 17 deletions
+8 -6
View File
@@ -16,25 +16,27 @@ import (
"github.com/stretchr/testify/require"
)
func TestAttachLinkedType(t *testing.T) {
func TestAttachLinkedTypeAndRepoID(t *testing.T) {
assert.NoError(t, unittest.PrepareTestDatabase())
testCases := []struct {
name string
attachID int64
expectedUnitType unit.Type
expectedRepoID int64
}{
{"LinkedIssue", 1, unit.TypeIssues},
{"LinkedComment", 3, unit.TypePullRequests},
{"LinkedRelease", 9, unit.TypeReleases},
{"Notlinked", 10, unit.TypeInvalid},
{"LinkedIssue", 1, unit.TypeIssues, 1},
{"LinkedComment", 3, unit.TypePullRequests, 1},
{"LinkedRelease", 9, unit.TypeReleases, 1},
{"Notlinked", 10, unit.TypeInvalid, 0},
}
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
attach, err := repo_model.GetAttachmentByID(t.Context(), tc.attachID)
assert.NoError(t, err)
unitType, err := GetAttachmentLinkedType(t.Context(), attach)
unitType, repoID, err := GetAttachmentLinkedTypeAndRepoID(t.Context(), attach)
assert.NoError(t, err)
assert.Equal(t, tc.expectedUnitType, unitType)
assert.Equal(t, tc.expectedRepoID, repoID)
})
}
}