loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[BRANDING] add Forgejo Git Service and migration UI

[FEAT] add Forgejo Git Service (squash) register a Forgejo factory

If the Forgejo factory for the Forgejo service is not registered,
newDownloader will fallback to a git service and not migrate issues
etc.

Refs: https://codeberg.org/forgejo/forgejo/issues/1678
(cherry picked from commit 51938cd1613c789c7176ca59592689c3bf055f45)

[FEAT] add Forgero Git Service

Signed-off-by: cassiozareck <cassiomilczareck@gmail.com>
(cherry picked from commit a878adfe628cf6dc367a17c3715fcd3499aa02b6)

Adding description and Forgejo SVG

(cherry picked from commit 13738c03804d019f28550e46a4ebc37dbe3a5cfc)

Undo reordering and tmpl redirection

(cherry picked from commit 9ae51c46f42acecac834371857e638098ebf6d27)
(cherry picked from commit 70fffdc61d06dd1d70b6a31496676a23d3d0c2fc)
(cherry picked from commit c0ebfa9da3db3e60d7b403a1bf8b8a19c32c5dc7)
(cherry picked from commit 9922c92787eccaba0021486ba0a3eb28583969e1)
(cherry picked from commit 00c0effbc74aedc7a4167a69c8a410ef324d576b)
(cherry picked from commit e4c9525b137205fa9ffdb4e0d7492bbbda9be6b5)
(cherry picked from commit 09d7b83211652d045975b0e3bb790856267d52a5)
(cherry picked from commit bbcd5975c91f6932f7f2ee07fbd63e84560ba96a)
(cherry picked from commit 55c70a0e18d33d8ac0da9ffb97f6d994ed88a319)
(cherry picked from commit 76596410c0dd0137cd497c9728c3e1d1c98f2430)
(cherry picked from commit 1308043931388bf6de691ad0f766861b77fb08a5)
(cherry picked from commit 919d6aedfed6abc8ec9def19f8deec2ee413252b)

[FEAT] add Forgero Git Service (squash) more tests

Previously only Gitea service was being tested under self-hosted migrations. Since Forgejo is also self-hosted and in fact use the same downloader/migrator we can add to this suite another test that will do the same, migrating the same repository under the same local instance but for the Forgejo service (represented by 9)

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/1709
Co-authored-by: zareck <cassiomilczareck@gmail.com>
Co-committed-by: zareck <cassiomilczareck@gmail.com>
(cherry picked from commit 40a4b8f1a8637f78cf2f48104f0b336377652df9)
(cherry picked from commit 3198b4a64240b7d4e8b33d8b858a12d046db38c9)
(cherry picked from commit 4edda1f3890eb1b5bb9b1eeec1214dbc11f8e343)
(cherry picked from commit 4d91b77d29fd4b20be12bf21c31447722ff6da40)
(cherry picked from commit afe85c52e3c1c165c171443e3ba79caef1560e0d)
(cherry picked from commit 5ea7df79adfba4a85c7ebbccfb7da15b48eef19c)
(cherry picked from commit a667182542abab8ebb29905fb38afe509682c220)
(cherry picked from commit a9bebb1e71b8a20bb19352357a5b71b9b84c0d21)
(cherry picked from commit 4831a89e460bb982a497b6f22613149840b13a9c)
(cherry picked from commit e02a74651f9813cc72c64e391a2fa6e3c282ce3f)
(cherry picked from commit 05dcef59aa4d05b040fe4ae24d73f9d9660e6ed2)
(cherry picked from commit c8bac187f983150150a2652724bab8f923be44e0)
(cherry picked from commit c87903a0cc75daeee8783d9774158711011d4382)

+120 -37
+5 -1
modules/structs/repo.go
··· 293 293 OneDevService // 6 onedev service 294 294 GitBucketService // 7 gitbucket service 295 295 CodebaseService // 8 codebase service 296 + ForgejoService // 9 forgejo service 296 297 ) 297 298 298 299 // Name represents the service type's name ··· 318 319 return "GitBucket" 319 320 case CodebaseService: 320 321 return "Codebase" 322 + case ForgejoService: 323 + return "Forgejo" 321 324 case PlainGitService: 322 325 return "Git" 323 326 } ··· 359 362 // TokenAuth represents whether a service type supports token-based auth 360 363 func (gt GitServiceType) TokenAuth() bool { 361 364 switch gt { 362 - case GithubService, GiteaService, GitlabService: 365 + case GithubService, GiteaService, GitlabService, ForgejoService: 363 366 return true 364 367 } 365 368 return false ··· 370 373 var SupportedFullGitService = []GitServiceType{ 371 374 GithubService, 372 375 GitlabService, 376 + ForgejoService, 373 377 GiteaService, 374 378 GogsService, 375 379 OneDevService,
+9
public/assets/img/svg/gitea-forgejo.svg
··· 1 + <svg width="32" height="32" viewBox="-15 0 256 256" xmlns="http://www.w3.org/2000/svg"> 2 + <g transform="translate(28,28)"> 3 + <path d="M58 168 v-98 a50 50 0 0 1 50-50 h20" fill="none" stroke="#ff6600" stroke-width="25" /> 4 + <path d="M58 168 v-30 a50 50 0 0 1 50-50 h20" fill="none" stroke="#d40000" stroke-width="25" /> 5 + <circle cx="142" cy="20" r="18" fill="none" stroke="#ff6600" stroke-width="15" /> 6 + <circle cx="142" cy="88" r="18" fill="none" stroke="#d40000" stroke-width="15" /> 7 + <circle cx="58" cy="180" r="18" fill="none" stroke="#d40000" stroke-width="15" /> 8 + </g> 9 + </svg>
+2
services/convert/utils.go
··· 36 36 return structs.OneDevService 37 37 case "gitbucket": 38 38 return structs.GitBucketService 39 + case "forgejo": 40 + return structs.ForgejoService 39 41 default: 40 42 return structs.PlainGitService 41 43 }
+2
services/convert/utils_test.go
··· 29 29 }, { 30 30 typ: "gogs", enum: 5, 31 31 }, { 32 + typ: "forgejo", enum: 9, 33 + }, { 32 34 typ: "trash", enum: 1, 33 35 }} 34 36 for _, test := range tc {
+20
services/migrations/forgejo_downloader.go
··· 1 + // Copyright 2023 The Forgejo Authors 2 + // SPDX-License-Identifier: MIT 3 + 4 + package migrations 5 + 6 + import ( 7 + "code.gitea.io/gitea/modules/structs" 8 + ) 9 + 10 + func init() { 11 + RegisterDownloaderFactory(&ForgejoDownloaderFactory{}) 12 + } 13 + 14 + type ForgejoDownloaderFactory struct { 15 + GiteaDownloaderFactory 16 + } 17 + 18 + func (f *ForgejoDownloaderFactory) GitServiceType() structs.GitServiceType { 19 + return structs.ForgejoService 20 + }
+16
services/migrations/forgejo_downloader_test.go
··· 1 + // Copyright 2023 The Forgejo Authors 2 + // SPDX-License-Identifier: MIT 3 + 4 + package migrations 5 + 6 + import ( 7 + "testing" 8 + 9 + "code.gitea.io/gitea/modules/structs" 10 + 11 + "github.com/stretchr/testify/require" 12 + ) 13 + 14 + func TestForgejoDownload(t *testing.T) { 15 + require.NotNil(t, getFactoryFromServiceType(structs.ForgejoService)) 16 + }
+14 -7
services/migrations/migrate.go
··· 20 20 "code.gitea.io/gitea/modules/log" 21 21 base "code.gitea.io/gitea/modules/migration" 22 22 "code.gitea.io/gitea/modules/setting" 23 + "code.gitea.io/gitea/modules/structs" 23 24 "code.gitea.io/gitea/modules/util" 24 25 ) 25 26 ··· 139 140 return uploader.repo, nil 140 141 } 141 142 143 + func getFactoryFromServiceType(serviceType structs.GitServiceType) base.DownloaderFactory { 144 + for _, factory := range factories { 145 + if factory.GitServiceType() == serviceType { 146 + return factory 147 + } 148 + } 149 + return nil 150 + } 151 + 142 152 func newDownloader(ctx context.Context, ownerName string, opts base.MigrateOptions) (base.Downloader, error) { 143 153 var ( 144 154 downloader base.Downloader 145 155 err error 146 156 ) 147 157 148 - for _, factory := range factories { 149 - if factory.GitServiceType() == opts.GitServiceType { 150 - downloader, err = factory.New(ctx, opts) 151 - if err != nil { 152 - return nil, err 153 - } 154 - break 158 + if factory := getFactoryFromServiceType(opts.GitServiceType); factory != nil { 159 + downloader, err = factory.New(ctx, opts) 160 + if err != nil { 161 + return nil, err 155 162 } 156 163 } 157 164
+1
templates/repo/migrate/forgejo.tmpl
··· 1 + {{template "repo/migrate/gitea" .}}
+42 -29
tests/integration/migrate_test.go
··· 4 4 package integration 5 5 6 6 import ( 7 + "context" 7 8 "fmt" 8 9 "net/http" 9 10 "net/url" ··· 20 21 "code.gitea.io/gitea/modules/setting" 21 22 "code.gitea.io/gitea/modules/structs" 22 23 "code.gitea.io/gitea/services/migrations" 24 + "code.gitea.io/gitea/services/repository" 23 25 24 26 "github.com/stretchr/testify/assert" 25 27 ) ··· 51 53 setting.ImportLocalPaths = old 52 54 } 53 55 54 - func TestMigrateGiteaForm(t *testing.T) { 56 + func TestMigrate(t *testing.T) { 55 57 onGiteaRun(t, func(t *testing.T, u *url.URL) { 56 58 AllowLocalNetworks := setting.Migrations.AllowLocalNetworks 57 59 setting.Migrations.AllowLocalNetworks = true ··· 71 73 session := loginUser(t, ownerName) 72 74 token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository, auth_model.AccessTokenScopeReadMisc) 73 75 74 - // Step 0: verify the repo is available 75 - req := NewRequestf(t, "GET", fmt.Sprintf("/%s/%s", ownerName, repoName)) 76 - _ = session.MakeRequest(t, req, http.StatusOK) 77 - // Step 1: get the Gitea migration form 78 - req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", structs.GiteaService) 79 - resp := session.MakeRequest(t, req, http.StatusOK) 80 - // Step 2: load the form 81 - htmlDoc := NewHTMLParser(t, resp.Body) 82 - link, exists := htmlDoc.doc.Find(`form.ui.form[action^="/repo/migrate"]`).Attr("action") 83 - assert.True(t, exists, "The template has changed") 84 - // Step 4: submit the migration to only migrate issues 85 - migratedRepoName := "otherrepo" 86 - req = NewRequestWithValues(t, "POST", link, map[string]string{ 87 - "_csrf": htmlDoc.GetCSRF(), 88 - "service": fmt.Sprintf("%d", structs.GiteaService), 89 - "clone_addr": fmt.Sprintf("%s%s/%s", u, ownerName, repoName), 90 - "auth_token": token, 91 - "issues": "on", 92 - "repo_name": migratedRepoName, 93 - "description": "", 94 - "uid": fmt.Sprintf("%d", repoOwner.ID), 95 - }) 96 - resp = session.MakeRequest(t, req, http.StatusSeeOther) 97 - // Step 5: a redirection displays the migrated repository 98 - loc := resp.Header().Get("Location") 99 - assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), loc) 100 - // Step 6: check the repo was created 101 - unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName}) 76 + for _, s := range []struct { 77 + svc structs.GitServiceType 78 + }{ 79 + {svc: structs.GiteaService}, 80 + {svc: structs.ForgejoService}, 81 + } { 82 + // Step 0: verify the repo is available 83 + req := NewRequestf(t, "GET", fmt.Sprintf("/%s/%s", ownerName, repoName)) 84 + _ = session.MakeRequest(t, req, http.StatusOK) 85 + // Step 1: get the Gitea migration form 86 + req = NewRequestf(t, "GET", "/repo/migrate/?service_type=%d", s.svc) 87 + resp := session.MakeRequest(t, req, http.StatusOK) 88 + // Step 2: load the form 89 + htmlDoc := NewHTMLParser(t, resp.Body) 90 + link, exists := htmlDoc.doc.Find(`form.ui.form[action^="/repo/migrate"]`).Attr("action") 91 + assert.True(t, exists, "The template has changed") 92 + // Step 4: submit the migration to only migrate issues 93 + migratedRepoName := "otherrepo" 94 + req = NewRequestWithValues(t, "POST", link, map[string]string{ 95 + "_csrf": htmlDoc.GetCSRF(), 96 + "service": fmt.Sprintf("%d", s.svc), 97 + "clone_addr": fmt.Sprintf("%s%s/%s", u, ownerName, repoName), 98 + "auth_token": token, 99 + "issues": "on", 100 + "repo_name": migratedRepoName, 101 + "description": "", 102 + "uid": fmt.Sprintf("%d", repoOwner.ID), 103 + }) 104 + resp = session.MakeRequest(t, req, http.StatusSeeOther) 105 + // Step 5: a redirection displays the migrated repository 106 + loc := resp.Header().Get("Location") 107 + assert.EqualValues(t, fmt.Sprintf("/%s/%s", ownerName, migratedRepoName), loc) 108 + // Step 6: check the repo was created 109 + repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: migratedRepoName}) 110 + 111 + // Step 7: delete the repository, so we can test with other services 112 + err := repository.DeleteRepository(context.Background(), repoOwner, repo, false) 113 + assert.NoError(t, err) 114 + } 102 115 }) 103 116 } 104 117
+9
web_src/svg/gitea-forgejo.svg
··· 1 + <svg width="64" height="64" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg" class="forgejo-logo" aria-hidden="true"> 2 + <g transform="translate(28,28)"> 3 + <path d="M58 168 v-98 a50 50 0 0 1 50-50 h20" fill="none" stroke="#ff6600" stroke-width="25" /> 4 + <path d="M58 168 v-30 a50 50 0 0 1 50-50 h20" fill="none" stroke="#d40000" stroke-width="25" /> 5 + <circle cx="142" cy="20" r="18" fill="none" stroke="#ff6600" stroke-width="15" /> 6 + <circle cx="142" cy="88" r="18" fill="none" stroke="#d40000" stroke-width="15" /> 7 + <circle cx="58" cy="180" r="18" fill="none" stroke="#d40000" stroke-width="15" /> 8 + </g> 9 + </svg>