refactor: clean up git migration forms (#39672)

Only extracted shared code, removed unnecessary code, and use
form-fetch-action to replace RenderWithErrDeprecated, slightly
refactored JS to use data-global-init

Nothing else is changed, although there are still many problems.

Written by AI

Diff with hiding spaces:
https://github.com/go-gitea/gitea/pull/39672/changes?w=1
This commit is contained in:
wxiaoguang authored and GitHub committed 2026-10-08 10:36:08 +02:00
1 parent 89ec271d9c
commit cc623c5f2f
18 files changed
+274 -724

No files matched your search

+2 -2
View File
@@ -94,9 +94,9 @@ func TestMigrateGiteaForm(t *testing.T) {
"description": "",
"uid": strconv.FormatInt(repoOwner.ID, 10),
})
resp = session.MakeRequest(t, req, http.StatusSeeOther)
resp = session.MakeRequest(t, req, http.StatusOK)
// Step 5: a redirection displays the migrated repository
loc := resp.Header().Get("Location")
loc := *test.ParseJSONRedirect(resp.Body.Bytes()).Redirect
assert.Equal(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), loc)
// Step 6: check the repo was created
unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName})
+5 -3
View File
@@ -10,6 +10,7 @@ import (
"testing"
"gitea.dev/modules/structs"
"gitea.dev/modules/test"
"gitea.dev/tests"
"github.com/stretchr/testify/assert"
@@ -23,7 +24,7 @@ func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName str
link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
assert.True(t, exists, "The template has changed")
uid, exists := htmlDoc.doc.Find("#uid").Attr("value")
uid, exists := htmlDoc.doc.Find(`input[name="uid"]`).Attr("value")
assert.True(t, exists, "The template has changed")
req = NewRequestWithValues(t, "POST", link, map[string]string{
@@ -32,7 +33,7 @@ func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName str
"repo_name": repoName,
"service": fmt.Sprintf("%d", structs.PlainGitService),
})
resp = session.MakeRequest(t, req, http.StatusSeeOther)
resp = session.MakeRequest(t, req, http.StatusOK)
return resp
}
@@ -40,5 +41,6 @@ func testRepoMigrate(t testing.TB, session *TestSession, cloneAddr, repoName str
func TestRepoMigrate(t *testing.T) {
defer tests.PrepareTestEnv(t)()
session := loginUser(t, "user2")
testRepoMigrate(t, session, "https://github.com/go-gitea/test_repo.git", "git")
resp := testRepoMigrate(t, session, "https://github.com/go-gitea/test_repo.git", "git")
assert.Equal(t, "/user2/git", *test.ParseJSONRedirect(resp.Body.Bytes()).Redirect)
}