Skip to content

Commit f0522e1

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Fix install page context, make the install page tests really test (go-gitea#24858) Add validations.required check to dropdown field (go-gitea#24849) Use Go 1.20 for next release (go-gitea#24859) Add gitea manager reload-templates command (go-gitea#24843) Remove `In your repositories` link in milestones dashboard (go-gitea#24853) Fix 500 error when select `No assignee` filter in issue list page (go-gitea#24854) Add IsErrRepoFilesAlreadyExist check when fork repo (go-gitea#24678) Fix missing yes/no in delete time log modal (go-gitea#24851) Fix document and improve comment (go-gitea#24844) # Conflicts: # web_src/css/base.css
2 parents 5884e1e + abcf5a7 commit f0522e1

File tree

24 files changed

+135
-57
lines changed

24 files changed

+135
-57
lines changed

cmd/manager.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ var (
2121
Subcommands: []cli.Command{
2222
subcmdShutdown,
2323
subcmdRestart,
24+
subcmdReloadTemplates,
2425
subcmdFlushQueues,
2526
subcmdLogging,
2627
subCmdProcesses,
@@ -46,6 +47,16 @@ var (
4647
},
4748
Action: runRestart,
4849
}
50+
subcmdReloadTemplates = cli.Command{
51+
Name: "reload-templates",
52+
Usage: "Reload template files in the running process",
53+
Flags: []cli.Flag{
54+
cli.BoolFlag{
55+
Name: "debug",
56+
},
57+
},
58+
Action: runReloadTemplates,
59+
}
4960
subcmdFlushQueues = cli.Command{
5061
Name: "flush-queues",
5162
Usage: "Flush queues in the running process",
@@ -115,6 +126,15 @@ func runRestart(c *cli.Context) error {
115126
return handleCliResponseExtra(extra)
116127
}
117128

129+
func runReloadTemplates(c *cli.Context) error {
130+
ctx, cancel := installSignals()
131+
defer cancel()
132+
133+
setup(ctx, c.Bool("debug"))
134+
extra := private.ReloadTemplates(ctx)
135+
return handleCliResponseExtra(extra)
136+
}
137+
118138
func runFlushQueues(c *cli.Context) error {
119139
ctx, cancel := installSignals()
120140
defer cancel()

cmd/web.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,10 +142,8 @@ func runWeb(ctx *cli.Context) error {
142142
return err
143143
}
144144
}
145-
installCtx, cancel := context.WithCancel(graceful.GetManager().HammerContext())
146-
c := install.Routes(installCtx)
145+
c := install.Routes()
147146
err := listen(c, false)
148-
cancel()
149147
if err != nil {
150148
log.Critical("Unable to open listener for installer. Is Gitea already running?")
151149
graceful.GetManager().DoGracefulShutdown()

docs/config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ params:
1818
description: Git with a cup of tea
1919
author: The Gitea Authors
2020
website: https://docs.gitea.io
21-
version: 1.19.0
22-
minGoVersion: 1.19
21+
version: 1.19.0 # FIXME: this version was used as "latest stable release", but it always gets outdated and doesn't make sense
22+
minGoVersion: 1.20
2323
goVersion: 1.20
2424
minNodeVersion: 16
2525
search: nav

docs/content/doc/help/faq.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ A "login prohibited" user is a user that is not allowed to log in to Gitea anymo
136136

137137
## Setting up logging
138138

139-
- [Official Docs]({{< relref "doc/administration/logging-documentation.en-us.md" >}})
139+
- [Official Docs]({{< relref "doc/administration/logging-config.en-us.md" >}})
140140

141141
## What is Swagger?
142142

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module code.gitea.io/gitea
22

3-
go 1.19
3+
go 1.20
44

55
require (
66
code.gitea.io/actions-proto-go v0.2.1

models/issues/issue_stats.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ func getIssueStatsChunk(opts *IssuesOptions, issueIDs []int64) (*IssueStats, err
141141
if opts.AssigneeID > 0 {
142142
applyAssigneeCondition(sess, opts.AssigneeID)
143143
} else if opts.AssigneeID == db.NoConditionID {
144-
sess.Where("id NOT IN (SELECT issue_id FROM issue_assignees)")
144+
sess.Where("issue.id NOT IN (SELECT issue_id FROM issue_assignees)")
145145
}
146146

147147
if opts.PosterID > 0 {

modules/context/context.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,12 @@ func (ctx *Context) TrHTMLEscapeArgs(msg string, args ...string) string {
6868
return ctx.Locale.Tr(msg, trArgs...)
6969
}
7070

71-
type contextKeyType struct{}
71+
type webContextKeyType struct{}
7272

73-
var contextKey interface{} = contextKeyType{}
73+
var WebContextKey = webContextKeyType{}
7474

75-
func GetContext(req *http.Request) *Context {
76-
ctx, _ := req.Context().Value(contextKey).(*Context)
75+
func GetWebContext(req *http.Request) *Context {
76+
ctx, _ := req.Context().Value(WebContextKey).(*Context)
7777
return ctx
7878
}
7979

@@ -86,7 +86,7 @@ type ValidateContext struct {
8686
func GetValidateContext(req *http.Request) (ctx *ValidateContext) {
8787
if ctxAPI, ok := req.Context().Value(apiContextKey).(*APIContext); ok {
8888
ctx = &ValidateContext{Base: ctxAPI.Base}
89-
} else if ctxWeb, ok := req.Context().Value(contextKey).(*Context); ok {
89+
} else if ctxWeb, ok := req.Context().Value(WebContextKey).(*Context); ok {
9090
ctx = &ValidateContext{Base: ctxWeb.Base}
9191
} else {
9292
panic("invalid context, expect either APIContext or Context")
@@ -135,7 +135,7 @@ func Contexter() func(next http.Handler) http.Handler {
135135
ctx.PageData = map[string]any{}
136136
ctx.Data["PageData"] = ctx.PageData
137137

138-
ctx.Base.AppendContextValue(contextKey, ctx)
138+
ctx.Base.AppendContextValue(WebContextKey, ctx)
139139
ctx.Base.AppendContextValueFunc(git.RepositoryContextKey, func() any { return ctx.Repo.GitRepo })
140140

141141
ctx.Csrf = PrepareCSRFProtector(csrfOpts, ctx)

modules/context/package.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ func PackageContexter() func(next http.Handler) http.Handler {
150150
}
151151
defer baseCleanUp()
152152

153-
ctx.Base.AppendContextValue(contextKey, ctx)
153+
ctx.Base.AppendContextValue(WebContextKey, ctx)
154154
next.ServeHTTP(ctx.Resp, ctx.Req)
155155
})
156156
}

modules/private/manager.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ func Restart(ctx context.Context) ResponseExtra {
2929
return requestJSONClientMsg(req, "Restarting")
3030
}
3131

32+
// ReloadTemplates calls the internal reload-templates function
33+
func ReloadTemplates(ctx context.Context) ResponseExtra {
34+
reqURL := setting.LocalURL + "api/internal/manager/reload-templates"
35+
req := newInternalRequest(ctx, reqURL, "POST")
36+
return requestJSONClientMsg(req, "Reloaded")
37+
}
38+
3239
// FlushOptions represents the options for the flush call
3340
type FlushOptions struct {
3441
Timeout time.Duration

modules/templates/htmlrenderer.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ func HTMLRenderer() *HTMLRender {
9696
return htmlRender
9797
}
9898

99+
func ReloadHTMLTemplates() error {
100+
if err := htmlRender.CompileTemplates(); err != nil {
101+
log.Error("Template error: %v\n%s", err, log.Stack(2))
102+
return err
103+
}
104+
return nil
105+
}
106+
99107
func initHTMLRenderer() {
100108
rendererType := "static"
101109
if !setting.IsProd {
@@ -115,9 +123,7 @@ func initHTMLRenderer() {
115123

116124
if !setting.IsProd {
117125
go AssetFS().WatchLocalChanges(graceful.GetManager().ShutdownContext(), func() {
118-
if err := htmlRender.CompileTemplates(); err != nil {
119-
log.Error("Template error: %v\n%s", err, log.Stack(2))
120-
}
126+
_ = ReloadHTMLTemplates()
121127
})
122128
}
123129
}

modules/web/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ type ResponseStatusProvider interface {
2222
// TODO: decouple this from the context package, let the context package register these providers
2323
var argTypeProvider = map[reflect.Type]func(req *http.Request) ResponseStatusProvider{
2424
reflect.TypeOf(&context.APIContext{}): func(req *http.Request) ResponseStatusProvider { return context.GetAPIContext(req) },
25-
reflect.TypeOf(&context.Context{}): func(req *http.Request) ResponseStatusProvider { return context.GetContext(req) },
25+
reflect.TypeOf(&context.Context{}): func(req *http.Request) ResponseStatusProvider { return context.GetWebContext(req) },
2626
reflect.TypeOf(&context.PrivateContext{}): func(req *http.Request) ResponseStatusProvider { return context.GetPrivateContext(req) },
2727
}
2828

routers/api/v1/repo/fork.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
package repo
66

77
import (
8+
"errors"
89
"fmt"
910
"net/http"
1011

@@ -15,6 +16,7 @@ import (
1516
user_model "code.gitea.io/gitea/models/user"
1617
"code.gitea.io/gitea/modules/context"
1718
api "code.gitea.io/gitea/modules/structs"
19+
"code.gitea.io/gitea/modules/util"
1820
"code.gitea.io/gitea/modules/web"
1921
"code.gitea.io/gitea/routers/api/v1/utils"
2022
"code.gitea.io/gitea/services/convert"
@@ -141,7 +143,7 @@ func CreateFork(ctx *context.APIContext) {
141143
Description: repo.Description,
142144
})
143145
if err != nil {
144-
if repo_service.IsErrForkAlreadyExist(err) || repo_model.IsErrRepoAlreadyExist(err) || repo_model.IsErrReachLimitOfRepo(err) {
146+
if errors.Is(err, util.ErrAlreadyExist) || repo_model.IsErrReachLimitOfRepo(err) {
145147
ctx.Error(http.StatusConflict, "ForkRepository", err)
146148
} else {
147149
ctx.Error(http.StatusInternalServerError, "ForkRepository", err)

routers/install/install.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,15 @@ func Contexter() func(next http.Handler) http.Handler {
5959
return func(next http.Handler) http.Handler {
6060
return http.HandlerFunc(func(resp http.ResponseWriter, req *http.Request) {
6161
base, baseCleanUp := context.NewBaseContext(resp, req)
62-
ctx := context.Context{
62+
ctx := &context.Context{
6363
Base: base,
6464
Flash: &middleware.Flash{},
6565
Render: rnd,
6666
Session: session.GetSession(req),
6767
}
6868
defer baseCleanUp()
6969

70+
ctx.AppendContextValue(context.WebContextKey, ctx)
7071
ctx.Data.MergeFrom(middleware.CommonTemplateContextData())
7172
ctx.Data.MergeFrom(middleware.ContextData{
7273
"locale": ctx.Locale,

routers/install/routes.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
package install
55

66
import (
7-
goctx "context"
87
"fmt"
98
"html"
109
"net/http"
@@ -18,7 +17,7 @@ import (
1817
)
1918

2019
// Routes registers the installation routes
21-
func Routes(ctx goctx.Context) *web.Route {
20+
func Routes() *web.Route {
2221
base := web.NewRoute()
2322
base.Use(common.ProtocolMiddlewares()...)
2423
base.RouteMethods("/assets/*", "GET, HEAD", public.AssetsHandlerFunc("/assets/"))

routers/install/routes_test.go

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,41 @@
1-
// Copyright 2021 The Gitea Authors. All rights reserved.
1+
// Copyright 2023 The Gitea Authors. All rights reserved.
22
// SPDX-License-Identifier: MIT
33

44
package install
55

66
import (
7-
"context"
7+
"net/http/httptest"
8+
"path/filepath"
89
"testing"
910

11+
"code.gitea.io/gitea/models/unittest"
12+
1013
"github.com/stretchr/testify/assert"
1114
)
1215

1316
func TestRoutes(t *testing.T) {
14-
// TODO: this test seems not really testing the handlers
15-
ctx, cancel := context.WithCancel(context.Background())
16-
defer cancel()
17-
base := Routes(ctx)
18-
assert.NotNil(t, base)
19-
r := base.R.Routes()[1]
20-
routes := r.SubRoutes.Routes()[0]
21-
assert.EqualValues(t, "/", routes.Pattern)
22-
assert.Nil(t, routes.SubRoutes)
23-
assert.Len(t, routes.Handlers, 2)
17+
r := Routes()
18+
assert.NotNil(t, r)
19+
20+
w := httptest.NewRecorder()
21+
req := httptest.NewRequest("GET", "/", nil)
22+
r.ServeHTTP(w, req)
23+
assert.EqualValues(t, 200, w.Code)
24+
assert.Contains(t, w.Body.String(), `class="page-content install"`)
25+
26+
w = httptest.NewRecorder()
27+
req = httptest.NewRequest("GET", "/no-such", nil)
28+
r.ServeHTTP(w, req)
29+
assert.EqualValues(t, 404, w.Code)
30+
31+
w = httptest.NewRecorder()
32+
req = httptest.NewRequest("GET", "/assets/img/gitea.svg", nil)
33+
r.ServeHTTP(w, req)
34+
assert.EqualValues(t, 200, w.Code)
35+
}
36+
37+
func TestMain(m *testing.M) {
38+
unittest.MainTest(m, &unittest.TestOptions{
39+
GiteaRootPath: filepath.Join("..", ".."),
40+
})
2441
}

routers/private/internal.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func Routes() *web.Route {
6767
r.Get("/serv/command/{keyid}/{owner}/{repo}", ServCommand)
6868
r.Post("/manager/shutdown", Shutdown)
6969
r.Post("/manager/restart", Restart)
70+
r.Post("/manager/reload-templates", ReloadTemplates)
7071
r.Post("/manager/flush-queues", bind(private.FlushOptions{}), FlushQueues)
7172
r.Post("/manager/pause-logging", PauseLogging)
7273
r.Post("/manager/resume-logging", ResumeLogging)

routers/private/manager.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,22 @@ import (
1515
"code.gitea.io/gitea/modules/private"
1616
"code.gitea.io/gitea/modules/queue"
1717
"code.gitea.io/gitea/modules/setting"
18+
"code.gitea.io/gitea/modules/templates"
1819
"code.gitea.io/gitea/modules/web"
1920
)
2021

22+
// ReloadTemplates reloads all the templates
23+
func ReloadTemplates(ctx *context.PrivateContext) {
24+
err := templates.ReloadHTMLTemplates()
25+
if err != nil {
26+
ctx.JSON(http.StatusInternalServerError, private.Response{
27+
UserMsg: fmt.Sprintf("Template error: %v", err),
28+
})
29+
return
30+
}
31+
ctx.PlainText(http.StatusOK, "success")
32+
}
33+
2134
// FlushQueues flushes all the Queues
2235
func FlushQueues(ctx *context.PrivateContext) {
2336
opts := web.GetForm(ctx).(*private.FlushOptions)

routers/web/repo/pull.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,17 @@ func ForkPost(ctx *context.Context) {
272272
ctx.RenderWithErr(msg, tplFork, &form)
273273
case repo_model.IsErrRepoAlreadyExist(err):
274274
ctx.RenderWithErr(ctx.Tr("repo.settings.new_owner_has_same_repo"), tplFork, &form)
275+
case repo_model.IsErrRepoFilesAlreadyExist(err):
276+
switch {
277+
case ctx.IsUserSiteAdmin() || (setting.Repository.AllowAdoptionOfUnadoptedRepositories && setting.Repository.AllowDeleteOfUnadoptedRepositories):
278+
ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist.adopt_or_delete"), tplFork, form)
279+
case setting.Repository.AllowAdoptionOfUnadoptedRepositories:
280+
ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist.adopt"), tplFork, form)
281+
case setting.Repository.AllowDeleteOfUnadoptedRepositories:
282+
ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist.delete"), tplFork, form)
283+
default:
284+
ctx.RenderWithErr(ctx.Tr("form.repository_files_already_exist"), tplFork, form)
285+
}
275286
case db.IsErrNameReserved(err):
276287
ctx.RenderWithErr(ctx.Tr("repo.form.name_reserved", err.(db.ErrNameReserved).Name), tplFork, &form)
277288
case db.IsErrNamePatternNotAllowed(err):

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1405,7 +1405,7 @@ func registerRoutes(m *web.Route) {
14051405
}
14061406

14071407
m.NotFound(func(w http.ResponseWriter, req *http.Request) {
1408-
ctx := context.GetContext(req)
1408+
ctx := context.GetWebContext(req)
14091409
ctx.NotFound("", nil)
14101410
})
14111411
}

services/auth/auth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func handleSignIn(resp http.ResponseWriter, req *http.Request, sess SessionStore
9292
middleware.SetLocaleCookie(resp, user.Language, 0)
9393

9494
// Clear whatever CSRF has right now, force to generate a new one
95-
if ctx := gitea_context.GetContext(req); ctx != nil {
95+
if ctx := gitea_context.GetWebContext(req); ctx != nil {
9696
ctx.Csrf.DeleteCookie(ctx)
9797
}
9898
}

templates/repo/issue/fields/dropdown.tmpl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
<div class="ui fluid selection dropdown {{if .item.Attributes.multiple}}multiple clearable{{end}}">
55
<input type="hidden" name="form-field-{{.item.ID}}" value="0">
66
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
7+
{{if not .item.Validations.required}}
78
{{svg "octicon-x" 14 "remove icon"}}
9+
{{end}}
810
<div class="default text"></div>
911
<div class="menu">
1012
{{range $i, $opt := .item.Attributes.options}}

templates/repo/issue/view_content/comments_delete_time.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
{{.ctxData.CsrfTokenHtml}}
88
</form>
99
<div class="header">{{.ctxData.locale.Tr "repo.issues.del_time"}}</div>
10-
{{template "base/modal_actions_confirm" .}}
10+
{{template "base/modal_actions_confirm" (dict "locale" .ctxData.locale)}}
1111
</div>
1212
<button class="ui icon button compact mini issue-delete-time" data-id="{{.comment.Time.ID}}" data-tooltip-content="{{.ctxData.locale.Tr "repo.issues.del_time"}}">
1313
{{svg "octicon-trash"}}

templates/user/dashboard/milestones.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<div class="ui stackable grid">
66
<div class="four wide column">
77
<div class="ui secondary vertical filter menu gt-bg-transparent">
8-
<a class="item" href="{{.Link}}?type=your_repositories&sort={{$.SortType}}&state={{.State}}&q={{$.Keyword}}">
8+
<div class="item">
99
{{.locale.Tr "home.issues.in_your_repos"}}
1010
<strong class="ui right">{{.Total}}</strong>
11-
</a>
11+
</div>
1212
<div class="ui divider"></div>
1313
{{range .Repos}}
1414
{{with $Repo := .}}

0 commit comments

Comments
 (0)