Skip to content

Commit 3f775bc

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: [skip ci] Updated translations via Crowdin Refactor: move part of updating protected branch logic to service layer (go-gitea#33742) Update changelog for v1.23.5 (go-gitea#33797) Email option to embed images as base64 instead of link (go-gitea#32061) Update TypeScript types (go-gitea#33799) Disable vet=off again (go-gitea#33794)
2 parents 1f845db + b0ee340 commit 3f775bc

File tree

17 files changed

+412
-98
lines changed

17 files changed

+412
-98
lines changed

CHANGELOG.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,28 @@ This changelog goes through the changes that have been made in each release
44
without substantial changes to our git log; to see the highlights of what has
55
been added to each release, please refer to the [blog](https://blog.gitea.com).
66

7+
## [1.23.5](https://github.com/go-gitea/gitea/releases/tag/v1.23.5) - 2025-03-04
8+
9+
* SECURITY
10+
* Bump x/oauth2 & x/crypto (#33704) (#33727)
11+
* PERFORMANCE
12+
* Optimize user dashboard loading (#33686) (#33708)
13+
* BUGFIXES
14+
* Fix navbar dropdown item align (#33782)
15+
* Fix inconsistent closed issue list icon (#33722) (#33728)
16+
* Fix for Maven Package Naming Convention Handling (#33678) (#33679)
17+
* Improve Open-with URL encoding (#33666) (#33680)
18+
* Deleting repository should unlink all related packages (#33653) (#33673)
19+
* Fix omitempty bug (#33663) (#33670)
20+
* Upgrade go-crypto from 1.1.4 to 1.1.6 (#33745) (#33754)
21+
* Fix OCI image.version annotation for releases to use full semver (#33698) (#33701)
22+
* Try to fix ACME path when renew (#33668) (#33693)
23+
* Fix mCaptcha bug (#33659) (#33661)
24+
* Git graph: don't show detached commits (#33645) (#33650)
25+
* Use MatchPhraseQuery for bleve code search (#33628)
26+
* Adjust appearence of commit status webhook (#33778) #33789
27+
* Upgrade golang net from 0.35.0 -> 0.36.0 (#33795) #33796
28+
729
## [1.23.4](https://github.com/go-gitea/gitea/releases/tag/v1.23.4) - 2025-02-16
830

931
* SECURITY

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ EXTRA_GOFLAGS ?=
7373
MAKE_VERSION := $(shell "$(MAKE)" -v | cat | head -n 1)
7474
MAKE_EVIDENCE_DIR := .make_evidence
7575

76-
GOTESTFLAGS ?= -vet=off
76+
GOTESTFLAGS ?=
7777
ifeq ($(RACE_ENABLED),true)
7878
GOFLAGS += -race
7979
GOTESTFLAGS += -race

custom/conf/app.example.ini

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1767,6 +1767,9 @@ LEVEL = Info
17671767
;;
17681768
;; convert \r\n to \n for Sendmail
17691769
;SENDMAIL_CONVERT_CRLF = true
1770+
;;
1771+
;; convert links of attached images to inline images. Only for images hosted in this gitea instance.
1772+
;EMBED_ATTACHMENT_IMAGES = false
17701773

17711774
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
17721775
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

modules/httplib/url.go

Lines changed: 65 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -102,25 +102,77 @@ func MakeAbsoluteURL(ctx context.Context, link string) string {
102102
return GuessCurrentHostURL(ctx) + "/" + strings.TrimPrefix(link, "/")
103103
}
104104

105-
func IsCurrentGiteaSiteURL(ctx context.Context, s string) bool {
105+
type urlType int
106+
107+
const (
108+
urlTypeGiteaAbsolute urlType = iota + 1 // "http://gitea/subpath"
109+
urlTypeGiteaPageRelative // "/subpath"
110+
urlTypeGiteaSiteRelative // "?key=val"
111+
urlTypeUnknown // "http://other"
112+
)
113+
114+
func detectURLRoutePath(ctx context.Context, s string) (routePath string, ut urlType) {
106115
u, err := url.Parse(s)
107116
if err != nil {
108-
return false
117+
return "", urlTypeUnknown
109118
}
119+
cleanedPath := ""
110120
if u.Path != "" {
111-
cleanedPath := util.PathJoinRelX(u.Path)
112-
if cleanedPath == "" || cleanedPath == "." {
113-
u.Path = "/"
114-
} else {
115-
u.Path = "/" + cleanedPath + "/"
116-
}
121+
cleanedPath = util.PathJoinRelX(u.Path)
122+
cleanedPath = util.Iif(cleanedPath == ".", "", "/"+cleanedPath)
117123
}
118124
if urlIsRelative(s, u) {
119-
return u.Path == "" || strings.HasPrefix(strings.ToLower(u.Path), strings.ToLower(setting.AppSubURL+"/"))
120-
}
121-
if u.Path == "" {
122-
u.Path = "/"
125+
if u.Path == "" {
126+
return "", urlTypeGiteaPageRelative
127+
}
128+
if strings.HasPrefix(strings.ToLower(cleanedPath+"/"), strings.ToLower(setting.AppSubURL+"/")) {
129+
return cleanedPath[len(setting.AppSubURL):], urlTypeGiteaSiteRelative
130+
}
131+
return "", urlTypeUnknown
123132
}
133+
u.Path = cleanedPath + "/"
124134
urlLower := strings.ToLower(u.String())
125-
return strings.HasPrefix(urlLower, strings.ToLower(setting.AppURL)) || strings.HasPrefix(urlLower, strings.ToLower(GuessCurrentAppURL(ctx)))
135+
if strings.HasPrefix(urlLower, strings.ToLower(setting.AppURL)) {
136+
return cleanedPath[len(setting.AppSubURL):], urlTypeGiteaAbsolute
137+
}
138+
guessedCurURL := GuessCurrentAppURL(ctx)
139+
if strings.HasPrefix(urlLower, strings.ToLower(guessedCurURL)) {
140+
return cleanedPath[len(setting.AppSubURL):], urlTypeGiteaAbsolute
141+
}
142+
return "", urlTypeUnknown
143+
}
144+
145+
func IsCurrentGiteaSiteURL(ctx context.Context, s string) bool {
146+
_, ut := detectURLRoutePath(ctx, s)
147+
return ut != urlTypeUnknown
148+
}
149+
150+
type GiteaSiteURL struct {
151+
RoutePath string
152+
OwnerName string
153+
RepoName string
154+
RepoSubPath string
155+
}
156+
157+
func ParseGiteaSiteURL(ctx context.Context, s string) *GiteaSiteURL {
158+
routePath, ut := detectURLRoutePath(ctx, s)
159+
if ut == urlTypeUnknown || ut == urlTypeGiteaPageRelative {
160+
return nil
161+
}
162+
ret := &GiteaSiteURL{RoutePath: routePath}
163+
fields := strings.SplitN(strings.TrimPrefix(ret.RoutePath, "/"), "/", 3)
164+
165+
// TODO: now it only does a quick check for some known reserved paths, should do more strict checks in the future
166+
if fields[0] == "attachments" {
167+
return ret
168+
}
169+
if len(fields) < 2 {
170+
return ret
171+
}
172+
ret.OwnerName = fields[0]
173+
ret.RepoName = fields[1]
174+
if len(fields) == 3 {
175+
ret.RepoSubPath = "/" + fields[2]
176+
}
177+
return ret
126178
}

modules/httplib/url_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,26 @@ func TestIsCurrentGiteaSiteURL(t *testing.T) {
122122
assert.True(t, IsCurrentGiteaSiteURL(ctx, "https://user-host"))
123123
assert.False(t, IsCurrentGiteaSiteURL(ctx, "https://forwarded-host"))
124124
}
125+
126+
func TestParseGiteaSiteURL(t *testing.T) {
127+
defer test.MockVariableValue(&setting.AppURL, "http://localhost:3000/sub/")()
128+
defer test.MockVariableValue(&setting.AppSubURL, "/sub")()
129+
ctx := t.Context()
130+
tests := []struct {
131+
url string
132+
exp *GiteaSiteURL
133+
}{
134+
{"http://localhost:3000/sub?k=v", &GiteaSiteURL{RoutePath: ""}},
135+
{"http://localhost:3000/sub/", &GiteaSiteURL{RoutePath: ""}},
136+
{"http://localhost:3000/sub/foo", &GiteaSiteURL{RoutePath: "/foo"}},
137+
{"http://localhost:3000/sub/foo/bar", &GiteaSiteURL{RoutePath: "/foo/bar", OwnerName: "foo", RepoName: "bar"}},
138+
{"http://localhost:3000/sub/foo/bar/", &GiteaSiteURL{RoutePath: "/foo/bar", OwnerName: "foo", RepoName: "bar"}},
139+
{"http://localhost:3000/sub/attachments/bar", &GiteaSiteURL{RoutePath: "/attachments/bar"}},
140+
{"http://localhost:3000/other", nil},
141+
{"http://other/", nil},
142+
}
143+
for _, test := range tests {
144+
su := ParseGiteaSiteURL(ctx, test.url)
145+
assert.Equal(t, test.exp, su, "URL = %s", test.url)
146+
}
147+
}

modules/setting/mailer.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import (
1313

1414
"code.gitea.io/gitea/modules/log"
1515

16-
shellquote "github.com/kballard/go-shellquote"
16+
"github.com/kballard/go-shellquote"
1717
)
1818

1919
// Mailer represents mail service.
@@ -29,6 +29,9 @@ type Mailer struct {
2929
SubjectPrefix string `ini:"SUBJECT_PREFIX"`
3030
OverrideHeader map[string][]string `ini:"-"`
3131

32+
// Embed attachment images as inline base64 img src attribute
33+
EmbedAttachmentImages bool
34+
3235
// SMTP sender
3336
Protocol string `ini:"PROTOCOL"`
3437
SMTPAddr string `ini:"SMTP_ADDR"`

options/locale/locale_ga-IE.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1937,6 +1937,7 @@ pulls.outdated_with_base_branch=Tá an brainse seo as dáta leis an mbunbhrainse
19371937
pulls.close=Dún Iarratas Tarraing
19381938
pulls.closed_at=`dhún an t-iarratas tarraingthe seo <a id="%[1]s" href="#%[1]s">%[2]s</a>`
19391939
pulls.reopened_at=`athoscail an t-iarratas tarraingthe seo <a id="%[1]s" href="#%[1]s">%[2]s</a>`
1940+
pulls.cmd_instruction_hint=Féach ar threoracha na n-orduithe
19401941
pulls.cmd_instruction_checkout_title=Seiceáil
19411942
pulls.cmd_instruction_checkout_desc=Ó stór tionscadail, seiceáil brainse nua agus déan tástáil ar na hathruithe.
19421943
pulls.cmd_instruction_merge_title=Cumaisc

routers/api/v1/repo/branch.go

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -594,12 +594,6 @@ func CreateBranchProtection(ctx *context.APIContext) {
594594
return
595595
}
596596

597-
isPlainRule := !git_model.IsRuleNameSpecial(ruleName)
598-
var isBranchExist bool
599-
if isPlainRule {
600-
isBranchExist = git.IsBranchExist(ctx.Req.Context(), ctx.Repo.Repository.RepoPath(), ruleName)
601-
}
602-
603597
protectBranch, err := git_model.GetProtectedBranchRuleByName(ctx, repo.ID, ruleName)
604598
if err != nil {
605599
ctx.APIErrorInternal(err)
@@ -716,7 +710,7 @@ func CreateBranchProtection(ctx *context.APIContext) {
716710
BlockAdminMergeOverride: form.BlockAdminMergeOverride,
717711
}
718712

719-
if err := git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{
713+
if err := pull_service.CreateOrUpdateProtectedBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{
720714
UserIDs: whitelistUsers,
721715
TeamIDs: whitelistTeams,
722716
ForcePushUserIDs: forcePushAllowlistUsers,
@@ -730,36 +724,6 @@ func CreateBranchProtection(ctx *context.APIContext) {
730724
return
731725
}
732726

733-
if isBranchExist {
734-
if err := pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, ruleName); err != nil {
735-
ctx.APIErrorInternal(err)
736-
return
737-
}
738-
} else {
739-
if !isPlainRule {
740-
if ctx.Repo.GitRepo == nil {
741-
ctx.Repo.GitRepo, err = gitrepo.RepositoryFromRequestContextOrOpen(ctx, ctx.Repo.Repository)
742-
if err != nil {
743-
ctx.APIErrorInternal(err)
744-
return
745-
}
746-
}
747-
// FIXME: since we only need to recheck files protected rules, we could improve this
748-
matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, ruleName)
749-
if err != nil {
750-
ctx.APIErrorInternal(err)
751-
return
752-
}
753-
754-
for _, branchName := range matchedBranches {
755-
if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil {
756-
ctx.APIErrorInternal(err)
757-
return
758-
}
759-
}
760-
}
761-
}
762-
763727
// Reload from db to get all whitelists
764728
bp, err := git_model.GetProtectedBranchRuleByName(ctx, ctx.Repo.Repository.ID, ruleName)
765729
if err != nil {

routers/web/repo/setting/protected_branch.go

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ func SettingsProtectedBranchPost(ctx *context.Context) {
261261
protectBranch.BlockOnOutdatedBranch = f.BlockOnOutdatedBranch
262262
protectBranch.BlockAdminMergeOverride = f.BlockAdminMergeOverride
263263

264-
err = git_model.UpdateProtectBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{
264+
if err = pull_service.CreateOrUpdateProtectedBranch(ctx, ctx.Repo.Repository, protectBranch, git_model.WhitelistOptions{
265265
UserIDs: whitelistUsers,
266266
TeamIDs: whitelistTeams,
267267
ForcePushUserIDs: forcePushAllowlistUsers,
@@ -270,24 +270,10 @@ func SettingsProtectedBranchPost(ctx *context.Context) {
270270
MergeTeamIDs: mergeWhitelistTeams,
271271
ApprovalsUserIDs: approvalsWhitelistUsers,
272272
ApprovalsTeamIDs: approvalsWhitelistTeams,
273-
})
274-
if err != nil {
275-
ctx.ServerError("UpdateProtectBranch", err)
276-
return
277-
}
278-
279-
// FIXME: since we only need to recheck files protected rules, we could improve this
280-
matchedBranches, err := git_model.FindAllMatchedBranches(ctx, ctx.Repo.Repository.ID, protectBranch.RuleName)
281-
if err != nil {
282-
ctx.ServerError("FindAllMatchedBranches", err)
273+
}); err != nil {
274+
ctx.ServerError("CreateOrUpdateProtectedBranch", err)
283275
return
284276
}
285-
for _, branchName := range matchedBranches {
286-
if err = pull_service.CheckPRsForBaseBranch(ctx, ctx.Repo.Repository, branchName); err != nil {
287-
ctx.ServerError("CheckPRsForBaseBranch", err)
288-
return
289-
}
290-
}
291277

292278
ctx.Flash.Success(ctx.Tr("repo.settings.update_protect_branch_success", protectBranch.RuleName))
293279
ctx.Redirect(fmt.Sprintf("%s/settings/branches?rule_name=%s", ctx.Repo.RepoLink, protectBranch.RuleName))

services/forms/repo_form.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -170,13 +170,6 @@ func (f *RepoSettingForm) Validate(req *http.Request, errs binding.Errors) bindi
170170
return middleware.Validate(errs, ctx.Data, f, ctx.Locale)
171171
}
172172

173-
// __________ .__
174-
// \______ \____________ ____ ____ | |__
175-
// | | _/\_ __ \__ \ / \_/ ___\| | \
176-
// | | \ | | \// __ \| | \ \___| Y \
177-
// |______ / |__| (____ /___| /\___ >___| /
178-
// \/ \/ \/ \/ \/
179-
180173
// ProtectBranchForm form for changing protected branch settings
181174
type ProtectBranchForm struct {
182175
RuleName string `binding:"Required"`

0 commit comments

Comments
 (0)