Skip to content

Commit a7ddfc9

Browse files
authored
Merge branch 'main' into patch-actions-email-2
2 parents 5eaa9c8 + e02b47d commit a7ddfc9

File tree

12 files changed

+146
-60
lines changed

12 files changed

+146
-60
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ require (
2727
github.com/ProtonMail/go-crypto v1.2.0
2828
github.com/PuerkitoBio/goquery v1.10.3
2929
github.com/SaveTheRbtz/zstd-seekable-format-go/pkg v0.7.3
30-
github.com/alecthomas/chroma/v2 v2.17.0
30+
github.com/alecthomas/chroma/v2 v2.20.0
3131
github.com/aws/aws-sdk-go-v2/credentials v1.17.67
3232
github.com/aws/aws-sdk-go-v2/service/codecommit v1.28.2
3333
github.com/blakesmith/ar v0.0.0-20190502131153-809d4375e1fb

go.sum

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ github.com/SaveTheRbtz/zstd-seekable-format-go/pkg v0.7.3/go.mod h1:hMNtySovKkn2
7878
github.com/alecthomas/assert/v2 v2.11.0 h1:2Q9r3ki8+JYXvGsDyBXwH3LcJ+WK5D0gc5E8vS6K3D0=
7979
github.com/alecthomas/assert/v2 v2.11.0/go.mod h1:Bze95FyfUr7x34QZrjL+XP+0qgp/zg8yS+TtBj1WA3k=
8080
github.com/alecthomas/chroma/v2 v2.2.0/go.mod h1:vf4zrexSH54oEjJ7EdB65tGNHmH3pGZmVkgTP5RHvAs=
81-
github.com/alecthomas/chroma/v2 v2.17.0 h1:3r2Cgk+nXNICMBxIFGnTRTbQFUwMiLisW+9uos0TtUI=
82-
github.com/alecthomas/chroma/v2 v2.17.0/go.mod h1:RVX6AvYm4VfYe/zsk7mjHueLDZor3aWCNE14TFlepBk=
81+
github.com/alecthomas/chroma/v2 v2.20.0 h1:sfIHpxPyR07/Oylvmcai3X/exDlE8+FA820NTz+9sGw=
82+
github.com/alecthomas/chroma/v2 v2.20.0/go.mod h1:e7tViK0xh/Nf4BYHl00ycY6rV7b8iXBksI9E359yNmA=
8383
github.com/alecthomas/repr v0.0.0-20220113201626-b1b626ac65ae/go.mod h1:2kn6fqh/zIyPLmm3ugklbEi5hg5wS435eygvNfaDQL8=
84-
github.com/alecthomas/repr v0.4.0 h1:GhI2A8MACjfegCPVq9f1FLvIBS+DrQ2KQBFZP1iFzXc=
85-
github.com/alecthomas/repr v0.4.0/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
84+
github.com/alecthomas/repr v0.5.1 h1:E3G4t2QbHTSNpPKBgMTln5KLkZHLOcU7r37J4pXBuIg=
85+
github.com/alecthomas/repr v0.5.1/go.mod h1:Fr0507jx4eOXV7AlPV6AVZLYrLIuIeSOWtW57eE/O/4=
8686
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa h1:LHTHcTQiSGT7VVbI0o4wBRNQIgn917usHWOd6VAffYI=
8787
github.com/alexbrainman/sspi v0.0.0-20231016080023-1a75b4708caa/go.mod h1:cEWa1LVoE5KvSD9ONXsZrj0z6KqySlCCNKHlLzbqAt4=
8888
github.com/anchore/archiver/v3 v3.5.2 h1:Bjemm2NzuRhmHy3m0lRe5tNoClB9A4zYyDV58PaB6aA=

modules/markup/orgmode/orgmode_test.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,16 +97,10 @@ func TestRender_Source(t *testing.T) {
9797
assert.Equal(t, strings.TrimSpace(expected), strings.TrimSpace(buffer))
9898
}
9999

100-
test(`#+begin_src go
101-
// HelloWorld prints "Hello World"
102-
func HelloWorld() {
103-
fmt.Println("Hello World")
104-
}
100+
test(`#+begin_src c
101+
int a;
105102
#+end_src
106-
`, `<div class="src src-go">
107-
<pre><code class="chroma language-go"><span class="c1">// HelloWorld prints &#34;Hello World&#34;</span>
108-
<span class="kd">func</span> <span class="nf">HelloWorld</span><span class="p">()</span> <span class="p">{</span>
109-
<span class="nx">fmt</span><span class="p">.</span><span class="nf">Println</span><span class="p">(</span><span class="s">&#34;Hello World&#34;</span><span class="p">)</span>
110-
<span class="p">}</span></code></pre>
103+
`, `<div class="src src-c">
104+
<pre><code class="chroma language-c"><span class="kt">int</span> <span class="n">a</span><span class="p">;</span></code></pre>
111105
</div>`)
112106
}

modules/setting/actions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424
ZombieTaskTimeout time.Duration `ini:"ZOMBIE_TASK_TIMEOUT"`
2525
EndlessTaskTimeout time.Duration `ini:"ENDLESS_TASK_TIMEOUT"`
2626
AbandonedJobTimeout time.Duration `ini:"ABANDONED_JOB_TIMEOUT"`
27-
SkipWorkflowStrings []string `ìni:"SKIP_WORKFLOW_STRINGS"`
27+
SkipWorkflowStrings []string `ini:"SKIP_WORKFLOW_STRINGS"`
2828
}{
2929
Enabled: true,
3030
DefaultActionsURL: defaultActionsURLGitHub,

modules/setting/cron_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,3 +41,56 @@ EXTEND = true
4141
assert.Equal(t, "white rabbit", extended.Second)
4242
assert.True(t, extended.Extend)
4343
}
44+
45+
// Test_getCronSettings2 tests that getCronSettings can not handle two levels of embedding
46+
func Test_getCronSettings2(t *testing.T) {
47+
type BaseStruct struct {
48+
Enabled bool
49+
RunAtStart bool
50+
Schedule string
51+
}
52+
53+
type Extended struct {
54+
BaseStruct
55+
Extend bool
56+
}
57+
type Extended2 struct {
58+
Extended
59+
Third string
60+
}
61+
62+
iniStr := `
63+
[cron.test]
64+
ENABLED = TRUE
65+
RUN_AT_START = TRUE
66+
SCHEDULE = @every 1h
67+
EXTEND = true
68+
THIRD = white rabbit
69+
`
70+
cfg, err := NewConfigProviderFromData(iniStr)
71+
assert.NoError(t, err)
72+
73+
extended := &Extended2{
74+
Extended: Extended{
75+
BaseStruct: BaseStruct{
76+
Enabled: false,
77+
RunAtStart: false,
78+
Schedule: "@every 72h",
79+
},
80+
Extend: false,
81+
},
82+
Third: "black rabbit",
83+
}
84+
85+
_, err = getCronSettings(cfg, "test", extended)
86+
assert.NoError(t, err)
87+
88+
// This confirms the first level of embedding works
89+
assert.Equal(t, "white rabbit", extended.Third)
90+
assert.True(t, extended.Extend)
91+
92+
// This confirms 2 levels of embedding doesn't work
93+
assert.False(t, extended.Enabled)
94+
assert.False(t, extended.RunAtStart)
95+
assert.Equal(t, "@every 72h", extended.Schedule)
96+
}

services/actions/notifier.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,6 @@ func (n *actionsNotifier) CreateIssueComment(ctx context.Context, doer *user_mod
263263
func (n *actionsNotifier) UpdateComment(ctx context.Context, doer *user_model.User, c *issues_model.Comment, oldContent string) {
264264
ctx = withMethod(ctx, "UpdateComment")
265265

266-
if err := c.LoadIssue(ctx); err != nil {
267-
log.Error("LoadIssue: %v", err)
268-
return
269-
}
270-
271266
if c.Issue.IsPull {
272267
notifyIssueCommentChange(ctx, doer, c, oldContent, webhook_module.HookEventPullRequestComment, api.HookIssueCommentEdited)
273268
return
@@ -278,11 +273,6 @@ func (n *actionsNotifier) UpdateComment(ctx context.Context, doer *user_model.Us
278273
func (n *actionsNotifier) DeleteComment(ctx context.Context, doer *user_model.User, comment *issues_model.Comment) {
279274
ctx = withMethod(ctx, "DeleteComment")
280275

281-
if err := comment.LoadIssue(ctx); err != nil {
282-
log.Error("LoadIssue: %v", err)
283-
return
284-
}
285-
286276
if comment.Issue.IsPull {
287277
notifyIssueCommentChange(ctx, doer, comment, "", webhook_module.HookEventPullRequestComment, api.HookIssueCommentDeleted)
288278
return
@@ -291,6 +281,7 @@ func (n *actionsNotifier) DeleteComment(ctx context.Context, doer *user_model.Us
291281
}
292282

293283
func notifyIssueCommentChange(ctx context.Context, doer *user_model.User, comment *issues_model.Comment, oldContent string, event webhook_module.HookEventType, action api.HookIssueCommentAction) {
284+
comment.Issue = nil // force issue to be loaded
294285
if err := comment.LoadIssue(ctx); err != nil {
295286
log.Error("LoadIssue: %v", err)
296287
return

services/cron/tasks_extended.go

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -171,34 +171,35 @@ func registerDeleteOldSystemNotices() {
171171
})
172172
}
173173

174+
type GCLFSConfig struct {
175+
BaseConfig
176+
OlderThan time.Duration
177+
LastUpdatedMoreThanAgo time.Duration
178+
NumberToCheckPerRepo int64
179+
ProportionToCheckPerRepo float64
180+
}
181+
174182
func registerGCLFS() {
175183
if !setting.LFS.StartServer {
176184
return
177185
}
178-
type GCLFSConfig struct {
179-
OlderThanConfig
180-
LastUpdatedMoreThanAgo time.Duration
181-
NumberToCheckPerRepo int64
182-
ProportionToCheckPerRepo float64
183-
}
184186

185187
RegisterTaskFatal("gc_lfs", &GCLFSConfig{
186-
OlderThanConfig: OlderThanConfig{
187-
BaseConfig: BaseConfig{
188-
Enabled: false,
189-
RunAtStart: false,
190-
Schedule: "@every 24h",
191-
},
192-
// Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
193-
// and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
194-
// an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
195-
// changes in new branches that might lead to lfs objects becoming temporarily unassociated with git
196-
// objects.
197-
//
198-
// It is likely that a week is potentially excessive but it should definitely be enough that any
199-
// unassociated LFS object is genuinely unassociated.
200-
OlderThan: 24 * time.Hour * 7,
188+
BaseConfig: BaseConfig{
189+
Enabled: false,
190+
RunAtStart: false,
191+
Schedule: "@every 24h",
201192
},
193+
// Only attempt to garbage collect lfs meta objects older than a week as the order of git lfs upload
194+
// and git object upload is not necessarily guaranteed. It's possible to imagine a situation whereby
195+
// an LFS object is uploaded but the git branch is not uploaded immediately, or there are some rapid
196+
// changes in new branches that might lead to lfs objects becoming temporarily unassociated with git
197+
// objects.
198+
//
199+
// It is likely that a week is potentially excessive but it should definitely be enough that any
200+
// unassociated LFS object is genuinely unassociated.
201+
OlderThan: 24 * time.Hour * 7,
202+
202203
// Only GC things that haven't been looked at in the past 3 days
203204
LastUpdatedMoreThanAgo: 24 * time.Hour * 3,
204205
NumberToCheckPerRepo: 100,
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// Copyright 2025 The Gitea Authors. All rights reserved.
2+
// SPDX-License-Identifier: MIT
3+
4+
package cron
5+
6+
import (
7+
"testing"
8+
"time"
9+
10+
"code.gitea.io/gitea/modules/setting"
11+
"code.gitea.io/gitea/modules/test"
12+
13+
"github.com/stretchr/testify/assert"
14+
)
15+
16+
func Test_GCLFSConfig(t *testing.T) {
17+
cfg, err := setting.NewConfigProviderFromData(`
18+
[cron.gc_lfs]
19+
ENABLED = true
20+
RUN_AT_START = true
21+
SCHEDULE = "@every 2h"
22+
OLDER_THAN = "1h"
23+
LAST_UPDATED_MORE_THAN_AGO = "7h"
24+
NUMBER_TO_CHECK_PER_REPO = 10
25+
PROPORTION_TO_CHECK_PER_REPO = 0.1
26+
`)
27+
assert.NoError(t, err)
28+
defer test.MockVariableValue(&setting.CfgProvider, cfg)()
29+
30+
config := &GCLFSConfig{
31+
BaseConfig: BaseConfig{
32+
Enabled: false,
33+
RunAtStart: false,
34+
Schedule: "@every 24h",
35+
},
36+
OlderThan: 24 * time.Hour * 7,
37+
LastUpdatedMoreThanAgo: 24 * time.Hour * 3,
38+
NumberToCheckPerRepo: 100,
39+
ProportionToCheckPerRepo: 0.6,
40+
}
41+
42+
_, err = setting.GetCronSettings("gc_lfs", config)
43+
assert.NoError(t, err)
44+
assert.True(t, config.Enabled)
45+
assert.True(t, config.RunAtStart)
46+
assert.Equal(t, "@every 2h", config.Schedule)
47+
assert.Equal(t, 1*time.Hour, config.OlderThan)
48+
assert.Equal(t, 7*time.Hour, config.LastUpdatedMoreThanAgo)
49+
assert.Equal(t, int64(10), config.NumberToCheckPerRepo)
50+
assert.InDelta(t, 0.1, config.ProportionToCheckPerRepo, 0.001)
51+
}

services/issue/comments.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ func CreateIssueComment(ctx context.Context, doer *user_model.User, repo *repo_m
8080
return nil, err
8181
}
8282

83+
// reload issue to ensure it has the latest data, especially the number of comments
84+
issue, err = issues_model.GetIssueByID(ctx, issue.ID)
85+
if err != nil {
86+
return nil, err
87+
}
88+
8389
notify_service.CreateIssueComment(ctx, doer, repo, issue, comment, mentions)
8490

8591
return comment, nil

services/webhook/notifier.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ func (m *webhookNotifier) DeleteComment(ctx context.Context, doer *user_model.Us
481481
log.Error("LoadPoster: %v", err)
482482
return
483483
}
484+
comment.Issue = nil // reload issue to ensure it has the latest data, especially the number of comments
484485
if err = comment.LoadIssue(ctx); err != nil {
485486
log.Error("LoadIssue: %v", err)
486487
return

0 commit comments

Comments
 (0)