Skip to content

Commit 8513e80

Browse files
committed
Merge branch 'main' into mainzjj
* main: Make Markdown fenced code block work with more syntaxes (go-gitea#37154) Remove unneeded doctor sub-commands (go-gitea#37156) Report structurally invalid workflows to users (go-gitea#37116) Replace `rollup-plugin-license` with `rolldown-license-plugin` (go-gitea#37130) Clean up and improve non-gitea js error filter (go-gitea#37148)
2 parents f9a395a + 45c80bf commit 8513e80

30 files changed

Lines changed: 162 additions & 1681 deletions

build/generate-go-licenses.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
// regexp is based on go-license, excluding README and NOTICE
2121
// https://github.com/google/go-licenses/blob/master/licenses/find.go
22+
// also defined in vite.config.ts
2223
var licenseRe = regexp.MustCompile(`^(?i)((UN)?LICEN(S|C)E|COPYING).*$`)
2324

2425
// primaryLicenseRe matches exact primary license filenames without suffixes.

models/actions/run_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func TestUpdateRepoRunsNumbers(t *testing.T) {
3232
err = UpdateRepoRunsNumbers(t.Context(), repo)
3333
assert.NoError(t, err)
3434
repo = unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4})
35-
assert.Equal(t, 5, repo.NumActionRuns)
35+
assert.Equal(t, 4, repo.NumActionRuns)
3636
assert.Equal(t, 3, repo.NumClosedActionRuns)
3737
}
3838

models/fixtures/action_run.yml

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -140,25 +140,4 @@
140140
need_approval: 0
141141
approved_by: 0
142142

143-
-
144-
id: 805
145-
title: "update actions"
146-
repo_id: 4
147-
owner_id: 1
148-
workflow_id: "artifact.yaml"
149-
index: 191
150-
trigger_user_id: 1
151-
ref: "refs/heads/master"
152-
commit_sha: "c2d72f548424103f01ee1dc02889c1e2bff816b0"
153-
event: "push"
154-
trigger_event: "push"
155-
is_fork_pull_request: 0
156-
status: 5
157-
started: 1683636528
158-
stopped: 1683636626
159-
created: 1683636108
160-
updated: 1683636626
161-
need_approval: 0
162-
approved_by: 0
163-
164143
# DO NOT add more test data in the fixtures, test case should prepare their own test data separately and clearly

models/fixtures/action_run_job.yml

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -130,19 +130,4 @@
130130
started: 1683636528
131131
stopped: 1683636626
132132

133-
-
134-
id: 206
135-
run_id: 805
136-
repo_id: 4
137-
owner_id: 1
138-
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
139-
is_fork_pull_request: 0
140-
name: job_2
141-
attempt: 1
142-
job_id: job_2
143-
task_id: 56
144-
status: 3
145-
started: 1683636528
146-
stopped: 1683636626
147-
148133
# DO NOT add more test data in the fixtures, test case should prepare their own test data separately and clearly

models/fixtures/action_task.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -178,24 +178,4 @@
178178
log_size: 0
179179
log_expired: 0
180180

181-
-
182-
id: 56
183-
attempt: 1
184-
runner_id: 1
185-
status: 3 # 3 is the status code for "cancelled"
186-
started: 1683636528
187-
stopped: 1683636626
188-
repo_id: 4
189-
owner_id: 1
190-
commit_sha: c2d72f548424103f01ee1dc02889c1e2bff816b0
191-
is_fork_pull_request: 0
192-
token_hash: 6d8ef48297195edcc8e22c70b3020eaa06c52976db67d39b4240c64a69a2cc1508825121b7b8394e48e00b1bf3718b2aaaab
193-
token_salt: eeeeeeee
194-
token_last_eight: eeeeeeee
195-
log_filename: artifact-test2/2f/47.log
196-
log_in_storage: 1
197-
log_length: 707
198-
log_size: 90179
199-
log_expired: 0
200-
201181
# DO NOT add more test data in the fixtures, test case should prepare their own test data separately and clearly

models/user/user.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,16 +1462,6 @@ func IsUserVisibleToViewer(ctx context.Context, u, viewer *User) bool {
14621462
return false
14631463
}
14641464

1465-
// CountWrongUserType count OrgUser who have wrong type
1466-
func CountWrongUserType(ctx context.Context) (int64, error) {
1467-
return db.GetEngine(ctx).Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Count(new(User))
1468-
}
1469-
1470-
// FixWrongUserType fix OrgUser who have wrong type
1471-
func FixWrongUserType(ctx context.Context) (int64, error) {
1472-
return db.GetEngine(ctx).Where(builder.Eq{"type": 0}.And(builder.Neq{"num_teams": 0})).Cols("type").NoAutoTime().Update(&User{Type: 1})
1473-
}
1474-
14751465
func GetOrderByName() string {
14761466
if setting.UI.DefaultShowFullName {
14771467
return "full_name, name"

modules/actions/workflows.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,20 @@ func GetEventsFromContent(content []byte) ([]*jobparser.Event, error) {
103103
if err != nil {
104104
return nil, err
105105
}
106+
if err := ValidateWorkflowContent(content); err != nil {
107+
return nil, err
108+
}
106109

107110
return events, nil
108111
}
109112

113+
// ValidateWorkflowContent catches structural errors (e.g. blank lines in run: | blocks)
114+
// that model.ReadWorkflow alone does not detect.
115+
func ValidateWorkflowContent(content []byte) error {
116+
_, err := jobparser.Parse(content)
117+
return err
118+
}
119+
110120
func DetectWorkflows(
111121
gitRepo *git.Repository,
112122
commit *git.Commit,

modules/actions/workflows_test.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,26 @@ import (
99
"code.gitea.io/gitea/modules/git"
1010
"code.gitea.io/gitea/modules/setting"
1111
api "code.gitea.io/gitea/modules/structs"
12+
"code.gitea.io/gitea/modules/test"
1213
webhook_module "code.gitea.io/gitea/modules/webhook"
1314

1415
"github.com/stretchr/testify/assert"
1516
)
1617

18+
func fullWorkflowContent(part string) []byte {
19+
return []byte(`
20+
name: test
21+
` + part + `
22+
jobs:
23+
test:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- run: echo hello
27+
`)
28+
}
29+
1730
func TestIsWorkflow(t *testing.T) {
18-
oldDirs := setting.Actions.WorkflowDirs
19-
defer func() {
20-
setting.Actions.WorkflowDirs = oldDirs
21-
}()
31+
defer test.MockVariableValue(&setting.Actions.WorkflowDirs)()
2232

2333
tests := []struct {
2434
name string
@@ -218,7 +228,7 @@ func TestDetectMatched(t *testing.T) {
218228

219229
for _, tc := range testCases {
220230
t.Run(tc.desc, func(t *testing.T) {
221-
evts, err := GetEventsFromContent([]byte(tc.yamlOn))
231+
evts, err := GetEventsFromContent(fullWorkflowContent(tc.yamlOn))
222232
assert.NoError(t, err)
223233
assert.Len(t, evts, 1)
224234
assert.Equal(t, tc.expected, detectMatched(nil, tc.commit, tc.triggedEvent, tc.payload, evts[0]))
@@ -373,7 +383,7 @@ func TestMatchIssuesEvent(t *testing.T) {
373383

374384
for _, tc := range testCases {
375385
t.Run(tc.desc, func(t *testing.T) {
376-
evts, err := GetEventsFromContent([]byte(tc.yamlOn))
386+
evts, err := GetEventsFromContent(fullWorkflowContent(tc.yamlOn))
377387
assert.NoError(t, err)
378388
assert.Len(t, evts, 1)
379389

modules/markup/markdown/goldmark.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ func (g *ASTTransformer) Transform(node *ast.Document, reader text.Reader, pc pa
7070
}
7171
case *ast.CodeSpan:
7272
g.transformCodeSpan(ctx, v, reader)
73+
case *ast.FencedCodeBlock:
74+
g.transformFencedCodeblock(v, reader)
7375
case *ast.Blockquote:
7476
return g.transformBlockquote(v, reader)
7577
}

modules/markup/markdown/markdown_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,22 @@ func TestMarkdownUlDir(t *testing.T) {
600600
</ul>
601601
`, string(result))
602602
}
603+
604+
func TestMarkdownFencedCodeBlock(t *testing.T) {
605+
testRender := func(input, expected string) {
606+
buffer, err := markdown.RenderString(markup.NewTestRenderContext(), input)
607+
assert.NoError(t, err)
608+
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(string(buffer)))
609+
}
610+
const nl = "\n"
611+
const prefix = `<div class="code-block-container code-overflow-scroll"><pre class="code-block">`
612+
const suffix = `</pre></div>`
613+
614+
testRender("```\ncode\n```", prefix+`<code class="chroma language-text display">code`+nl+`</code>`+suffix)
615+
616+
const jsCommon = prefix + `<code class="chroma language-js display"><span class="nx">code</span>` + nl + `</code>` + suffix
617+
testRender("```js\ncode\n```", jsCommon)
618+
testRender("```js:app.ts\ncode\n```", jsCommon)
619+
testRender("```js,ignore\ncode\n```", jsCommon)
620+
testRender("```js ignore\ncode\n```", jsCommon)
621+
}

0 commit comments

Comments
 (0)