Skip to content

Commit e89bc0d

Browse files
authored
Merge branch 'main' into add-tailwind-nesting-config
2 parents a464dfe + 487ac9b commit e89bc0d

File tree

20 files changed

+257
-103
lines changed

20 files changed

+257
-103
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ GOFUMPT_PACKAGE ?= mvdan.cc/[email protected]
3131
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/[email protected]
3232
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3333
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/[email protected]
34-
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.30.5
34+
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@db51e79a0e37c572d8b59ae0c58bf2bbbbe53285
3535
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
3636
GO_LICENSES_PACKAGE ?= github.com/google/[email protected]
3737
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/[email protected]

custom/conf/app.example.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2608,7 +2608,7 @@ LEVEL = Info
26082608
;ENDLESS_TASK_TIMEOUT = 3h
26092609
;; Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time
26102610
;ABANDONED_JOB_TIMEOUT = 24h
2611-
;; Strings committers can place inside a commit message to skip executing the corresponding actions workflow
2611+
;; Strings committers can place inside a commit message or PR title to skip executing the corresponding actions workflow
26122612
;SKIP_WORKFLOW_STRINGS = [skip ci],[ci skip],[no ci],[skip actions],[actions skip]
26132613

26142614
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/administration/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1406,7 +1406,7 @@ PROXY_HOSTS = *.github.com
14061406
- `ZOMBIE_TASK_TIMEOUT`: **10m**: Timeout to stop the task which have running status, but haven't been updated for a long time
14071407
- `ENDLESS_TASK_TIMEOUT`: **3h**: Timeout to stop the tasks which have running status and continuous updates, but don't end for a long time
14081408
- `ABANDONED_JOB_TIMEOUT`: **24h**: Timeout to cancel the jobs which have waiting status, but haven't been picked by a runner for a long time
1409-
- `SKIP_WORKFLOW_STRINGS`: **[skip ci],[ci skip],[no ci],[skip actions],[actions skip]**: Strings committers can place inside a commit message to skip executing the corresponding actions workflow
1409+
- `SKIP_WORKFLOW_STRINGS`: **[skip ci],[ci skip],[no ci],[skip actions],[actions skip]**: Strings committers can place inside a commit message or PR title to skip executing the corresponding actions workflow
14101410

14111411
`DEFAULT_ACTIONS_URL` indicates where the Gitea Actions runners should find the actions with relative path.
14121412
For example, `uses: actions/checkout@v4` means `https://github.com/actions/checkout@v4` since the value of `DEFAULT_ACTIONS_URL` is `github`.

modules/markup/csv/csv.go

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,62 @@ func writeField(w io.Writer, element, class, field string) error {
7777
}
7878

7979
// Render implements markup.Renderer
80-
func (Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error {
80+
func (r Renderer) Render(ctx *markup.RenderContext, input io.Reader, output io.Writer) error {
8181
tmpBlock := bufio.NewWriter(output)
82+
maxSize := setting.UI.CSV.MaxFileSize
8283

83-
// FIXME: don't read all to memory
84-
rawBytes, err := io.ReadAll(input)
84+
if maxSize == 0 {
85+
return r.tableRender(ctx, input, tmpBlock)
86+
}
87+
88+
rawBytes, err := io.ReadAll(io.LimitReader(input, maxSize+1))
8589
if err != nil {
8690
return err
8791
}
8892

89-
if setting.UI.CSV.MaxFileSize != 0 && setting.UI.CSV.MaxFileSize < int64(len(rawBytes)) {
90-
if _, err := tmpBlock.WriteString("<pre>"); err != nil {
91-
return err
92-
}
93-
if _, err := tmpBlock.WriteString(html.EscapeString(string(rawBytes))); err != nil {
94-
return err
93+
if int64(len(rawBytes)) <= maxSize {
94+
return r.tableRender(ctx, bytes.NewReader(rawBytes), tmpBlock)
95+
}
96+
return r.fallbackRender(io.MultiReader(bytes.NewReader(rawBytes), input), tmpBlock)
97+
}
98+
99+
func (Renderer) fallbackRender(input io.Reader, tmpBlock *bufio.Writer) error {
100+
_, err := tmpBlock.WriteString("<pre>")
101+
if err != nil {
102+
return err
103+
}
104+
105+
scan := bufio.NewScanner(input)
106+
scan.Split(bufio.ScanRunes)
107+
for scan.Scan() {
108+
switch scan.Text() {
109+
case `&`:
110+
_, err = tmpBlock.WriteString("&amp;")
111+
case `'`:
112+
_, err = tmpBlock.WriteString("&#39;") // "&#39;" is shorter than "&apos;" and apos was not in HTML until HTML5.
113+
case `<`:
114+
_, err = tmpBlock.WriteString("&lt;")
115+
case `>`:
116+
_, err = tmpBlock.WriteString("&gt;")
117+
case `"`:
118+
_, err = tmpBlock.WriteString("&#34;") // "&#34;" is shorter than "&quot;".
119+
default:
120+
_, err = tmpBlock.Write(scan.Bytes())
95121
}
96-
if _, err := tmpBlock.WriteString("</pre>"); err != nil {
122+
if err != nil {
97123
return err
98124
}
99-
return tmpBlock.Flush()
100125
}
101126

102-
rd, err := csv.CreateReaderAndDetermineDelimiter(ctx, bytes.NewReader(rawBytes))
127+
_, err = tmpBlock.WriteString("</pre>")
128+
if err != nil {
129+
return err
130+
}
131+
return tmpBlock.Flush()
132+
}
133+
134+
func (Renderer) tableRender(ctx *markup.RenderContext, input io.Reader, tmpBlock *bufio.Writer) error {
135+
rd, err := csv.CreateReaderAndDetermineDelimiter(ctx, input)
103136
if err != nil {
104137
return err
105138
}

modules/markup/csv/csv_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
package markup
55

66
import (
7+
"bufio"
8+
"bytes"
79
"strings"
810
"testing"
911

@@ -29,4 +31,12 @@ func TestRenderCSV(t *testing.T) {
2931
assert.NoError(t, err)
3032
assert.EqualValues(t, v, buf.String())
3133
}
34+
35+
t.Run("fallbackRender", func(t *testing.T) {
36+
var buf bytes.Buffer
37+
err := render.fallbackRender(strings.NewReader("1,<a>\n2,<b>"), bufio.NewWriter(&buf))
38+
assert.NoError(t, err)
39+
want := "<pre>1,&lt;a&gt;\n2,&lt;b&gt;</pre>"
40+
assert.Equal(t, want, buf.String())
41+
})
3242
}

modules/setting/setting.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"code.gitea.io/gitea/modules/log"
1515
"code.gitea.io/gitea/modules/user"
16+
"code.gitea.io/gitea/modules/util"
1617
)
1718

1819
// settings
@@ -158,9 +159,11 @@ func loadCommonSettingsFrom(cfg ConfigProvider) error {
158159
func loadRunModeFrom(rootCfg ConfigProvider) {
159160
rootSec := rootCfg.Section("")
160161
RunUser = rootSec.Key("RUN_USER").MustString(user.CurrentUsername())
162+
161163
// The following is a purposefully undocumented option. Please do not run Gitea as root. It will only cause future headaches.
162164
// Please don't use root as a bandaid to "fix" something that is broken, instead the broken thing should instead be fixed properly.
163165
unsafeAllowRunAsRoot := ConfigSectionKeyBool(rootSec, "I_AM_BEING_UNSAFE_RUNNING_AS_ROOT")
166+
unsafeAllowRunAsRoot = unsafeAllowRunAsRoot || util.OptionalBoolParse(os.Getenv("GITEA_I_AM_BEING_UNSAFE_RUNNING_AS_ROOT")).Value()
164167
RunMode = os.Getenv("GITEA_RUN_MODE")
165168
if RunMode == "" {
166169
RunMode = rootSec.Key("RUN_MODE").MustString("prod")

modules/structs/user.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,3 @@ type UserBadgeOption struct {
132132
// example: ["badge1","badge2"]
133133
BadgeSlugs []string `json:"badge_slugs" binding:"Required"`
134134
}
135-
136-
// BadgeList
137-
// swagger:response BadgeList
138-
type BadgeList struct {
139-
// in:body
140-
Body []Badge `json:"body"`
141-
}

modules/util/util.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,12 @@ func ToFloat64(number any) (float64, error) {
212212
func ToPointer[T any](val T) *T {
213213
return &val
214214
}
215+
216+
// IfZero returns "def" if "v" is a zero value, otherwise "v"
217+
func IfZero[T comparable](v, def T) T {
218+
var zero T
219+
if v == zero {
220+
return def
221+
}
222+
return v
223+
}

routers/api/v1/swagger/options.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,4 @@ type swaggerParameterBodies struct {
193193

194194
// in:body
195195
UserBadgeOption api.UserBadgeOption
196-
197-
// in:body
198-
UserBadgeList api.BadgeList
199196
}

routers/api/v1/swagger/user.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,10 @@ type swaggerResponseUserSettings struct {
4848
// in:body
4949
Body []api.UserSettings `json:"body"`
5050
}
51+
52+
// BadgeList
53+
// swagger:response BadgeList
54+
type swaggerResponseBadgeList struct {
55+
// in:body
56+
Body []api.Badge `json:"body"`
57+
}

routers/web/repo/setting/webhook.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,6 +588,7 @@ func checkWebhook(ctx *context.Context) (*ownerRepoCtx, *webhook.Webhook) {
588588
return nil, nil
589589
}
590590
ctx.Data["BaseLink"] = orCtx.Link
591+
ctx.Data["BaseLinkNew"] = orCtx.LinkNew
591592

592593
var w *webhook.Webhook
593594
if orCtx.RepoID > 0 {

services/actions/notifier_helper.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func notify(ctx context.Context, input *notifyInput) error {
157157
return fmt.Errorf("gitRepo.GetCommit: %w", err)
158158
}
159159

160-
if skipWorkflowsForCommit(input, commit) {
160+
if skipWorkflows(input, commit) {
161161
return nil
162162
}
163163

@@ -223,8 +223,8 @@ func notify(ctx context.Context, input *notifyInput) error {
223223
return handleWorkflows(ctx, detectedWorkflows, commit, input, ref)
224224
}
225225

226-
func skipWorkflowsForCommit(input *notifyInput, commit *git.Commit) bool {
227-
// skip workflow runs with a configured skip-ci string in commit message if the event is push or pull_request(_sync)
226+
func skipWorkflows(input *notifyInput, commit *git.Commit) bool {
227+
// skip workflow runs with a configured skip-ci string in commit message or pr title if the event is push or pull_request(_sync)
228228
// https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs
229229
skipWorkflowEvents := []webhook_module.HookEventType{
230230
webhook_module.HookEventPush,
@@ -233,6 +233,10 @@ func skipWorkflowsForCommit(input *notifyInput, commit *git.Commit) bool {
233233
}
234234
if slices.Contains(skipWorkflowEvents, input.Event) {
235235
for _, s := range setting.Actions.SkipWorkflowStrings {
236+
if input.PullRequest != nil && strings.Contains(input.PullRequest.Issue.Title, s) {
237+
log.Debug("repo %s: skipped run for pr %v because of %s string", input.Repo.RepoPath(), input.PullRequest.Issue.ID, s)
238+
return true
239+
}
236240
if strings.Contains(commit.CommitMessage, s) {
237241
log.Debug("repo %s with commit %s: skipped run because of %s string", input.Repo.RepoPath(), commit.ID, s)
238242
return true

services/convert/pull_review.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ func ToPullReviewList(ctx context.Context, rl []*issues_model.Review, doer *user
6666
result := make([]*api.PullReview, 0, len(rl))
6767
for i := range rl {
6868
// show pending reviews only for the user who created them
69-
if rl[i].Type == issues_model.ReviewTypePending && !(doer.IsAdmin || doer.ID == rl[i].ReviewerID) {
69+
if rl[i].Type == issues_model.ReviewTypePending && (doer == nil || (!doer.IsAdmin && doer.ID != rl[i].ReviewerID)) {
7070
continue
7171
}
7272
r, err := ToPullReview(ctx, rl[i], doer)

services/convert/pull_review_test.go

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2024 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package convert
5+
6+
import (
7+
"testing"
8+
9+
"code.gitea.io/gitea/models/db"
10+
issues_model "code.gitea.io/gitea/models/issues"
11+
"code.gitea.io/gitea/models/unittest"
12+
user_model "code.gitea.io/gitea/models/user"
13+
14+
"github.com/stretchr/testify/assert"
15+
)
16+
17+
func Test_ToPullReview(t *testing.T) {
18+
assert.NoError(t, unittest.PrepareTestDatabase())
19+
20+
reviewer := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
21+
review := unittest.AssertExistsAndLoadBean(t, &issues_model.Review{ID: 6})
22+
assert.EqualValues(t, reviewer.ID, review.ReviewerID)
23+
assert.EqualValues(t, issues_model.ReviewTypePending, review.Type)
24+
25+
reviewList := []*issues_model.Review{review}
26+
27+
t.Run("Anonymous User", func(t *testing.T) {
28+
prList, err := ToPullReviewList(db.DefaultContext, reviewList, nil)
29+
assert.NoError(t, err)
30+
assert.Empty(t, prList)
31+
})
32+
33+
t.Run("Reviewer Himself", func(t *testing.T) {
34+
prList, err := ToPullReviewList(db.DefaultContext, reviewList, reviewer)
35+
assert.NoError(t, err)
36+
assert.Len(t, prList, 1)
37+
})
38+
39+
t.Run("Other User", func(t *testing.T) {
40+
user4 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 4})
41+
prList, err := ToPullReviewList(db.DefaultContext, reviewList, user4)
42+
assert.NoError(t, err)
43+
assert.Len(t, prList, 0)
44+
})
45+
46+
t.Run("Admin User", func(t *testing.T) {
47+
adminUser := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1})
48+
prList, err := ToPullReviewList(db.DefaultContext, reviewList, adminUser)
49+
assert.NoError(t, err)
50+
assert.Len(t, prList, 1)
51+
})
52+
}

0 commit comments

Comments
 (0)