[GITEA] Allow changing the repo Wiki branch to main
Previously, the repo wiki was hardcoded to use `master` as its branch, this change makes it possible to use `main` (or something else, governed by `[repository].DEFAULT_BRANCH`, a setting that already exists and defaults to `main`). The way it is done is that a new column is added to the `repository` table: `wiki_branch`. The migration will make existing repositories default to `master`, for compatibility's sake, even if they don't have a Wiki (because it's easier to do that). Newly created repositories will default to `[repository].DEFAULT_BRANCH` instead. The Wiki service was updated to use the branch name stored in the database, and fall back to the default if it is empty. Old repositories with Wikis using the older `master` branch will have the option to do a one-time transition to `main`, available via the repository settings in the "Danger Zone". This option will only be available for repositories that have the internal wiki enabled, it is not empty, and the wiki branch is not `[repository].DEFAULT_BRANCH`. When migrating a repository with a Wiki, Forgejo will use the same branch name for the wiki as the source repository did. If that's not the same as the default, the option to normalize it will be available after the migration's done. Additionally, the `/api/v1/{owner}/{repo}` endpoint was updated: it will now include the wiki branch name in `GET` requests, and allow changing the wiki branch via `PATCH`. Signed-off-by: Gergely Nagy <forgejo@gergo.csillger.hu> (cherry picked from commit d87c526d2a313fa45093ab49b78bb30322b33298)
This commit is contained in:
parent
361617eea0
commit
2ca4862f8b
19 changed files with 364 additions and 24 deletions
|
@ -48,6 +48,8 @@ var migrations = []*Migration{
|
|||
NewMigration("Add default_permissions to repo_unit", forgejo_v1_22.AddDefaultPermissionsToRepoUnit),
|
||||
// v4 -> v5
|
||||
NewMigration("create the forgejo_repo_flag table", forgejo_v1_22.CreateRepoFlagTable),
|
||||
// v5 -> v6
|
||||
NewMigration("Add wiki_branch to repository", forgejo_v1_22.AddWikiBranchToRepository),
|
||||
}
|
||||
|
||||
// GetCurrentDBVersion returns the current Forgejo database version.
|
||||
|
|
24
models/forgejo_migrations/v1_22/v6.go
Normal file
24
models/forgejo_migrations/v1_22/v6.go
Normal file
|
@ -0,0 +1,24 @@
|
|||
// Copyright 2024 The Forgejo Authors c/o Codeberg e.V.. All rights reserved.
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
package v1_22 //nolint
|
||||
|
||||
import (
|
||||
"xorm.io/xorm"
|
||||
)
|
||||
|
||||
func AddWikiBranchToRepository(x *xorm.Engine) error {
|
||||
type Repository struct {
|
||||
ID int64
|
||||
WikiBranch string
|
||||
}
|
||||
|
||||
if err := x.Sync(&Repository{}); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Update existing repositories to use `master` as the wiki branch, for
|
||||
// compatilibty's sake.
|
||||
_, err := x.Exec("UPDATE repository SET wiki_branch = 'master' WHERE wiki_branch = '' OR wiki_branch IS NULL")
|
||||
return err
|
||||
}
|
|
@ -135,6 +135,7 @@ type Repository struct {
|
|||
OriginalServiceType api.GitServiceType `xorm:"index"`
|
||||
OriginalURL string `xorm:"VARCHAR(2048)"`
|
||||
DefaultBranch string
|
||||
WikiBranch string
|
||||
|
||||
NumWatches int
|
||||
NumStars int
|
||||
|
@ -204,6 +205,13 @@ func (repo *Repository) GetOwnerName() string {
|
|||
return repo.OwnerName
|
||||
}
|
||||
|
||||
func (repo *Repository) GetWikiBranchName() string {
|
||||
if repo.WikiBranch == "" {
|
||||
return setting.Repository.DefaultBranch
|
||||
}
|
||||
return repo.WikiBranch
|
||||
}
|
||||
|
||||
// SanitizedOriginalURL returns a sanitized OriginalURL
|
||||
func (repo *Repository) SanitizedOriginalURL() string {
|
||||
if repo.OriginalURL == "" {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue