Skip to content

Commit e148c28

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Support GITEA_I_AM_BEING_UNSAFE_RUNNING_AS_ROOT env (go-gitea#29788) Fix missing translation on milestons (go-gitea#29785) Fix lint-swagger warning (go-gitea#29787) Tweak actions view sticky (go-gitea#29781) add skip ci support for pull request title (go-gitea#29774) Refactor markup/csv: don't read all to memory (go-gitea#29760)
2 parents 6e7fc2d + 487ac9b commit e148c28

File tree

13 files changed

+123
-52
lines changed

13 files changed

+123
-52
lines changed

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-
}

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+
}

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

templates/swagger/v1_json.tmpl

Lines changed: 1 addition & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)