Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify repo settings & show better error #19828

Merged
merged 9 commits into from
Jun 12, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion routers/web/repo/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package repo

import (
"fmt"
"net/http"
"net/url"
"strings"
Expand Down Expand Up @@ -128,7 +129,7 @@ func handleMigrateRemoteAddrError(ctx *context.Context, err error, tpl base.TplN
case addrErr.IsProtocolInvalid:
ctx.RenderWithErr(ctx.Tr("repo.mirror_address_protocol_invalid"), tpl, form)
case addrErr.IsURLError:
ctx.RenderWithErr(ctx.Tr("form.url_error"), tpl, form)
ctx.RenderWithErr(fmt.Sprintf("%q%s", addrErr.Host, ctx.Tr("form.url_error")), tpl, form)
Gusted marked this conversation as resolved.
Show resolved Hide resolved
case addrErr.IsPermissionDenied:
if addrErr.LocalPath {
ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tpl, form)
Expand Down
12 changes: 7 additions & 5 deletions routers/web/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ const (
tplProtectedBranch base.TplName = "repo/settings/protected_branch"
)

// Settings show a repository's settings page
func Settings(ctx *context.Context) {
// SettingsCtxData is a middleware that sets all the general context data for the
// settings template.
func SettingsCtxData(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsOptions"] = true
ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate
Expand Down Expand Up @@ -92,15 +93,16 @@ func Settings(ctx *context.Context) {
return
}
ctx.Data["PushMirrors"] = pushMirrors
}

// Settings show a repository's settings page
func Settings(ctx *context.Context) {
ctx.HTML(http.StatusOK, tplSettingsOptions)
}

// SettingsPost response for changes of a repository
func SettingsPost(ctx *context.Context) {
form := web.GetForm(ctx).(*forms.RepoSettingForm)
zeripath marked this conversation as resolved.
Show resolved Hide resolved
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsOptions"] = true

repo := ctx.Repo.Repository

Expand Down Expand Up @@ -811,7 +813,7 @@ func handleSettingRemoteAddrError(ctx *context.Context, err error, form *forms.R
case addrErr.IsProtocolInvalid:
ctx.RenderWithErr(ctx.Tr("repo.mirror_address_protocol_invalid"), tplSettingsOptions, form)
case addrErr.IsURLError:
ctx.RenderWithErr(ctx.Tr("form.url_error"), tplSettingsOptions, form)
ctx.RenderWithErr(fmt.Sprintf("%q%s", addrErr.Host, ctx.Tr("form.url_error")), tplSettingsOptions, form)
Gusted marked this conversation as resolved.
Show resolved Hide resolved
case addrErr.IsPermissionDenied:
if addrErr.LocalPath {
ctx.RenderWithErr(ctx.Tr("repo.migrate.permission_denied"), tplSettingsOptions, form)
Expand Down
6 changes: 4 additions & 2 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -730,8 +730,10 @@ func RegisterRoutes(m *web.Route) {

m.Group("/{username}/{reponame}", func() {
m.Group("/settings", func() {
m.Combo("").Get(repo.Settings).
Post(bindIgnErr(forms.RepoSettingForm{}), repo.SettingsPost)
m.Group("", func() {
m.Combo("").Get(repo.Settings).
Post(bindIgnErr(forms.RepoSettingForm{}), repo.SettingsPost)
}, repo.SettingsCtxData)
m.Post("/avatar", bindIgnErr(forms.AvatarForm{}), repo.SettingsAvatar)
m.Post("/avatar/delete", repo.SettingsDeleteAvatar)

Expand Down
2 changes: 1 addition & 1 deletion services/forms/repo_form.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func ParseRemoteAddr(remoteAddr, authUsername, authPassword string) (string, err
strings.HasPrefix(remoteAddr, "git://") {
u, err := url.Parse(remoteAddr)
if err != nil {
return "", &models.ErrInvalidCloneAddr{IsURLError: true}
return "", &models.ErrInvalidCloneAddr{IsURLError: true, Host: remoteAddr}
}
if len(authUsername)+len(authPassword) > 0 {
u.User = url.UserPassword(authUsername, authPassword)
Expand Down
2 changes: 1 addition & 1 deletion services/migrations/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func IsMigrateURLAllowed(remoteURL string, doer *user_model.User) error {
// Remote address can be HTTP/HTTPS/Git URL or local path.
u, err := url.Parse(remoteURL)
if err != nil {
return &models.ErrInvalidCloneAddr{IsURLError: true}
return &models.ErrInvalidCloneAddr{IsURLError: true, Host: remoteURL}
}

if u.Scheme == "file" || u.Scheme == "" {
Expand Down