aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2025-07-05 23:19:33 +0800
committerGitHub <noreply@github.com>2025-07-05 23:19:33 +0800
commit6033c67a1aa8516e9ee6619b4b640fd92ae3b4ce (patch)
treedf5f5f1e1fb1b0718ce9f0cc4cec2b0e64f2c4b2
parent555735936f2399b6c45106751137df50bf8e757e (diff)
downloadgitea-6033c67a1aa8516e9ee6619b4b640fd92ae3b4ce.tar.gz
gitea-6033c67a1aa8516e9ee6619b4b640fd92ae3b4ce.zip
Refactor some trivial problems (#34959)
1. make our "route group pattern match" also update chi's RoutePattern 2. fix incorrect "NotFound" call in conda package 3. make ".flex-item .flex-item-main" has a general gap, then no need to use `tw` tricks 4. improve the "test webhook" UI
-rw-r--r--modules/web/router_path.go7
-rw-r--r--modules/web/router_test.go39
-rw-r--r--options/locale/locale_en-US.ini4
-rw-r--r--routers/api/packages/conda/conda.go2
-rw-r--r--templates/devtest/flex-list.tmpl2
-rw-r--r--templates/repo/settings/webhook/history.tmpl2
-rw-r--r--templates/shared/issuelist.tmpl2
-rw-r--r--web_src/css/shared/flex-list.css1
8 files changed, 39 insertions, 20 deletions
diff --git a/modules/web/router_path.go b/modules/web/router_path.go
index ce041eedab..64154c34a5 100644
--- a/modules/web/router_path.go
+++ b/modules/web/router_path.go
@@ -26,6 +26,7 @@ func (g *RouterPathGroup) ServeHTTP(resp http.ResponseWriter, req *http.Request)
path := chiCtx.URLParam(g.pathParam)
for _, m := range g.matchers {
if m.matchPath(chiCtx, path) {
+ chiCtx.RoutePatterns = append(chiCtx.RoutePatterns, m.pattern)
handler := m.handlerFunc
for i := len(m.middlewares) - 1; i >= 0; i-- {
handler = m.middlewares[i](handler).ServeHTTP
@@ -38,6 +39,7 @@ func (g *RouterPathGroup) ServeHTTP(resp http.ResponseWriter, req *http.Request)
}
type RouterPathGroupPattern struct {
+ pattern string
re *regexp.Regexp
params []routerPathParam
middlewares []any
@@ -62,6 +64,7 @@ type routerPathParam struct {
type routerPathMatcher struct {
methods container.Set[string]
+ pattern string
re *regexp.Regexp
params []routerPathParam
middlewares []func(http.Handler) http.Handler
@@ -117,7 +120,7 @@ func newRouterPathMatcher(methods string, patternRegexp *RouterPathGroupPattern,
}
p.methods.Add(method)
}
- p.re, p.params = patternRegexp.re, patternRegexp.params
+ p.pattern, p.re, p.params = patternRegexp.pattern, patternRegexp.re, patternRegexp.params
return p
}
@@ -157,7 +160,7 @@ func patternRegexp(pattern string, h ...any) *RouterPathGroupPattern {
p.params = append(p.params, param)
}
re = append(re, '$')
- p.re = regexp.MustCompile(string(re))
+ p.pattern, p.re = pattern, regexp.MustCompile(string(re))
return p
}
diff --git a/modules/web/router_test.go b/modules/web/router_test.go
index 1cee2b879b..f216aa6180 100644
--- a/modules/web/router_test.go
+++ b/modules/web/router_test.go
@@ -56,17 +56,20 @@ func TestRouter(t *testing.T) {
recorder.Body = buff
type resultStruct struct {
- method string
- pathParams map[string]string
- handlerMarks []string
+ method string
+ pathParams map[string]string
+ handlerMarks []string
+ chiRoutePattern *string
}
var res resultStruct
h := func(optMark ...string) func(resp http.ResponseWriter, req *http.Request) {
mark := util.OptionalArg(optMark, "")
return func(resp http.ResponseWriter, req *http.Request) {
+ chiCtx := chi.RouteContext(req.Context())
res.method = req.Method
- res.pathParams = chiURLParamsToMap(chi.RouteContext(req.Context()))
+ res.pathParams = chiURLParamsToMap(chiCtx)
+ res.chiRoutePattern = util.ToPointer(chiCtx.RoutePattern())
if mark != "" {
res.handlerMarks = append(res.handlerMarks, mark)
}
@@ -125,21 +128,29 @@ func TestRouter(t *testing.T) {
req, err := http.NewRequest(methodPathFields[0], methodPathFields[1], nil)
assert.NoError(t, err)
r.ServeHTTP(recorder, req)
+ if expected.chiRoutePattern == nil {
+ res.chiRoutePattern = nil
+ }
assert.Equal(t, expected, res)
})
}
t.Run("RootRouter", func(t *testing.T) {
- testRoute(t, "GET /the-user/the-repo/other", resultStruct{method: "GET", handlerMarks: []string{"not-found:/"}})
+ testRoute(t, "GET /the-user/the-repo/other", resultStruct{
+ method: "GET",
+ handlerMarks: []string{"not-found:/"},
+ chiRoutePattern: util.ToPointer(""),
+ })
testRoute(t, "GET /the-user/the-repo/pulls", resultStruct{
method: "GET",
pathParams: map[string]string{"username": "the-user", "reponame": "the-repo", "type": "pulls"},
handlerMarks: []string{"list-issues-b"},
})
testRoute(t, "GET /the-user/the-repo/issues/123", resultStruct{
- method: "GET",
- pathParams: map[string]string{"username": "the-user", "reponame": "the-repo", "type": "issues", "index": "123"},
- handlerMarks: []string{"view-issue"},
+ method: "GET",
+ pathParams: map[string]string{"username": "the-user", "reponame": "the-repo", "type": "issues", "index": "123"},
+ handlerMarks: []string{"view-issue"},
+ chiRoutePattern: util.ToPointer("/{username}/{reponame}/{type:issues|pulls}/{index}"),
})
testRoute(t, "GET /the-user/the-repo/issues/123?stop=hijack", resultStruct{
method: "GET",
@@ -154,7 +165,10 @@ func TestRouter(t *testing.T) {
})
t.Run("Sub Router", func(t *testing.T) {
- testRoute(t, "GET /api/v1/other", resultStruct{method: "GET", handlerMarks: []string{"not-found:/api/v1"}})
+ testRoute(t, "GET /api/v1/other", resultStruct{
+ method: "GET",
+ handlerMarks: []string{"not-found:/api/v1"},
+ })
testRoute(t, "GET /api/v1/repos/the-user/the-repo/branches", resultStruct{
method: "GET",
pathParams: map[string]string{"username": "the-user", "reponame": "the-repo"},
@@ -211,9 +225,10 @@ func TestRouter(t *testing.T) {
})
testRoute(t, "GET /api/v1/repos/the-user/the-repo/branches/d1/d2/fn?stop=s3", resultStruct{
- method: "GET",
- pathParams: map[string]string{"username": "the-user", "reponame": "the-repo", "*": "d1/d2/fn", "dir": "d1/d2", "file": "fn"},
- handlerMarks: []string{"s1", "s2", "s3"},
+ method: "GET",
+ pathParams: map[string]string{"username": "the-user", "reponame": "the-repo", "*": "d1/d2/fn", "dir": "d1/d2", "file": "fn"},
+ handlerMarks: []string{"s1", "s2", "s3"},
+ chiRoutePattern: util.ToPointer("/api/v1/repos/{username}/{reponame}/branches/<dir:*>/<file:[a-z]{1,2}>"),
})
})
}
diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini
index f979fc814d..f13f20bfa0 100644
--- a/options/locale/locale_en-US.ini
+++ b/options/locale/locale_en-US.ini
@@ -2334,8 +2334,8 @@ settings.hooks_desc = Webhooks automatically make HTTP POST requests to a server
settings.webhook_deletion = Remove Webhook
settings.webhook_deletion_desc = Removing a webhook deletes its settings and delivery history. Continue?
settings.webhook_deletion_success = The webhook has been removed.
-settings.webhook.test_delivery = Test Delivery
-settings.webhook.test_delivery_desc = Test this webhook with a fake event.
+settings.webhook.test_delivery = Test Push Event
+settings.webhook.test_delivery_desc = Test this webhook with a fake push event.
settings.webhook.test_delivery_desc_disabled = To test this webhook with a fake event, activate it.
settings.webhook.request = Request
settings.webhook.response = Response
diff --git a/routers/api/packages/conda/conda.go b/routers/api/packages/conda/conda.go
index cfe069d6db..e8c97503c8 100644
--- a/routers/api/packages/conda/conda.go
+++ b/routers/api/packages/conda/conda.go
@@ -51,7 +51,7 @@ func ListOrGetPackages(ctx *context.Context) {
DownloadPackageFile(ctx)
return
}
- ctx.NotFound(nil)
+ http.NotFound(ctx.Resp, ctx.Req)
}
func EnumeratePackages(ctx *context.Context) {
diff --git a/templates/devtest/flex-list.tmpl b/templates/devtest/flex-list.tmpl
index 11d71d56a9..0db84b0c59 100644
--- a/templates/devtest/flex-list.tmpl
+++ b/templates/devtest/flex-list.tmpl
@@ -68,7 +68,7 @@
<a class="text primary" href="{{$.Link}}">
gitea-org / gitea
</a>
- <span data-tooltip-content="{{ctx.Locale.Tr "repo.fork"}}">{{svg "octicon-repo-forked"}}</span>
+ <span class="flex-text-inline" data-tooltip-content="{{ctx.Locale.Tr "repo.fork"}}">{{svg "octicon-repo-forked"}}</span>
</div>
<div class="flex-item-trailing">
<a class="muted" href="{{$.Link}}">
diff --git a/templates/repo/settings/webhook/history.tmpl b/templates/repo/settings/webhook/history.tmpl
index ea3c037813..953ba69670 100644
--- a/templates/repo/settings/webhook/history.tmpl
+++ b/templates/repo/settings/webhook/history.tmpl
@@ -26,7 +26,7 @@
{{else}}
<span class="text red">{{svg "octicon-alert"}}</span>
{{end}}
- <a class="ui primary sha label toggle button show-panel" data-panel="#info-{{.ID}}">{{.UUID}}</a>
+ <button class="btn interact-bg tw-p-2 toggle show-panel" data-panel="#info-{{.ID}}">{{.UUID}}</button>
</div>
<span class="text grey">
{{DateUtils.TimeSince .Delivered}}
diff --git a/templates/shared/issuelist.tmpl b/templates/shared/issuelist.tmpl
index b25bcc14b9..98c26b32dc 100644
--- a/templates/shared/issuelist.tmpl
+++ b/templates/shared/issuelist.tmpl
@@ -35,7 +35,7 @@
</div>
{{end}}
</div>
- <div class="flex-item-body tw-mt-1">
+ <div class="flex-item-body">
<a class="index" href="{{if .Link}}{{.Link}}{{else}}{{$.Link}}/{{.Index}}{{end}}">
{{if eq $.listType "dashboard"}}
{{.Repo.FullName}}#{{.Index}}
diff --git a/web_src/css/shared/flex-list.css b/web_src/css/shared/flex-list.css
index 24abe8fd9d..e94e9e9cc2 100644
--- a/web_src/css/shared/flex-list.css
+++ b/web_src/css/shared/flex-list.css
@@ -17,6 +17,7 @@
.flex-item .flex-item-main {
display: flex;
flex-direction: column;
+ gap: 0.25em;
flex-grow: 1;
flex-basis: 60%; /* avoid wrapping the "flex-item-trailing" too aggressively */
min-width: 0; /* make the "text truncate" work, otherwise the flex axis is not limited and the text just overflows */