2014-02-20 02:45:43 +00:00
|
|
|
// Copyright 2014 The Gogs Authors. All rights reserved.
|
2020-01-22 23:46:46 +00:00
|
|
|
// Copyright 2020 The Gitea Authors. All rights reserved.
|
2022-11-27 18:20:29 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2014-02-20 02:45:43 +00:00
|
|
|
|
|
|
|
package repo
|
|
|
|
|
|
|
|
import (
|
2021-03-01 00:47:30 +00:00
|
|
|
"errors"
|
2014-07-26 06:28:04 +00:00
|
|
|
"fmt"
|
2021-04-05 15:30:52 +00:00
|
|
|
"net/http"
|
2023-09-07 09:37:47 +00:00
|
|
|
"slices"
|
2014-07-26 06:28:04 +00:00
|
|
|
"strings"
|
2014-03-22 17:50:50 +00:00
|
|
|
|
2016-11-10 16:24:48 +00:00
|
|
|
"code.gitea.io/gitea/models"
|
2021-09-19 11:49:59 +00:00
|
|
|
"code.gitea.io/gitea/models/db"
|
2023-05-13 21:59:01 +00:00
|
|
|
git_model "code.gitea.io/gitea/models/git"
|
2022-03-29 06:29:02 +00:00
|
|
|
"code.gitea.io/gitea/models/organization"
|
2022-08-25 02:31:57 +00:00
|
|
|
access_model "code.gitea.io/gitea/models/perm/access"
|
2021-11-19 13:39:57 +00:00
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-09 19:57:58 +00:00
|
|
|
"code.gitea.io/gitea/models/unit"
|
2021-11-24 09:49:20 +00:00
|
|
|
user_model "code.gitea.io/gitea/models/user"
|
2016-11-10 16:24:48 +00:00
|
|
|
"code.gitea.io/gitea/modules/base"
|
2023-04-27 06:06:45 +00:00
|
|
|
"code.gitea.io/gitea/modules/cache"
|
2016-11-10 16:24:48 +00:00
|
|
|
"code.gitea.io/gitea/modules/context"
|
2023-04-27 06:06:45 +00:00
|
|
|
"code.gitea.io/gitea/modules/git"
|
2016-11-10 16:24:48 +00:00
|
|
|
"code.gitea.io/gitea/modules/log"
|
2022-03-29 07:23:45 +00:00
|
|
|
repo_module "code.gitea.io/gitea/modules/repository"
|
2016-11-10 16:24:48 +00:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2021-06-23 21:12:38 +00:00
|
|
|
"code.gitea.io/gitea/modules/storage"
|
2022-04-07 18:59:56 +00:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
|
|
|
"code.gitea.io/gitea/modules/util"
|
2021-01-26 15:36:53 +00:00
|
|
|
"code.gitea.io/gitea/modules/web"
|
2022-12-29 02:57:15 +00:00
|
|
|
"code.gitea.io/gitea/services/convert"
|
2021-04-06 19:44:05 +00:00
|
|
|
"code.gitea.io/gitea/services/forms"
|
2019-10-26 06:54:11 +00:00
|
|
|
repo_service "code.gitea.io/gitea/services/repository"
|
2021-12-06 07:19:28 +00:00
|
|
|
archiver_service "code.gitea.io/gitea/services/repository/archiver"
|
2014-02-20 02:45:43 +00:00
|
|
|
)
|
|
|
|
|
2014-06-23 03:11:12 +00:00
|
|
|
const (
|
2020-10-20 23:50:10 +00:00
|
|
|
tplCreate base.TplName = "repo/create"
|
|
|
|
tplAlertDetails base.TplName = "base/alert_details"
|
2014-06-23 03:11:12 +00:00
|
|
|
)
|
|
|
|
|
2019-01-18 00:01:04 +00:00
|
|
|
// MustBeNotEmpty render when a repo is a empty git dir
|
|
|
|
func MustBeNotEmpty(ctx *context.Context) {
|
|
|
|
if ctx.Repo.Repository.IsEmpty {
|
|
|
|
ctx.NotFound("MustBeNotEmpty", nil)
|
2016-01-07 03:07:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-10-30 02:04:25 +00:00
|
|
|
// MustBeEditable check that repo can be edited
|
|
|
|
func MustBeEditable(ctx *context.Context) {
|
|
|
|
if !ctx.Repo.Repository.CanEnableEditor() || ctx.Repo.IsViewCommit {
|
2018-01-10 21:34:17 +00:00
|
|
|
ctx.NotFound("", nil)
|
2017-10-30 02:04:25 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// MustBeAbleToUpload check that repo can be uploaded to
|
|
|
|
func MustBeAbleToUpload(ctx *context.Context) {
|
|
|
|
if !setting.Repository.Upload.Enabled {
|
2018-01-10 21:34:17 +00:00
|
|
|
ctx.NotFound("", nil)
|
2017-10-30 02:04:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-27 06:06:45 +00:00
|
|
|
func CommitInfoCache(ctx *context.Context) {
|
|
|
|
var err error
|
|
|
|
ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetBranchCommit(ctx.Repo.Repository.DefaultBranch)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetBranchCommit", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Repo.CommitsCount, err = ctx.Repo.GetCommitsCount()
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetCommitsCount", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
ctx.Data["CommitsCount"] = ctx.Repo.CommitsCount
|
|
|
|
ctx.Repo.GitRepo.LastCommitCache = git.NewLastCommitCache(ctx.Repo.CommitsCount, ctx.Repo.Repository.FullName(), ctx.Repo.GitRepo, cache.GetCache())
|
|
|
|
}
|
|
|
|
|
2021-11-24 09:49:20 +00:00
|
|
|
func checkContextUser(ctx *context.Context, uid int64) *user_model.User {
|
2023-09-14 17:09:32 +00:00
|
|
|
orgs, err := organization.GetOrgsCanCreateRepoByUserID(ctx, ctx.Doer.ID)
|
2015-09-07 17:58:23 +00:00
|
|
|
if err != nil {
|
2019-11-20 11:27:49 +00:00
|
|
|
ctx.ServerError("GetOrgsCanCreateRepoByUserID", err)
|
2015-08-28 10:33:09 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-03-22 07:03:22 +00:00
|
|
|
if !ctx.Doer.IsAdmin {
|
2022-03-29 06:29:02 +00:00
|
|
|
orgsAvailable := []*organization.Organization{}
|
2020-05-03 21:08:24 +00:00
|
|
|
for i := 0; i < len(orgs); i++ {
|
|
|
|
if orgs[i].CanCreateRepo() {
|
|
|
|
orgsAvailable = append(orgsAvailable, orgs[i])
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ctx.Data["Orgs"] = orgsAvailable
|
|
|
|
} else {
|
|
|
|
ctx.Data["Orgs"] = orgs
|
|
|
|
}
|
|
|
|
|
2015-07-19 09:11:16 +00:00
|
|
|
// Not equal means current user is an organization.
|
2022-03-22 07:03:22 +00:00
|
|
|
if uid == ctx.Doer.ID || uid == 0 {
|
|
|
|
return ctx.Doer
|
2015-07-19 09:11:16 +00:00
|
|
|
}
|
|
|
|
|
2022-12-03 02:48:26 +00:00
|
|
|
org, err := user_model.GetUserByID(ctx, uid)
|
2021-11-24 09:49:20 +00:00
|
|
|
if user_model.IsErrUserNotExist(err) {
|
2022-03-22 07:03:22 +00:00
|
|
|
return ctx.Doer
|
2015-07-19 09:11:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
2022-10-24 19:29:17 +00:00
|
|
|
ctx.ServerError("GetUserByID", fmt.Errorf("[%d]: %w", uid, err))
|
2015-07-19 09:11:16 +00:00
|
|
|
return nil
|
2015-08-28 10:33:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Check ownership of organization.
|
2017-12-21 07:43:26 +00:00
|
|
|
if !org.IsOrganization() {
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.Error(http.StatusForbidden)
|
2015-07-19 09:11:16 +00:00
|
|
|
return nil
|
2014-11-06 04:30:04 +00:00
|
|
|
}
|
2022-03-22 07:03:22 +00:00
|
|
|
if !ctx.Doer.IsAdmin {
|
2023-10-03 10:30:41 +00:00
|
|
|
canCreate, err := organization.OrgFromUser(org).CanCreateOrgRepo(ctx, ctx.Doer.ID)
|
2017-12-21 07:43:26 +00:00
|
|
|
if err != nil {
|
2019-11-20 11:27:49 +00:00
|
|
|
ctx.ServerError("CanCreateOrgRepo", err)
|
2017-12-21 07:43:26 +00:00
|
|
|
return nil
|
2019-11-20 11:27:49 +00:00
|
|
|
} else if !canCreate {
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.Error(http.StatusForbidden)
|
2017-12-21 07:43:26 +00:00
|
|
|
return nil
|
|
|
|
}
|
2020-04-30 15:11:56 +00:00
|
|
|
} else {
|
|
|
|
ctx.Data["Orgs"] = orgs
|
2017-12-21 07:43:26 +00:00
|
|
|
}
|
2015-07-19 09:11:16 +00:00
|
|
|
return org
|
2014-11-06 04:30:04 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 12:59:56 +00:00
|
|
|
func getRepoPrivate(ctx *context.Context) bool {
|
|
|
|
switch strings.ToLower(setting.Repository.DefaultPrivate) {
|
|
|
|
case setting.RepoCreatingLastUserVisibility:
|
2022-03-22 07:03:22 +00:00
|
|
|
return ctx.Doer.LastRepoVisibility
|
2017-12-20 12:59:56 +00:00
|
|
|
case setting.RepoCreatingPrivate:
|
|
|
|
return true
|
|
|
|
case setting.RepoCreatingPublic:
|
|
|
|
return false
|
|
|
|
default:
|
2022-03-22 07:03:22 +00:00
|
|
|
return ctx.Doer.LastRepoVisibility
|
2017-12-20 12:59:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 07:04:31 +00:00
|
|
|
// Create render creating repository page
|
2016-03-11 16:56:52 +00:00
|
|
|
func Create(ctx *context.Context) {
|
2014-07-26 04:24:27 +00:00
|
|
|
ctx.Data["Title"] = ctx.Tr("new_repo")
|
|
|
|
|
|
|
|
// Give default value for template to render.
|
2022-03-29 07:23:45 +00:00
|
|
|
ctx.Data["Gitignores"] = repo_module.Gitignores
|
2023-04-10 08:44:02 +00:00
|
|
|
ctx.Data["LabelTemplateFiles"] = repo_module.LabelTemplateFiles
|
2022-03-29 07:23:45 +00:00
|
|
|
ctx.Data["Licenses"] = repo_module.Licenses
|
|
|
|
ctx.Data["Readmes"] = repo_module.Readmes
|
2015-08-28 08:44:04 +00:00
|
|
|
ctx.Data["readme"] = "Default"
|
2017-12-20 12:59:56 +00:00
|
|
|
ctx.Data["private"] = getRepoPrivate(ctx)
|
2015-10-25 08:26:26 +00:00
|
|
|
ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate
|
2020-06-17 20:53:55 +00:00
|
|
|
ctx.Data["default_branch"] = setting.Repository.DefaultBranch
|
2023-12-13 21:02:00 +00:00
|
|
|
ctx.Data["hash_type"] = "sha1"
|
2014-06-25 07:55:59 +00:00
|
|
|
|
2021-07-29 01:42:15 +00:00
|
|
|
ctxUser := checkContextUser(ctx, ctx.FormInt64("org"))
|
2015-07-19 09:11:16 +00:00
|
|
|
if ctx.Written() {
|
2014-11-06 04:30:04 +00:00
|
|
|
return
|
2014-07-26 06:28:04 +00:00
|
|
|
}
|
2014-06-28 19:43:25 +00:00
|
|
|
ctx.Data["ContextUser"] = ctxUser
|
|
|
|
|
2019-11-11 15:15:29 +00:00
|
|
|
ctx.Data["repo_template_name"] = ctx.Tr("repo.template_select")
|
2021-07-29 01:42:15 +00:00
|
|
|
templateID := ctx.FormInt64("template_id")
|
2019-11-11 15:15:29 +00:00
|
|
|
if templateID > 0 {
|
2022-12-03 02:48:26 +00:00
|
|
|
templateRepo, err := repo_model.GetRepositoryByID(ctx, templateID)
|
2022-08-25 02:31:57 +00:00
|
|
|
if err == nil && access_model.CheckRepoUnitUser(ctx, templateRepo, ctxUser, unit.TypeCode) {
|
2019-11-11 15:15:29 +00:00
|
|
|
ctx.Data["repo_template"] = templateID
|
|
|
|
ctx.Data["repo_template_name"] = templateRepo.Name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 07:03:22 +00:00
|
|
|
ctx.Data["CanCreateRepo"] = ctx.Doer.CanCreateRepo()
|
|
|
|
ctx.Data["MaxCreationLimit"] = ctx.Doer.MaxCreationLimit()
|
2021-01-21 23:44:37 +00:00
|
|
|
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.HTML(http.StatusOK, tplCreate)
|
2014-04-10 22:09:57 +00:00
|
|
|
}
|
2014-03-07 21:05:18 +00:00
|
|
|
|
2023-07-04 18:36:08 +00:00
|
|
|
func handleCreateError(ctx *context.Context, owner *user_model.User, err error, name string, tpl base.TplName, form any) {
|
2015-08-28 10:33:09 +00:00
|
|
|
switch {
|
2021-12-12 15:48:20 +00:00
|
|
|
case repo_model.IsErrReachLimitOfRepo(err):
|
2022-01-02 02:38:07 +00:00
|
|
|
maxCreationLimit := owner.MaxCreationLimit()
|
2022-01-02 03:33:57 +00:00
|
|
|
msg := ctx.TrN(maxCreationLimit, "repo.form.reach_limit_of_creation_1", "repo.form.reach_limit_of_creation_n", maxCreationLimit)
|
2021-12-31 08:43:03 +00:00
|
|
|
ctx.RenderWithErr(msg, tpl, form)
|
2021-12-12 15:48:20 +00:00
|
|
|
case repo_model.IsErrRepoAlreadyExist(err):
|
2015-08-28 10:33:09 +00:00
|
|
|
ctx.Data["Err_RepoName"] = true
|
|
|
|
ctx.RenderWithErr(ctx.Tr("form.repo_name_been_taken"), tpl, form)
|
2021-12-12 15:48:20 +00:00
|
|
|
case repo_model.IsErrRepoFilesAlreadyExist(err):
|
2020-09-25 04:09:23 +00:00
|
|
|
ctx.Data["Err_RepoName"] = true
|
|
|
|
switch {
|
|
|
|
case ctx.IsUserSiteAdmin() || (setting.Repository.AllowAdoptionOfUnadoptedRepositories && setting.Repository.AllowDeleteOfUnadoptedRepositories):
|
|
|
|
ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist.adopt_or_delete"), tpl, form)
|
|
|
|
case setting.Repository.AllowAdoptionOfUnadoptedRepositories:
|
|
|
|
ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist.adopt"), tpl, form)
|
|
|
|
case setting.Repository.AllowDeleteOfUnadoptedRepositories:
|
|
|
|
ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist.delete"), tpl, form)
|
|
|
|
default:
|
|
|
|
ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist"), tpl, form)
|
|
|
|
}
|
2021-11-24 09:49:20 +00:00
|
|
|
case db.IsErrNameReserved(err):
|
2015-08-28 10:33:09 +00:00
|
|
|
ctx.Data["Err_RepoName"] = true
|
2021-11-24 09:49:20 +00:00
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tpl, form)
|
|
|
|
case db.IsErrNamePatternNotAllowed(err):
|
2015-08-28 10:33:09 +00:00
|
|
|
ctx.Data["Err_RepoName"] = true
|
2021-11-24 09:49:20 +00:00
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.form.name_pattern_not_allowed", err.(db.ErrNamePatternNotAllowed).Pattern), tpl, form)
|
2015-08-28 10:33:09 +00:00
|
|
|
default:
|
2018-01-10 21:34:17 +00:00
|
|
|
ctx.ServerError(name, err)
|
2015-08-28 10:33:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-24 07:04:31 +00:00
|
|
|
// CreatePost response for creating repository
|
2021-01-26 15:36:53 +00:00
|
|
|
func CreatePost(ctx *context.Context) {
|
2021-04-06 19:44:05 +00:00
|
|
|
form := web.GetForm(ctx).(*forms.CreateRepoForm)
|
2014-07-26 04:24:27 +00:00
|
|
|
ctx.Data["Title"] = ctx.Tr("new_repo")
|
|
|
|
|
2022-03-29 07:23:45 +00:00
|
|
|
ctx.Data["Gitignores"] = repo_module.Gitignores
|
2023-04-10 08:44:02 +00:00
|
|
|
ctx.Data["LabelTemplateFiles"] = repo_module.LabelTemplateFiles
|
2022-03-29 07:23:45 +00:00
|
|
|
ctx.Data["Licenses"] = repo_module.Licenses
|
|
|
|
ctx.Data["Readmes"] = repo_module.Readmes
|
2014-02-20 02:45:43 +00:00
|
|
|
|
2022-03-22 07:03:22 +00:00
|
|
|
ctx.Data["CanCreateRepo"] = ctx.Doer.CanCreateRepo()
|
|
|
|
ctx.Data["MaxCreationLimit"] = ctx.Doer.MaxCreationLimit()
|
2021-04-07 07:26:41 +00:00
|
|
|
|
2016-11-27 06:03:59 +00:00
|
|
|
ctxUser := checkContextUser(ctx, form.UID)
|
2015-07-19 09:11:16 +00:00
|
|
|
if ctx.Written() {
|
|
|
|
return
|
2014-07-26 06:28:04 +00:00
|
|
|
}
|
2014-07-26 04:24:27 +00:00
|
|
|
ctx.Data["ContextUser"] = ctxUser
|
|
|
|
|
2014-03-22 20:00:46 +00:00
|
|
|
if ctx.HasError() {
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.HTML(http.StatusOK, tplCreate)
|
2014-03-22 20:00:46 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-12-10 01:27:50 +00:00
|
|
|
var repo *repo_model.Repository
|
2019-11-11 15:15:29 +00:00
|
|
|
var err error
|
|
|
|
if form.RepoTemplate > 0 {
|
2022-06-06 08:01:49 +00:00
|
|
|
opts := repo_module.GenerateRepoOptions{
|
2023-07-21 04:32:47 +00:00
|
|
|
Name: form.RepoName,
|
|
|
|
Description: form.Description,
|
|
|
|
Private: form.Private,
|
|
|
|
GitContent: form.GitContent,
|
|
|
|
Topics: form.Topics,
|
|
|
|
GitHooks: form.GitHooks,
|
|
|
|
Webhooks: form.Webhooks,
|
|
|
|
Avatar: form.Avatar,
|
|
|
|
IssueLabels: form.Labels,
|
|
|
|
ProtectedBranch: form.ProtectedBranch,
|
2019-11-11 15:15:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if !opts.IsValid() {
|
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.template.one_item"), tplCreate, form)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
templateRepo := getRepository(ctx, form.RepoTemplate)
|
|
|
|
if ctx.Written() {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if !templateRepo.IsTemplate {
|
|
|
|
ctx.RenderWithErr(ctx.Tr("repo.template.invalid"), tplCreate, form)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-02-28 22:17:51 +00:00
|
|
|
repo, err = repo_service.GenerateRepository(ctx, ctx.Doer, ctxUser, templateRepo, opts)
|
2019-11-11 15:15:29 +00:00
|
|
|
if err == nil {
|
|
|
|
log.Trace("Repository generated [%d]: %s/%s", repo.ID, ctxUser.Name, repo.Name)
|
2021-11-16 18:18:25 +00:00
|
|
|
ctx.Redirect(repo.Link())
|
2019-11-11 15:15:29 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
2023-09-06 12:08:51 +00:00
|
|
|
repo, err = repo_service.CreateRepository(ctx, ctx.Doer, ctxUser, repo_service.CreateRepoOptions{
|
2023-12-17 11:56:08 +00:00
|
|
|
Name: form.RepoName,
|
|
|
|
Description: form.Description,
|
|
|
|
Gitignores: form.Gitignores,
|
|
|
|
IssueLabels: form.IssueLabels,
|
|
|
|
License: form.License,
|
|
|
|
Readme: form.Readme,
|
|
|
|
IsPrivate: form.Private || setting.Repository.ForcePrivate,
|
|
|
|
DefaultBranch: form.DefaultBranch,
|
|
|
|
AutoInit: form.AutoInit,
|
|
|
|
IsTemplate: form.Template,
|
2024-01-16 12:54:48 +00:00
|
|
|
TrustModel: repo_model.DefaultTrustModel,
|
2023-12-17 11:56:08 +00:00
|
|
|
ObjectFormatName: form.ObjectFormatName,
|
2019-11-11 15:15:29 +00:00
|
|
|
})
|
|
|
|
if err == nil {
|
|
|
|
log.Trace("Repository created [%d]: %s/%s", repo.ID, ctxUser.Name, repo.Name)
|
2021-11-16 18:18:25 +00:00
|
|
|
ctx.Redirect(repo.Link())
|
2019-11-11 15:15:29 +00:00
|
|
|
return
|
|
|
|
}
|
2014-03-10 00:06:29 +00:00
|
|
|
}
|
2014-04-13 00:35:35 +00:00
|
|
|
|
2016-11-24 07:04:31 +00:00
|
|
|
handleCreateError(ctx, ctxUser, err, "CreatePost", tplCreate, &form)
|
2014-04-10 22:09:57 +00:00
|
|
|
}
|
2014-04-09 13:28:00 +00:00
|
|
|
|
2016-11-24 07:04:31 +00:00
|
|
|
// Action response for actions to a repository
|
2016-03-11 16:56:52 +00:00
|
|
|
func Action(ctx *context.Context) {
|
2014-08-11 03:11:18 +00:00
|
|
|
var err error
|
|
|
|
switch ctx.Params(":action") {
|
|
|
|
case "watch":
|
2022-05-20 14:08:52 +00:00
|
|
|
err = repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
2014-08-11 03:11:18 +00:00
|
|
|
case "unwatch":
|
2022-05-20 14:08:52 +00:00
|
|
|
err = repo_model.WatchRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
2014-08-11 03:11:18 +00:00
|
|
|
case "star":
|
2023-09-15 06:13:19 +00:00
|
|
|
err = repo_model.StarRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, true)
|
2014-08-11 03:11:18 +00:00
|
|
|
case "unstar":
|
2023-09-15 06:13:19 +00:00
|
|
|
err = repo_model.StarRepo(ctx, ctx.Doer.ID, ctx.Repo.Repository.ID, false)
|
2021-03-01 00:47:30 +00:00
|
|
|
case "accept_transfer":
|
|
|
|
err = acceptOrRejectRepoTransfer(ctx, true)
|
|
|
|
case "reject_transfer":
|
|
|
|
err = acceptOrRejectRepoTransfer(ctx, false)
|
2016-01-07 03:07:17 +00:00
|
|
|
case "desc": // FIXME: this is not used
|
2015-02-16 10:51:56 +00:00
|
|
|
if !ctx.Repo.IsOwner() {
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.Error(http.StatusNotFound)
|
2014-08-11 03:11:18 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-08-11 00:31:13 +00:00
|
|
|
ctx.Repo.Repository.Description = ctx.FormString("desc")
|
|
|
|
ctx.Repo.Repository.Website = ctx.FormString("site")
|
2023-02-28 22:17:51 +00:00
|
|
|
err = repo_service.UpdateRepository(ctx, ctx.Repo.Repository, false)
|
2014-08-11 03:11:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if err != nil {
|
2018-01-10 21:34:17 +00:00
|
|
|
ctx.ServerError(fmt.Sprintf("Action (%s)", ctx.Params(":action")), err)
|
2014-08-11 03:11:18 +00:00
|
|
|
return
|
|
|
|
}
|
2015-07-23 20:50:05 +00:00
|
|
|
|
2021-08-11 00:31:13 +00:00
|
|
|
ctx.RedirectToFirst(ctx.FormString("redirect_to"), ctx.Repo.RepoLink)
|
2014-08-11 03:11:18 +00:00
|
|
|
}
|
2014-07-26 04:24:27 +00:00
|
|
|
|
2021-03-01 00:47:30 +00:00
|
|
|
func acceptOrRejectRepoTransfer(ctx *context.Context, accept bool) error {
|
2022-12-10 02:46:31 +00:00
|
|
|
repoTransfer, err := models.GetPendingRepositoryTransfer(ctx, ctx.Repo.Repository)
|
2021-03-01 00:47:30 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2022-12-10 02:46:31 +00:00
|
|
|
if err := repoTransfer.LoadAttributes(ctx); err != nil {
|
2021-03-01 00:47:30 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2023-09-16 14:39:12 +00:00
|
|
|
if !repoTransfer.CanUserAcceptTransfer(ctx, ctx.Doer) {
|
2021-03-01 00:47:30 +00:00
|
|
|
return errors.New("user does not have enough permissions")
|
|
|
|
}
|
|
|
|
|
|
|
|
if accept {
|
2021-12-21 02:01:58 +00:00
|
|
|
if ctx.Repo.GitRepo != nil {
|
|
|
|
ctx.Repo.GitRepo.Close()
|
|
|
|
ctx.Repo.GitRepo = nil
|
|
|
|
}
|
|
|
|
|
2022-12-10 02:46:31 +00:00
|
|
|
if err := repo_service.TransferOwnership(ctx, repoTransfer.Doer, repoTransfer.Recipient, ctx.Repo.Repository, repoTransfer.Teams); err != nil {
|
2021-03-01 00:47:30 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.transfer.success"))
|
|
|
|
} else {
|
2023-09-16 14:39:12 +00:00
|
|
|
if err := models.CancelRepositoryTransfer(ctx, ctx.Repo.Repository); err != nil {
|
2021-03-01 00:47:30 +00:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
ctx.Flash.Success(ctx.Tr("repo.settings.transfer.rejected"))
|
|
|
|
}
|
|
|
|
|
2023-02-11 06:34:11 +00:00
|
|
|
ctx.Redirect(ctx.Repo.Repository.Link())
|
2021-03-01 00:47:30 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-01-06 22:37:30 +00:00
|
|
|
// RedirectDownload return a file based on the following infos:
|
|
|
|
func RedirectDownload(ctx *context.Context) {
|
|
|
|
var (
|
|
|
|
vTag = ctx.Params("vTag")
|
|
|
|
fileName = ctx.Params("fileName")
|
|
|
|
)
|
|
|
|
tagNames := []string{vTag}
|
|
|
|
curRepo := ctx.Repo.Repository
|
2024-01-15 02:19:25 +00:00
|
|
|
releases, err := db.Find[repo_model.Release](ctx, repo_model.FindReleasesOptions{
|
|
|
|
RepoID: curRepo.ID,
|
|
|
|
TagNames: tagNames,
|
|
|
|
})
|
2019-01-06 22:37:30 +00:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("RedirectDownload", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if len(releases) == 1 {
|
|
|
|
release := releases[0]
|
2022-05-20 14:08:52 +00:00
|
|
|
att, err := repo_model.GetAttachmentByReleaseIDFileName(ctx, release.ID, fileName)
|
2019-01-06 22:37:30 +00:00
|
|
|
if err != nil {
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.Error(http.StatusNotFound)
|
2019-01-06 22:37:30 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
if att != nil {
|
2023-04-12 09:05:23 +00:00
|
|
|
ServeAttachment(ctx, att.UUID)
|
2019-01-06 22:37:30 +00:00
|
|
|
return
|
|
|
|
}
|
2023-09-06 11:06:04 +00:00
|
|
|
} else if len(releases) == 0 && vTag == "latest" {
|
|
|
|
// GitHub supports the alias "latest" for the latest release
|
|
|
|
// We only fetch the latest release if the tag is "latest" and no release with the tag "latest" exists
|
2023-09-25 13:17:37 +00:00
|
|
|
release, err := repo_model.GetLatestReleaseByRepoID(ctx, ctx.Repo.Repository.ID)
|
2023-09-06 11:06:04 +00:00
|
|
|
if err != nil {
|
|
|
|
ctx.Error(http.StatusNotFound)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
att, err := repo_model.GetAttachmentByReleaseIDFileName(ctx, release.ID, fileName)
|
|
|
|
if err != nil {
|
|
|
|
ctx.Error(http.StatusNotFound)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
if att != nil {
|
|
|
|
ServeAttachment(ctx, att.UUID)
|
|
|
|
return
|
|
|
|
}
|
2019-01-06 22:37:30 +00:00
|
|
|
}
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.Error(http.StatusNotFound)
|
2019-01-06 22:37:30 +00:00
|
|
|
}
|
|
|
|
|
2021-06-23 21:12:38 +00:00
|
|
|
// Download an archive of a repository
|
|
|
|
func Download(ctx *context.Context) {
|
|
|
|
uri := ctx.Params("*")
|
|
|
|
aReq, err := archiver_service.NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, uri)
|
|
|
|
if err != nil {
|
2021-11-17 19:47:35 +00:00
|
|
|
if errors.Is(err, archiver_service.ErrUnknownArchiveFormat{}) {
|
|
|
|
ctx.Error(http.StatusBadRequest, err.Error())
|
2022-08-29 09:45:20 +00:00
|
|
|
} else if errors.Is(err, archiver_service.RepoRefNotFoundError{}) {
|
|
|
|
ctx.Error(http.StatusNotFound, err.Error())
|
2021-11-17 19:47:35 +00:00
|
|
|
} else {
|
|
|
|
ctx.ServerError("archiver_service.NewRequest", err)
|
|
|
|
}
|
2021-06-23 21:12:38 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-29 09:45:20 +00:00
|
|
|
archiver, err := aReq.Await(ctx)
|
2021-06-23 21:12:38 +00:00
|
|
|
if err != nil {
|
2022-08-29 09:45:20 +00:00
|
|
|
ctx.ServerError("archiver.Await", err)
|
2021-06-23 21:12:38 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-08-29 09:45:20 +00:00
|
|
|
download(ctx, aReq.GetArchiveName(), archiver)
|
2021-06-23 21:12:38 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 07:19:28 +00:00
|
|
|
func download(ctx *context.Context, archiveName string, archiver *repo_model.RepoArchiver) {
|
2021-06-23 21:12:38 +00:00
|
|
|
downloadName := ctx.Repo.Repository.Name + "-" + archiveName
|
|
|
|
|
2022-08-29 09:45:20 +00:00
|
|
|
rPath := archiver.RelativePath()
|
2023-06-14 03:42:38 +00:00
|
|
|
if setting.RepoArchive.Storage.MinioConfig.ServeDirect {
|
2022-01-20 17:46:10 +00:00
|
|
|
// If we have a signed url (S3, object storage), redirect to this directly.
|
2021-06-23 21:12:38 +00:00
|
|
|
u, err := storage.RepoArchives.URL(rPath, downloadName)
|
|
|
|
if u != nil && err == nil {
|
|
|
|
ctx.Redirect(u.String())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-20 17:46:10 +00:00
|
|
|
// If we have matched and access to release or issue
|
2021-06-23 21:12:38 +00:00
|
|
|
fr, err := storage.RepoArchives.Open(rPath)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("Open", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
defer fr.Close()
|
2022-08-25 16:05:21 +00:00
|
|
|
|
2022-11-24 14:25:13 +00:00
|
|
|
ctx.ServeContent(fr, &context.ServeHeaderOptions{
|
|
|
|
Filename: downloadName,
|
|
|
|
LastModified: archiver.CreatedUnix.AsLocalTime(),
|
|
|
|
})
|
2021-06-23 21:12:38 +00:00
|
|
|
}
|
|
|
|
|
[RFC] Make archival asynchronous (#11296)
* Make archival asynchronous
The prime benefit being sought here is for large archives to not
clog up the rendering process and cause unsightly proxy timeouts.
As a secondary benefit, archive-in-progress is moved out of the
way into a /tmp file so that new archival requests for the same
commit will not get fulfilled based on an archive that isn't yet
finished.
This asynchronous system is fairly primitive; request comes in, we'll
spawn off a new goroutine to handle it, then we'll mark it as done.
Status requests will see if the file exists in the final location,
and report the archival as done when it exists.
Fixes #11265
* Archive links: drop initial delay to three-quarters of a second
Some, or perhaps even most, archives will not take all that long to archive.
The archive process starts as soon as the download button is initially
clicked, so in theory they could be done quite quickly. Drop the initial
delay down to three-quarters of a second to make it more responsive in the
common case of the archive being quickly created.
* archiver: restructure a little bit to facilitate testing
This introduces two sync.Cond pointers to the archiver package. If they're
non-nil when we go to process a request, we'll wait until signalled (at all)
to proceed. The tests will then create the sync.Cond so that it can signal
at-will and sanity-check the state of the queue at different phases.
The author believes that nil-checking these two sync.Cond pointers on every
archive processing will introduce minimal overhead with no impact on
maintainability.
* gofmt nit: no space around binary + operator
* services: archiver: appease golangci-lint, lock queueMutex
Locking/unlocking the queueMutex is allowed, but not required, for
Cond.Signal() and Cond.Broadcast(). The magic at play here is just a little
too much for golangci-lint, as we take the address of queueMutex and this is
mostly used in archiver.go; the variable still gets flagged as unused.
* archiver: tests: fix several timing nits
Once we've signaled a cond var, it may take some small amount of time for
the goroutines released to hit the spot we're wanting them to be at. Give
them an appropriate amount of time.
* archiver: tests: no underscore in var name, ungh
* archiver: tests: Test* is run in a separate context than TestMain
We must setup the mutex/cond variables at the beginning of any test that's
going to use it, or else these will be nil when the test is actually ran.
* archiver: tests: hopefully final tweak
Things got shuffled around such that we carefully build up and release
requests from the queue, so we can validate the state of the queue at each
step. Fix some assertions that no longer hold true as fallout.
* repo: Download: restore some semblance of previous behavior
When archival was made async, the GET endpoint was only useful if a previous
POST had initiated the download. This commit restores the previous behavior,
to an extent; we'll now submit the archive request there and return a
"202 Accepted" to indicate that it's processing if we didn't manage to
complete the request within ~2 seconds of submission.
This lets a client directly GET the archive, and gives them some indication
that they may attempt to GET it again at a later time.
* archiver: tests: simplify a bit further
We don't need to risk failure and use time.ParseDuration to get 2 *
time.Second.
else if isn't really necessary if the conditions are simple enough and lead
to the same result.
* archiver: tests: resolve potential source of flakiness
Increase all timeouts to 10 seconds; these aren't hard-coded sleeps, so
there's no guarantee we'll actually take that long. If we need longer to
not have a false-positive, then so be it.
While here, various assert.{Not,}Equal arguments are flipped around so that
the wording in error output reflects reality, where the expected argument is
second and actual third.
* archiver: setup infrastructure for notifying consumers of completion
This API will *not* allow consumers to subscribe to specific requests being
completed, just *any* request being completed. The caller is responsible for
determining if their request is satisfied and waiting again if needed.
* repo: archive: make GET endpoint synchronous again
If the request isn't complete, this endpoint will now submit the request and
wait for completion using the new API. This may still be susceptible to
timeouts for larger repos, but other endpoints now exist that the web
interface will use to negotiate its way through larger archive processes.
* archiver: tests: amend test to include WaitForCompletion()
This is a trivial one, so go ahead and include it.
* archiver: tests: fix test by calling NewContext()
The mutex is otherwise uninitialized, so we need to ensure that we're
actually initializing it if we plan to test it.
* archiver: tests: integrate new WaitForCompletion a little better
We can use this to wait for archives to come in, rather than spinning and
hoping with a timeout.
* archiver: tests: combine numQueued declaration with next-instruction assignment
* routers: repo: reap unused archiving flag from DownloadStatus()
This had some planned usage before, indicating whether this request
initiated the archival process or not. After several rounds of refactoring,
this use was deemed not necessary for much of anything and got boiled down
to !complete in all cases.
* services: archiver: restructure to use a channel
We now offer two forms of waiting for a request:
- WaitForCompletion: wait for completion with no timeout
- TimedWaitForCompletion: wait for completion with timeout
In both cases, we wait for the given request's cchan to close; in the latter
case, we do so with the caller-provided timeout. This completely removes the
need for busy-wait loops in Download/InitiateDownload, as it's fairly clean
to wait on a channel with timeout.
* services: archiver: use defer to unlock now that we can
This previously carried the lock into the goroutine, but an intermediate
step just added the request to archiveInProgress outside of the new
goroutine and removed the need for the goroutine to start out with it.
* Revert "archiver: tests: combine numQueued declaration with next-instruction assignment"
This reverts commit bcc52140238e16680f2e05e448e9be51372afdf5.
Revert "archiver: tests: integrate new WaitForCompletion a little better"
This reverts commit 9fc8bedb5667d24d3a3c7843dc28a229efffb1e6.
Revert "archiver: tests: fix test by calling NewContext()"
This reverts commit 709c35685eaaf261ebbb7d3420e3376a4ee8e7f2.
Revert "archiver: tests: amend test to include WaitForCompletion()"
This reverts commit 75261f56bc05d1fa8ff7e81dcbc0ccd93fdc9d50.
* archiver: tests: first attempt at WaitForCompletion() tests
* archiver: tests: slight improvement, less busy-loop
Just wait for the requests to complete in order, instead of busy-waiting
with a timeout. This is slightly less fragile.
While here, reverse the arguments of a nearby assert.Equal() so that
expected/actual are correct in any test output.
* archiver: address lint nits
* services: archiver: only close the channel once
* services: archiver: use a struct{} for the wait channel
This makes it obvious that the channel is only being used as a signal,
rather than anything useful being piped through it.
* archiver: tests: fix expectations
Move the close of the channel into doArchive() itself; notably, before these
goroutines move on to waiting on the Release cond.
The tests are adjusted to reflect that we can't WaitForCompletion() after
they've already completed, as WaitForCompletion() doesn't indicate that
they've been released from the queue yet.
* archiver: tests: set cchan to nil for comparison
* archiver: move ctx.Error's back into the route handlers
We shouldn't be setting this in a service, we should just be validating the
request that we were handed.
* services: archiver: use regex to match a hash
This makes sure we don't try and use refName as a hash when it's clearly not
one, e.g. heads/pull/foo.
* routers: repo: remove the weird /archive/status endpoint
We don't need to do this anymore, we can just continue POSTing to the
archive/* endpoint until we're told the download's complete. This avoids a
potential naming conflict, where a ref could start with "status/"
* archiver: tests: bump reasonable timeout to 15s
* archiver: tests: actually release timedReq
* archiver: tests: run through inFlight instead of manually checking
While we're here, add a test for manually re-processing an archive that's
already been complete. Re-open the channel and mark it incomplete, so that
doArchive can just mark it complete again.
* initArchiveLinks: prevent default behavior from clicking
* archiver: alias gitea's context, golang context import pending
* archiver: simplify logic, just reconstruct slices
While the previous logic was perhaps slightly more efficient, the
new variant's readability is much improved.
* archiver: don't block shutdown on waiting for archive
The technique established launches a goroutine to do the wait,
which will close a wait channel upon termination. For the timeout
case, we also send back a value indicating whether the timeout was
hit or not.
The timeouts are expected to be relatively small, but still a multi-
second delay to shutdown due to this could be unfortunate.
* archiver: simplify shutdown logic
We can just grab the shutdown channel from the graceful manager instead of
constructing a channel to halt the caller and/or pass a result back.
* Style issues
* Fix mis-merge
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
2020-11-07 20:27:28 +00:00
|
|
|
// InitiateDownload will enqueue an archival request, as needed. It may submit
|
|
|
|
// a request that's already in-progress, but the archiver service will just
|
|
|
|
// kind of drop it on the floor if this is the case.
|
|
|
|
func InitiateDownload(ctx *context.Context) {
|
|
|
|
uri := ctx.Params("*")
|
2021-06-23 21:12:38 +00:00
|
|
|
aReq, err := archiver_service.NewRequest(ctx.Repo.Repository.ID, ctx.Repo.GitRepo, uri)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("archiver_service.NewRequest", err)
|
|
|
|
return
|
|
|
|
}
|
[RFC] Make archival asynchronous (#11296)
* Make archival asynchronous
The prime benefit being sought here is for large archives to not
clog up the rendering process and cause unsightly proxy timeouts.
As a secondary benefit, archive-in-progress is moved out of the
way into a /tmp file so that new archival requests for the same
commit will not get fulfilled based on an archive that isn't yet
finished.
This asynchronous system is fairly primitive; request comes in, we'll
spawn off a new goroutine to handle it, then we'll mark it as done.
Status requests will see if the file exists in the final location,
and report the archival as done when it exists.
Fixes #11265
* Archive links: drop initial delay to three-quarters of a second
Some, or perhaps even most, archives will not take all that long to archive.
The archive process starts as soon as the download button is initially
clicked, so in theory they could be done quite quickly. Drop the initial
delay down to three-quarters of a second to make it more responsive in the
common case of the archive being quickly created.
* archiver: restructure a little bit to facilitate testing
This introduces two sync.Cond pointers to the archiver package. If they're
non-nil when we go to process a request, we'll wait until signalled (at all)
to proceed. The tests will then create the sync.Cond so that it can signal
at-will and sanity-check the state of the queue at different phases.
The author believes that nil-checking these two sync.Cond pointers on every
archive processing will introduce minimal overhead with no impact on
maintainability.
* gofmt nit: no space around binary + operator
* services: archiver: appease golangci-lint, lock queueMutex
Locking/unlocking the queueMutex is allowed, but not required, for
Cond.Signal() and Cond.Broadcast(). The magic at play here is just a little
too much for golangci-lint, as we take the address of queueMutex and this is
mostly used in archiver.go; the variable still gets flagged as unused.
* archiver: tests: fix several timing nits
Once we've signaled a cond var, it may take some small amount of time for
the goroutines released to hit the spot we're wanting them to be at. Give
them an appropriate amount of time.
* archiver: tests: no underscore in var name, ungh
* archiver: tests: Test* is run in a separate context than TestMain
We must setup the mutex/cond variables at the beginning of any test that's
going to use it, or else these will be nil when the test is actually ran.
* archiver: tests: hopefully final tweak
Things got shuffled around such that we carefully build up and release
requests from the queue, so we can validate the state of the queue at each
step. Fix some assertions that no longer hold true as fallout.
* repo: Download: restore some semblance of previous behavior
When archival was made async, the GET endpoint was only useful if a previous
POST had initiated the download. This commit restores the previous behavior,
to an extent; we'll now submit the archive request there and return a
"202 Accepted" to indicate that it's processing if we didn't manage to
complete the request within ~2 seconds of submission.
This lets a client directly GET the archive, and gives them some indication
that they may attempt to GET it again at a later time.
* archiver: tests: simplify a bit further
We don't need to risk failure and use time.ParseDuration to get 2 *
time.Second.
else if isn't really necessary if the conditions are simple enough and lead
to the same result.
* archiver: tests: resolve potential source of flakiness
Increase all timeouts to 10 seconds; these aren't hard-coded sleeps, so
there's no guarantee we'll actually take that long. If we need longer to
not have a false-positive, then so be it.
While here, various assert.{Not,}Equal arguments are flipped around so that
the wording in error output reflects reality, where the expected argument is
second and actual third.
* archiver: setup infrastructure for notifying consumers of completion
This API will *not* allow consumers to subscribe to specific requests being
completed, just *any* request being completed. The caller is responsible for
determining if their request is satisfied and waiting again if needed.
* repo: archive: make GET endpoint synchronous again
If the request isn't complete, this endpoint will now submit the request and
wait for completion using the new API. This may still be susceptible to
timeouts for larger repos, but other endpoints now exist that the web
interface will use to negotiate its way through larger archive processes.
* archiver: tests: amend test to include WaitForCompletion()
This is a trivial one, so go ahead and include it.
* archiver: tests: fix test by calling NewContext()
The mutex is otherwise uninitialized, so we need to ensure that we're
actually initializing it if we plan to test it.
* archiver: tests: integrate new WaitForCompletion a little better
We can use this to wait for archives to come in, rather than spinning and
hoping with a timeout.
* archiver: tests: combine numQueued declaration with next-instruction assignment
* routers: repo: reap unused archiving flag from DownloadStatus()
This had some planned usage before, indicating whether this request
initiated the archival process or not. After several rounds of refactoring,
this use was deemed not necessary for much of anything and got boiled down
to !complete in all cases.
* services: archiver: restructure to use a channel
We now offer two forms of waiting for a request:
- WaitForCompletion: wait for completion with no timeout
- TimedWaitForCompletion: wait for completion with timeout
In both cases, we wait for the given request's cchan to close; in the latter
case, we do so with the caller-provided timeout. This completely removes the
need for busy-wait loops in Download/InitiateDownload, as it's fairly clean
to wait on a channel with timeout.
* services: archiver: use defer to unlock now that we can
This previously carried the lock into the goroutine, but an intermediate
step just added the request to archiveInProgress outside of the new
goroutine and removed the need for the goroutine to start out with it.
* Revert "archiver: tests: combine numQueued declaration with next-instruction assignment"
This reverts commit bcc52140238e16680f2e05e448e9be51372afdf5.
Revert "archiver: tests: integrate new WaitForCompletion a little better"
This reverts commit 9fc8bedb5667d24d3a3c7843dc28a229efffb1e6.
Revert "archiver: tests: fix test by calling NewContext()"
This reverts commit 709c35685eaaf261ebbb7d3420e3376a4ee8e7f2.
Revert "archiver: tests: amend test to include WaitForCompletion()"
This reverts commit 75261f56bc05d1fa8ff7e81dcbc0ccd93fdc9d50.
* archiver: tests: first attempt at WaitForCompletion() tests
* archiver: tests: slight improvement, less busy-loop
Just wait for the requests to complete in order, instead of busy-waiting
with a timeout. This is slightly less fragile.
While here, reverse the arguments of a nearby assert.Equal() so that
expected/actual are correct in any test output.
* archiver: address lint nits
* services: archiver: only close the channel once
* services: archiver: use a struct{} for the wait channel
This makes it obvious that the channel is only being used as a signal,
rather than anything useful being piped through it.
* archiver: tests: fix expectations
Move the close of the channel into doArchive() itself; notably, before these
goroutines move on to waiting on the Release cond.
The tests are adjusted to reflect that we can't WaitForCompletion() after
they've already completed, as WaitForCompletion() doesn't indicate that
they've been released from the queue yet.
* archiver: tests: set cchan to nil for comparison
* archiver: move ctx.Error's back into the route handlers
We shouldn't be setting this in a service, we should just be validating the
request that we were handed.
* services: archiver: use regex to match a hash
This makes sure we don't try and use refName as a hash when it's clearly not
one, e.g. heads/pull/foo.
* routers: repo: remove the weird /archive/status endpoint
We don't need to do this anymore, we can just continue POSTing to the
archive/* endpoint until we're told the download's complete. This avoids a
potential naming conflict, where a ref could start with "status/"
* archiver: tests: bump reasonable timeout to 15s
* archiver: tests: actually release timedReq
* archiver: tests: run through inFlight instead of manually checking
While we're here, add a test for manually re-processing an archive that's
already been complete. Re-open the channel and mark it incomplete, so that
doArchive can just mark it complete again.
* initArchiveLinks: prevent default behavior from clicking
* archiver: alias gitea's context, golang context import pending
* archiver: simplify logic, just reconstruct slices
While the previous logic was perhaps slightly more efficient, the
new variant's readability is much improved.
* archiver: don't block shutdown on waiting for archive
The technique established launches a goroutine to do the wait,
which will close a wait channel upon termination. For the timeout
case, we also send back a value indicating whether the timeout was
hit or not.
The timeouts are expected to be relatively small, but still a multi-
second delay to shutdown due to this could be unfortunate.
* archiver: simplify shutdown logic
We can just grab the shutdown channel from the graceful manager instead of
constructing a channel to halt the caller and/or pass a result back.
* Style issues
* Fix mis-merge
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
2020-11-07 20:27:28 +00:00
|
|
|
if aReq == nil {
|
2021-04-05 15:30:52 +00:00
|
|
|
ctx.Error(http.StatusNotFound)
|
2014-09-24 21:43:33 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:22:54 +00:00
|
|
|
archiver, err := repo_model.GetRepoArchiver(ctx, aReq.RepoID, aReq.Type, aReq.CommitID)
|
2021-06-23 21:12:38 +00:00
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("archiver_service.StartArchive", err)
|
|
|
|
return
|
|
|
|
}
|
2021-12-06 07:19:28 +00:00
|
|
|
if archiver == nil || archiver.Status != repo_model.ArchiverReady {
|
2021-06-23 21:12:38 +00:00
|
|
|
if err := archiver_service.StartArchive(aReq); err != nil {
|
|
|
|
ctx.ServerError("archiver_service.StartArchive", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var completed bool
|
2021-12-06 07:19:28 +00:00
|
|
|
if archiver != nil && archiver.Status == repo_model.ArchiverReady {
|
2021-06-23 21:12:38 +00:00
|
|
|
completed = true
|
2014-03-22 17:50:50 +00:00
|
|
|
}
|
|
|
|
|
2023-07-04 18:36:08 +00:00
|
|
|
ctx.JSON(http.StatusOK, map[string]any{
|
2021-06-23 21:12:38 +00:00
|
|
|
"complete": completed,
|
[RFC] Make archival asynchronous (#11296)
* Make archival asynchronous
The prime benefit being sought here is for large archives to not
clog up the rendering process and cause unsightly proxy timeouts.
As a secondary benefit, archive-in-progress is moved out of the
way into a /tmp file so that new archival requests for the same
commit will not get fulfilled based on an archive that isn't yet
finished.
This asynchronous system is fairly primitive; request comes in, we'll
spawn off a new goroutine to handle it, then we'll mark it as done.
Status requests will see if the file exists in the final location,
and report the archival as done when it exists.
Fixes #11265
* Archive links: drop initial delay to three-quarters of a second
Some, or perhaps even most, archives will not take all that long to archive.
The archive process starts as soon as the download button is initially
clicked, so in theory they could be done quite quickly. Drop the initial
delay down to three-quarters of a second to make it more responsive in the
common case of the archive being quickly created.
* archiver: restructure a little bit to facilitate testing
This introduces two sync.Cond pointers to the archiver package. If they're
non-nil when we go to process a request, we'll wait until signalled (at all)
to proceed. The tests will then create the sync.Cond so that it can signal
at-will and sanity-check the state of the queue at different phases.
The author believes that nil-checking these two sync.Cond pointers on every
archive processing will introduce minimal overhead with no impact on
maintainability.
* gofmt nit: no space around binary + operator
* services: archiver: appease golangci-lint, lock queueMutex
Locking/unlocking the queueMutex is allowed, but not required, for
Cond.Signal() and Cond.Broadcast(). The magic at play here is just a little
too much for golangci-lint, as we take the address of queueMutex and this is
mostly used in archiver.go; the variable still gets flagged as unused.
* archiver: tests: fix several timing nits
Once we've signaled a cond var, it may take some small amount of time for
the goroutines released to hit the spot we're wanting them to be at. Give
them an appropriate amount of time.
* archiver: tests: no underscore in var name, ungh
* archiver: tests: Test* is run in a separate context than TestMain
We must setup the mutex/cond variables at the beginning of any test that's
going to use it, or else these will be nil when the test is actually ran.
* archiver: tests: hopefully final tweak
Things got shuffled around such that we carefully build up and release
requests from the queue, so we can validate the state of the queue at each
step. Fix some assertions that no longer hold true as fallout.
* repo: Download: restore some semblance of previous behavior
When archival was made async, the GET endpoint was only useful if a previous
POST had initiated the download. This commit restores the previous behavior,
to an extent; we'll now submit the archive request there and return a
"202 Accepted" to indicate that it's processing if we didn't manage to
complete the request within ~2 seconds of submission.
This lets a client directly GET the archive, and gives them some indication
that they may attempt to GET it again at a later time.
* archiver: tests: simplify a bit further
We don't need to risk failure and use time.ParseDuration to get 2 *
time.Second.
else if isn't really necessary if the conditions are simple enough and lead
to the same result.
* archiver: tests: resolve potential source of flakiness
Increase all timeouts to 10 seconds; these aren't hard-coded sleeps, so
there's no guarantee we'll actually take that long. If we need longer to
not have a false-positive, then so be it.
While here, various assert.{Not,}Equal arguments are flipped around so that
the wording in error output reflects reality, where the expected argument is
second and actual third.
* archiver: setup infrastructure for notifying consumers of completion
This API will *not* allow consumers to subscribe to specific requests being
completed, just *any* request being completed. The caller is responsible for
determining if their request is satisfied and waiting again if needed.
* repo: archive: make GET endpoint synchronous again
If the request isn't complete, this endpoint will now submit the request and
wait for completion using the new API. This may still be susceptible to
timeouts for larger repos, but other endpoints now exist that the web
interface will use to negotiate its way through larger archive processes.
* archiver: tests: amend test to include WaitForCompletion()
This is a trivial one, so go ahead and include it.
* archiver: tests: fix test by calling NewContext()
The mutex is otherwise uninitialized, so we need to ensure that we're
actually initializing it if we plan to test it.
* archiver: tests: integrate new WaitForCompletion a little better
We can use this to wait for archives to come in, rather than spinning and
hoping with a timeout.
* archiver: tests: combine numQueued declaration with next-instruction assignment
* routers: repo: reap unused archiving flag from DownloadStatus()
This had some planned usage before, indicating whether this request
initiated the archival process or not. After several rounds of refactoring,
this use was deemed not necessary for much of anything and got boiled down
to !complete in all cases.
* services: archiver: restructure to use a channel
We now offer two forms of waiting for a request:
- WaitForCompletion: wait for completion with no timeout
- TimedWaitForCompletion: wait for completion with timeout
In both cases, we wait for the given request's cchan to close; in the latter
case, we do so with the caller-provided timeout. This completely removes the
need for busy-wait loops in Download/InitiateDownload, as it's fairly clean
to wait on a channel with timeout.
* services: archiver: use defer to unlock now that we can
This previously carried the lock into the goroutine, but an intermediate
step just added the request to archiveInProgress outside of the new
goroutine and removed the need for the goroutine to start out with it.
* Revert "archiver: tests: combine numQueued declaration with next-instruction assignment"
This reverts commit bcc52140238e16680f2e05e448e9be51372afdf5.
Revert "archiver: tests: integrate new WaitForCompletion a little better"
This reverts commit 9fc8bedb5667d24d3a3c7843dc28a229efffb1e6.
Revert "archiver: tests: fix test by calling NewContext()"
This reverts commit 709c35685eaaf261ebbb7d3420e3376a4ee8e7f2.
Revert "archiver: tests: amend test to include WaitForCompletion()"
This reverts commit 75261f56bc05d1fa8ff7e81dcbc0ccd93fdc9d50.
* archiver: tests: first attempt at WaitForCompletion() tests
* archiver: tests: slight improvement, less busy-loop
Just wait for the requests to complete in order, instead of busy-waiting
with a timeout. This is slightly less fragile.
While here, reverse the arguments of a nearby assert.Equal() so that
expected/actual are correct in any test output.
* archiver: address lint nits
* services: archiver: only close the channel once
* services: archiver: use a struct{} for the wait channel
This makes it obvious that the channel is only being used as a signal,
rather than anything useful being piped through it.
* archiver: tests: fix expectations
Move the close of the channel into doArchive() itself; notably, before these
goroutines move on to waiting on the Release cond.
The tests are adjusted to reflect that we can't WaitForCompletion() after
they've already completed, as WaitForCompletion() doesn't indicate that
they've been released from the queue yet.
* archiver: tests: set cchan to nil for comparison
* archiver: move ctx.Error's back into the route handlers
We shouldn't be setting this in a service, we should just be validating the
request that we were handed.
* services: archiver: use regex to match a hash
This makes sure we don't try and use refName as a hash when it's clearly not
one, e.g. heads/pull/foo.
* routers: repo: remove the weird /archive/status endpoint
We don't need to do this anymore, we can just continue POSTing to the
archive/* endpoint until we're told the download's complete. This avoids a
potential naming conflict, where a ref could start with "status/"
* archiver: tests: bump reasonable timeout to 15s
* archiver: tests: actually release timedReq
* archiver: tests: run through inFlight instead of manually checking
While we're here, add a test for manually re-processing an archive that's
already been complete. Re-open the channel and mark it incomplete, so that
doArchive can just mark it complete again.
* initArchiveLinks: prevent default behavior from clicking
* archiver: alias gitea's context, golang context import pending
* archiver: simplify logic, just reconstruct slices
While the previous logic was perhaps slightly more efficient, the
new variant's readability is much improved.
* archiver: don't block shutdown on waiting for archive
The technique established launches a goroutine to do the wait,
which will close a wait channel upon termination. For the timeout
case, we also send back a value indicating whether the timeout was
hit or not.
The timeouts are expected to be relatively small, but still a multi-
second delay to shutdown due to this could be unfortunate.
* archiver: simplify shutdown logic
We can just grab the shutdown channel from the graceful manager instead of
constructing a channel to halt the caller and/or pass a result back.
* Style issues
* Fix mis-merge
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Co-authored-by: Lauris BH <lauris@nix.lv>
2020-11-07 20:27:28 +00:00
|
|
|
})
|
2014-03-22 17:50:50 +00:00
|
|
|
}
|
2022-04-07 18:59:56 +00:00
|
|
|
|
|
|
|
// SearchRepo repositories via options
|
|
|
|
func SearchRepo(ctx *context.Context) {
|
2022-06-06 08:01:49 +00:00
|
|
|
opts := &repo_model.SearchRepoOptions{
|
2022-04-07 18:59:56 +00:00
|
|
|
ListOptions: db.ListOptions{
|
|
|
|
Page: ctx.FormInt("page"),
|
|
|
|
PageSize: convert.ToCorrectPageSize(ctx.FormInt("limit")),
|
|
|
|
},
|
|
|
|
Actor: ctx.Doer,
|
|
|
|
Keyword: ctx.FormTrim("q"),
|
|
|
|
OwnerID: ctx.FormInt64("uid"),
|
|
|
|
PriorityOwnerID: ctx.FormInt64("priority_owner_id"),
|
|
|
|
TeamID: ctx.FormInt64("team_id"),
|
|
|
|
TopicOnly: ctx.FormBool("topic"),
|
|
|
|
Collaborate: util.OptionalBoolNone,
|
|
|
|
Private: ctx.IsSigned && (ctx.FormString("private") == "" || ctx.FormBool("private")),
|
|
|
|
Template: util.OptionalBoolNone,
|
|
|
|
StarredByID: ctx.FormInt64("starredBy"),
|
|
|
|
IncludeDescription: ctx.FormBool("includeDesc"),
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.FormString("template") != "" {
|
|
|
|
opts.Template = util.OptionalBoolOf(ctx.FormBool("template"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.FormBool("exclusive") {
|
|
|
|
opts.Collaborate = util.OptionalBoolFalse
|
|
|
|
}
|
|
|
|
|
|
|
|
mode := ctx.FormString("mode")
|
|
|
|
switch mode {
|
|
|
|
case "source":
|
|
|
|
opts.Fork = util.OptionalBoolFalse
|
|
|
|
opts.Mirror = util.OptionalBoolFalse
|
|
|
|
case "fork":
|
|
|
|
opts.Fork = util.OptionalBoolTrue
|
|
|
|
case "mirror":
|
|
|
|
opts.Mirror = util.OptionalBoolTrue
|
|
|
|
case "collaborative":
|
|
|
|
opts.Mirror = util.OptionalBoolFalse
|
|
|
|
opts.Collaborate = util.OptionalBoolTrue
|
|
|
|
case "":
|
|
|
|
default:
|
|
|
|
ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("Invalid search mode: \"%s\"", mode))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.FormString("archived") != "" {
|
|
|
|
opts.Archived = util.OptionalBoolOf(ctx.FormBool("archived"))
|
|
|
|
}
|
|
|
|
|
|
|
|
if ctx.FormString("is_private") != "" {
|
|
|
|
opts.IsPrivate = util.OptionalBoolOf(ctx.FormBool("is_private"))
|
|
|
|
}
|
|
|
|
|
|
|
|
sortMode := ctx.FormString("sort")
|
|
|
|
if len(sortMode) > 0 {
|
|
|
|
sortOrder := ctx.FormString("order")
|
|
|
|
if len(sortOrder) == 0 {
|
|
|
|
sortOrder = "asc"
|
|
|
|
}
|
2023-05-08 09:36:54 +00:00
|
|
|
if searchModeMap, ok := repo_model.SearchOrderByMap[sortOrder]; ok {
|
2022-04-07 18:59:56 +00:00
|
|
|
if orderBy, ok := searchModeMap[sortMode]; ok {
|
|
|
|
opts.OrderBy = orderBy
|
|
|
|
} else {
|
|
|
|
ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("Invalid sort mode: \"%s\"", sortMode))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ctx.Error(http.StatusUnprocessableEntity, fmt.Sprintf("Invalid sort order: \"%s\"", sortOrder))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var err error
|
2022-11-19 08:12:33 +00:00
|
|
|
repos, count, err := repo_model.SearchRepository(ctx, opts)
|
2022-04-07 18:59:56 +00:00
|
|
|
if err != nil {
|
|
|
|
ctx.JSON(http.StatusInternalServerError, api.SearchError{
|
|
|
|
OK: false,
|
|
|
|
Error: err.Error(),
|
|
|
|
})
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-04-26 20:34:30 +00:00
|
|
|
ctx.SetTotalCountHeader(count)
|
|
|
|
|
|
|
|
// To improve performance when only the count is requested
|
|
|
|
if ctx.FormBool("count_only") {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-13 21:59:01 +00:00
|
|
|
// collect the latest commit of each repo
|
2023-05-14 13:45:47 +00:00
|
|
|
// at most there are dozens of repos (limited by MaxResponseItems), so it's not a big problem at the moment
|
2023-07-03 01:53:05 +00:00
|
|
|
repoBranchNames := make(map[int64]string, len(repos))
|
2023-05-13 21:59:01 +00:00
|
|
|
for _, repo := range repos {
|
2023-07-03 01:53:05 +00:00
|
|
|
repoBranchNames[repo.ID] = repo.DefaultBranch
|
|
|
|
}
|
|
|
|
|
|
|
|
repoIDsToLatestCommitSHAs, err := git_model.FindBranchesByRepoAndBranchName(ctx, repoBranchNames)
|
|
|
|
if err != nil {
|
|
|
|
log.Error("FindBranchesByRepoAndBranchName: %v", err)
|
|
|
|
return
|
2023-05-13 21:59:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// call the database O(1) times to get the commit statuses for all repos
|
2023-12-11 06:19:57 +00:00
|
|
|
repoToItsLatestCommitStatuses, err := git_model.GetLatestCommitStatusForPairs(ctx, repoIDsToLatestCommitSHAs, db.ListOptionsAll)
|
2023-05-13 21:59:01 +00:00
|
|
|
if err != nil {
|
|
|
|
log.Error("GetLatestCommitStatusForPairs: %v", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
results := make([]*repo_service.WebSearchRepository, len(repos))
|
2022-04-07 18:59:56 +00:00
|
|
|
for i, repo := range repos {
|
2023-08-21 07:26:10 +00:00
|
|
|
latestCommitStatus := git_model.CalcCommitStatus(repoToItsLatestCommitStatuses[repo.ID])
|
|
|
|
|
2023-05-13 21:59:01 +00:00
|
|
|
results[i] = &repo_service.WebSearchRepository{
|
|
|
|
Repository: &api.Repository{
|
|
|
|
ID: repo.ID,
|
|
|
|
FullName: repo.FullName(),
|
|
|
|
Fork: repo.IsFork,
|
|
|
|
Private: repo.IsPrivate,
|
|
|
|
Template: repo.IsTemplate,
|
|
|
|
Mirror: repo.IsMirror,
|
|
|
|
Stars: repo.NumStars,
|
|
|
|
HTMLURL: repo.HTMLURL(),
|
|
|
|
Link: repo.Link(),
|
|
|
|
Internal: !repo.IsPrivate && repo.Owner.Visibility == api.VisibleTypePrivate,
|
|
|
|
},
|
2023-08-21 07:26:10 +00:00
|
|
|
LatestCommitStatus: latestCommitStatus,
|
|
|
|
LocaleLatestCommitStatus: latestCommitStatus.LocaleString(ctx.Locale),
|
2022-04-07 18:59:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-13 21:59:01 +00:00
|
|
|
ctx.JSON(http.StatusOK, repo_service.WebSearchResults{
|
2022-04-07 18:59:56 +00:00
|
|
|
OK: true,
|
|
|
|
Data: results,
|
|
|
|
})
|
|
|
|
}
|
2023-07-21 11:20:04 +00:00
|
|
|
|
|
|
|
type branchTagSearchResponse struct {
|
|
|
|
Results []string `json:"results"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBranchesList get branches for current repo'
|
|
|
|
func GetBranchesList(ctx *context.Context) {
|
|
|
|
branchOpts := git_model.FindBranchOptions{
|
|
|
|
RepoID: ctx.Repo.Repository.ID,
|
|
|
|
IsDeletedBranch: util.OptionalBoolFalse,
|
|
|
|
ListOptions: db.ListOptions{
|
|
|
|
ListAll: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
branches, err := git_model.FindBranchNames(ctx, branchOpts)
|
|
|
|
if err != nil {
|
|
|
|
ctx.JSON(http.StatusInternalServerError, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp := &branchTagSearchResponse{}
|
|
|
|
// always put default branch on the top if it exists
|
2023-09-07 09:37:47 +00:00
|
|
|
if slices.Contains(branches, ctx.Repo.Repository.DefaultBranch) {
|
2023-07-21 11:20:04 +00:00
|
|
|
branches = util.SliceRemoveAll(branches, ctx.Repo.Repository.DefaultBranch)
|
|
|
|
branches = append([]string{ctx.Repo.Repository.DefaultBranch}, branches...)
|
|
|
|
}
|
|
|
|
resp.Results = branches
|
|
|
|
ctx.JSON(http.StatusOK, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetTagList get tag list for current repo
|
|
|
|
func GetTagList(ctx *context.Context) {
|
|
|
|
tags, err := repo_model.GetTagNamesByRepoID(ctx, ctx.Repo.Repository.ID)
|
|
|
|
if err != nil {
|
|
|
|
ctx.JSON(http.StatusInternalServerError, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
resp := &branchTagSearchResponse{}
|
|
|
|
resp.Results = tags
|
|
|
|
ctx.JSON(http.StatusOK, resp)
|
|
|
|
}
|
|
|
|
|
|
|
|
func PrepareBranchList(ctx *context.Context) {
|
|
|
|
branchOpts := git_model.FindBranchOptions{
|
|
|
|
RepoID: ctx.Repo.Repository.ID,
|
|
|
|
IsDeletedBranch: util.OptionalBoolFalse,
|
|
|
|
ListOptions: db.ListOptions{
|
|
|
|
ListAll: true,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
brs, err := git_model.FindBranchNames(ctx, branchOpts)
|
|
|
|
if err != nil {
|
|
|
|
ctx.ServerError("GetBranches", err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
// always put default branch on the top if it exists
|
2023-09-07 09:37:47 +00:00
|
|
|
if slices.Contains(brs, ctx.Repo.Repository.DefaultBranch) {
|
2023-07-21 11:20:04 +00:00
|
|
|
brs = util.SliceRemoveAll(brs, ctx.Repo.Repository.DefaultBranch)
|
|
|
|
brs = append([]string{ctx.Repo.Repository.DefaultBranch}, brs...)
|
|
|
|
}
|
|
|
|
ctx.Data["Branches"] = brs
|
|
|
|
}
|