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.

templates/user/dashboard/milestones.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@
6262
</span>
6363
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
6464
<div class="menu">
65-
<a class="{{if or (eq .SortType "closestduedate") (not .SortType)}}active {{end}}item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=closestduedate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.closest_due_date"}}</a>
66-
<a class="{{if eq .SortType "furthestduedate"}}active {{end}}item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=furthestduedate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.furthest_due_date"}}</a>
65+
<a class="{{if or (eq .SortType "closestduedate") (not .SortType)}}active {{end}}item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=closestduedate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.earliest_due_data"}}</a>
66+
<a class="{{if eq .SortType "furthestduedate"}}active {{end}}item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=furthestduedate&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.latest_due_date"}}</a>
6767
<a class="{{if eq .SortType "leastcomplete"}}active {{end}}item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=leastcomplete&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.least_complete"}}</a>
6868
<a class="{{if eq .SortType "mostcomplete"}}active {{end}}item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=mostcomplete&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.most_complete"}}</a>
6969
<a class="{{if eq .SortType "mostissues"}}active {{end}}item" href="{{$.Link}}?repos=[{{range $.RepoIDs}}{{.}}%2C{{end}}]&sort=mostissues&state={{$.State}}&q={{$.Keyword}}">{{ctx.Locale.Tr "repo.milestones.filter_sort.most_issues"}}</a>

tests/integration/actions_trigger_test.go

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
actions_module "code.gitea.io/gitea/modules/actions"
2121
"code.gitea.io/gitea/modules/git"
2222
"code.gitea.io/gitea/modules/setting"
23+
"code.gitea.io/gitea/modules/test"
2324
pull_service "code.gitea.io/gitea/services/pull"
2425
repo_service "code.gitea.io/gitea/services/repository"
2526
files_service "code.gitea.io/gitea/services/repository/files"
@@ -199,6 +200,7 @@ func TestPullRequestTargetEvent(t *testing.T) {
199200

200201
func TestSkipCI(t *testing.T) {
201202
onGiteaRun(t, func(t *testing.T, u *url.URL) {
203+
session := loginUser(t, "user2")
202204
user2 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2})
203205

204206
// create the repo
@@ -209,7 +211,7 @@ func TestSkipCI(t *testing.T) {
209211
Gitignores: "Go",
210212
License: "MIT",
211213
Readme: "Default",
212-
DefaultBranch: "main",
214+
DefaultBranch: "master",
213215
IsPrivate: false,
214216
})
215217
assert.NoError(t, err)
@@ -228,12 +230,12 @@ func TestSkipCI(t *testing.T) {
228230
{
229231
Operation: "create",
230232
TreePath: ".gitea/workflows/pr.yml",
231-
ContentReader: strings.NewReader("name: test\non:\n push:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
233+
ContentReader: strings.NewReader("name: test\non:\n push:\n branches: [master]\n pull_request:\njobs:\n test:\n runs-on: ubuntu-latest\n steps:\n - run: echo helloworld\n"),
232234
},
233235
},
234236
Message: "add workflow",
235-
OldBranch: "main",
236-
NewBranch: "main",
237+
OldBranch: "master",
238+
NewBranch: "master",
237239
Author: &files_service.IdentityOptions{
238240
Name: user2.Name,
239241
Email: user2.Email,
@@ -263,8 +265,8 @@ func TestSkipCI(t *testing.T) {
263265
},
264266
},
265267
Message: fmt.Sprintf("%s add bar", setting.Actions.SkipWorkflowStrings[0]),
266-
OldBranch: "main",
267-
NewBranch: "main",
268+
OldBranch: "master",
269+
NewBranch: "master",
268270
Author: &files_service.IdentityOptions{
269271
Name: user2.Name,
270272
Email: user2.Email,
@@ -283,5 +285,42 @@ func TestSkipCI(t *testing.T) {
283285

284286
// the commit message contains a configured skip-ci string, so there is still only 1 record
285287
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
288+
289+
// add file to new branch
290+
addFileToBranchResp, err := files_service.ChangeRepoFiles(git.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
291+
Files: []*files_service.ChangeRepoFile{
292+
{
293+
Operation: "create",
294+
TreePath: "test-skip-ci",
295+
ContentReader: strings.NewReader("test-skip-ci"),
296+
},
297+
},
298+
Message: "add test file",
299+
OldBranch: "master",
300+
NewBranch: "test-skip-ci",
301+
Author: &files_service.IdentityOptions{
302+
Name: user2.Name,
303+
Email: user2.Email,
304+
},
305+
Committer: &files_service.IdentityOptions{
306+
Name: user2.Name,
307+
Email: user2.Email,
308+
},
309+
Dates: &files_service.CommitDateOptions{
310+
Author: time.Now(),
311+
Committer: time.Now(),
312+
},
313+
})
314+
assert.NoError(t, err)
315+
assert.NotEmpty(t, addFileToBranchResp)
316+
317+
resp := testPullCreate(t, session, "user2", "skip-ci", true, "master", "test-skip-ci", "[skip ci] test-skip-ci")
318+
319+
// check the redirected URL
320+
url := test.RedirectURL(resp)
321+
assert.Regexp(t, "^/user2/skip-ci/pulls/[0-9]*$", url)
322+
323+
// the pr title contains a configured skip-ci string, so there is still only 1 record
324+
assert.Equal(t, 1, unittest.GetCount(t, &actions_model.ActionRun{RepoID: repo.ID}))
286325
})
287326
}

web_src/js/components/RepoActionView.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ export function initRepositoryActionView() {
524524
width: 30%;
525525
max-width: 400px;
526526
position: sticky;
527-
top: 0;
527+
top: 12px;
528528
max-height: 100vh;
529529
overflow-y: auto;
530530
}

0 commit comments

Comments
 (0)