Skip to content

Commit bad8f07

Browse files
committed
Merge branch 'main' into add-project-icon-in-badge
2 parents 0c8e332 + 8ea33ba commit bad8f07

33 files changed

+616
-271
lines changed

.eslintrc.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ plugins:
1212
- eslint-plugin-unicorn
1313
- eslint-plugin-import
1414
- eslint-plugin-jquery
15+
- eslint-plugin-no-jquery
1516
- eslint-plugin-sonarjs
1617
- eslint-plugin-custom-elements
1718

@@ -192,6 +193,7 @@ rules:
192193
jquery/no-val: [0]
193194
jquery/no-when: [2]
194195
jquery/no-wrap: [2]
196+
no-jquery/no-event-shorthand: [2]
195197
key-spacing: [2]
196198
keyword-spacing: [2]
197199
line-comment-position: [0]

models/issues/comment.go

Lines changed: 71 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -52,84 +52,61 @@ func (err ErrCommentNotExist) Unwrap() error {
5252
// CommentType defines whether a comment is just a simple comment, an action (like close) or a reference.
5353
type CommentType int
5454

55-
// define unknown comment type
56-
const (
57-
CommentTypeUnknown CommentType = -1
58-
)
55+
// CommentTypeUndefined is used to search for comments of any type
56+
const CommentTypeUndefined CommentType = -1
5957

60-
// Enumerate all the comment types
6158
const (
62-
// 0 Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0)
63-
CommentTypeComment CommentType = iota
64-
CommentTypeReopen // 1
65-
CommentTypeClose // 2
66-
67-
// 3 References.
68-
CommentTypeIssueRef
69-
// 4 Reference from a commit (not part of a pull request)
70-
CommentTypeCommitRef
71-
// 5 Reference from a comment
72-
CommentTypeCommentRef
73-
// 6 Reference from a pull request
74-
CommentTypePullRef
75-
// 7 Labels changed
76-
CommentTypeLabel
77-
// 8 Milestone changed
78-
CommentTypeMilestone
79-
// 9 Assignees changed
80-
CommentTypeAssignees
81-
// 10 Change Title
82-
CommentTypeChangeTitle
83-
// 11 Delete Branch
84-
CommentTypeDeleteBranch
85-
// 12 Start a stopwatch for time tracking
86-
CommentTypeStartTracking
87-
// 13 Stop a stopwatch for time tracking
88-
CommentTypeStopTracking
89-
// 14 Add time manual for time tracking
90-
CommentTypeAddTimeManual
91-
// 15 Cancel a stopwatch for time tracking
92-
CommentTypeCancelTracking
93-
// 16 Added a due date
94-
CommentTypeAddedDeadline
95-
// 17 Modified the due date
96-
CommentTypeModifiedDeadline
97-
// 18 Removed a due date
98-
CommentTypeRemovedDeadline
99-
// 19 Dependency added
100-
CommentTypeAddDependency
101-
// 20 Dependency removed
102-
CommentTypeRemoveDependency
103-
// 21 Comment a line of code
104-
CommentTypeCode
105-
// 22 Reviews a pull request by giving general feedback
106-
CommentTypeReview
107-
// 23 Lock an issue, giving only collaborators access
108-
CommentTypeLock
109-
// 24 Unlocks a previously locked issue
110-
CommentTypeUnlock
111-
// 25 Change pull request's target branch
112-
CommentTypeChangeTargetBranch
113-
// 26 Delete time manual for time tracking
114-
CommentTypeDeleteTimeManual
115-
// 27 add or remove Request from one
116-
CommentTypeReviewRequest
117-
// 28 merge pull request
118-
CommentTypeMergePull
119-
// 29 push to PR head branch
120-
CommentTypePullRequestPush
121-
// 30 Project changed
122-
CommentTypeProject
123-
// 31 Project board changed
124-
CommentTypeProjectBoard
125-
// 32 Dismiss Review
126-
CommentTypeDismissReview
127-
// 33 Change issue ref
128-
CommentTypeChangeIssueRef
129-
// 34 pr was scheduled to auto merge when checks succeed
130-
CommentTypePRScheduledToAutoMerge
131-
// 35 pr was un scheduled to auto merge when checks succeed
132-
CommentTypePRUnScheduledToAutoMerge
59+
CommentTypeComment CommentType = iota // 0 Plain comment, can be associated with a commit (CommitID > 0) and a line (LineNum > 0)
60+
61+
CommentTypeReopen // 1
62+
CommentTypeClose // 2
63+
64+
CommentTypeIssueRef // 3 References.
65+
CommentTypeCommitRef // 4 Reference from a commit (not part of a pull request)
66+
CommentTypeCommentRef // 5 Reference from a comment
67+
CommentTypePullRef // 6 Reference from a pull request
68+
69+
CommentTypeLabel // 7 Labels changed
70+
CommentTypeMilestone // 8 Milestone changed
71+
CommentTypeAssignees // 9 Assignees changed
72+
CommentTypeChangeTitle // 10 Change Title
73+
CommentTypeDeleteBranch // 11 Delete Branch
74+
75+
CommentTypeStartTracking // 12 Start a stopwatch for time tracking
76+
CommentTypeStopTracking // 13 Stop a stopwatch for time tracking
77+
CommentTypeAddTimeManual // 14 Add time manual for time tracking
78+
CommentTypeCancelTracking // 15 Cancel a stopwatch for time tracking
79+
CommentTypeAddedDeadline // 16 Added a due date
80+
CommentTypeModifiedDeadline // 17 Modified the due date
81+
CommentTypeRemovedDeadline // 18 Removed a due date
82+
83+
CommentTypeAddDependency // 19 Dependency added
84+
CommentTypeRemoveDependency // 20 Dependency removed
85+
86+
CommentTypeCode // 21 Comment a line of code
87+
CommentTypeReview // 22 Reviews a pull request by giving general feedback
88+
89+
CommentTypeLock // 23 Lock an issue, giving only collaborators access
90+
CommentTypeUnlock // 24 Unlocks a previously locked issue
91+
92+
CommentTypeChangeTargetBranch // 25 Change pull request's target branch
93+
94+
CommentTypeDeleteTimeManual // 26 Delete time manual for time tracking
95+
96+
CommentTypeReviewRequest // 27 add or remove Request from one
97+
CommentTypeMergePull // 28 merge pull request
98+
CommentTypePullRequestPush // 29 push to PR head branch
99+
100+
CommentTypeProject // 30 Project changed
101+
CommentTypeProjectBoard // 31 Project board changed
102+
103+
CommentTypeDismissReview // 32 Dismiss Review
104+
105+
CommentTypeChangeIssueRef // 33 Change issue ref
106+
107+
CommentTypePRScheduledToAutoMerge // 34 pr was scheduled to auto merge when checks succeed
108+
CommentTypePRUnScheduledToAutoMerge // 35 pr was un scheduled to auto merge when checks succeed
109+
133110
)
134111

135112
var commentStrings = []string{
@@ -181,7 +158,23 @@ func AsCommentType(typeName string) CommentType {
181158
return CommentType(index)
182159
}
183160
}
184-
return CommentTypeUnknown
161+
return CommentTypeUndefined
162+
}
163+
164+
func (t CommentType) HasContentSupport() bool {
165+
switch t {
166+
case CommentTypeComment, CommentTypeCode, CommentTypeReview:
167+
return true
168+
}
169+
return false
170+
}
171+
172+
func (t CommentType) HasAttachmentSupport() bool {
173+
switch t {
174+
case CommentTypeComment, CommentTypeCode, CommentTypeReview:
175+
return true
176+
}
177+
return false
185178
}
186179

187180
// RoleDescriptor defines comment tag type
@@ -1039,7 +1032,7 @@ func (opts *FindCommentsOptions) ToConds() builder.Cond {
10391032
if opts.Before > 0 {
10401033
cond = cond.And(builder.Lte{"comment.updated_unix": opts.Before})
10411034
}
1042-
if opts.Type != CommentTypeUnknown {
1035+
if opts.Type != CommentTypeUndefined {
10431036
cond = cond.And(builder.Eq{"comment.type": opts.Type})
10441037
}
10451038
if opts.Line != 0 {

models/issues/comment_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ func TestFetchCodeComments(t *testing.T) {
6464
}
6565

6666
func TestAsCommentType(t *testing.T) {
67-
assert.Equal(t, issues_model.CommentTypeUnknown, issues_model.AsCommentType(""))
68-
assert.Equal(t, issues_model.CommentTypeUnknown, issues_model.AsCommentType("nonsense"))
67+
assert.Equal(t, issues_model.CommentType(0), issues_model.CommentTypeComment)
68+
assert.Equal(t, issues_model.CommentTypeUndefined, issues_model.AsCommentType(""))
69+
assert.Equal(t, issues_model.CommentTypeUndefined, issues_model.AsCommentType("nonsense"))
6970
assert.Equal(t, issues_model.CommentTypeComment, issues_model.AsCommentType("comment"))
7071
assert.Equal(t, issues_model.CommentTypePRUnScheduledToAutoMerge, issues_model.AsCommentType("pull_cancel_scheduled_merge"))
7172
}

models/issues/issue.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ func (issue *Issue) LoadPullRequest(ctx context.Context) (err error) {
269269
}
270270

271271
func (issue *Issue) loadComments(ctx context.Context) (err error) {
272-
return issue.loadCommentsByType(ctx, CommentTypeUnknown)
272+
return issue.loadCommentsByType(ctx, CommentTypeUndefined)
273273
}
274274

275275
// LoadDiscussComments loads discuss comments

modules/context/context.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ const CookieNameFlash = "gitea_flash"
4747

4848
// Render represents a template render
4949
type Render interface {
50-
TemplateLookup(tmpl string) (*template.Template, error)
50+
TemplateLookup(tmpl string) (templates.TemplateExecutor, error)
5151
HTML(w io.Writer, status int, name string, data interface{}) error
5252
}
5353

modules/templates/htmlrenderer.go

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"context"
1010
"errors"
1111
"fmt"
12-
"html/template"
1312
"io"
1413
"net/http"
1514
"path/filepath"
@@ -22,13 +21,16 @@ import (
2221
"code.gitea.io/gitea/modules/assetfs"
2322
"code.gitea.io/gitea/modules/log"
2423
"code.gitea.io/gitea/modules/setting"
24+
"code.gitea.io/gitea/modules/templates/scopedtmpl"
2525
"code.gitea.io/gitea/modules/util"
2626
)
2727

2828
var rendererKey interface{} = "templatesHtmlRenderer"
2929

30+
type TemplateExecutor scopedtmpl.TemplateExecutor
31+
3032
type HTMLRender struct {
31-
templates atomic.Pointer[template.Template]
33+
templates atomic.Pointer[scopedtmpl.ScopedTemplate]
3234
}
3335

3436
var ErrTemplateNotInitialized = errors.New("template system is not initialized, check your log for errors")
@@ -47,22 +49,20 @@ func (h *HTMLRender) HTML(w io.Writer, status int, name string, data interface{}
4749
return t.Execute(w, data)
4850
}
4951

50-
func (h *HTMLRender) TemplateLookup(name string) (*template.Template, error) {
52+
func (h *HTMLRender) TemplateLookup(name string) (TemplateExecutor, error) {
5153
tmpls := h.templates.Load()
5254
if tmpls == nil {
5355
return nil, ErrTemplateNotInitialized
5456
}
55-
tmpl := tmpls.Lookup(name)
56-
if tmpl == nil {
57-
return nil, util.ErrNotExist
58-
}
59-
return tmpl, nil
57+
58+
return tmpls.Executor(name, NewFuncMap()[0])
6059
}
6160

6261
func (h *HTMLRender) CompileTemplates() error {
63-
extSuffix := ".tmpl"
64-
tmpls := template.New("")
6562
assets := AssetFS()
63+
extSuffix := ".tmpl"
64+
tmpls := scopedtmpl.NewScopedTemplate()
65+
tmpls.Funcs(NewFuncMap()[0])
6666
files, err := ListWebTemplateAssetNames(assets)
6767
if err != nil {
6868
return nil
@@ -73,9 +73,6 @@ func (h *HTMLRender) CompileTemplates() error {
7373
}
7474
name := strings.TrimSuffix(file, extSuffix)
7575
tmpl := tmpls.New(filepath.ToSlash(name))
76-
for _, fm := range NewFuncMap() {
77-
tmpl.Funcs(fm)
78-
}
7976
buf, err := assets.ReadFile(file)
8077
if err != nil {
8178
return err
@@ -84,6 +81,7 @@ func (h *HTMLRender) CompileTemplates() error {
8481
return err
8582
}
8683
}
84+
tmpls.Freeze()
8785
h.templates.Store(tmpls)
8886
return nil
8987
}

0 commit comments

Comments
 (0)