Skip to content

Commit 83d0247

Browse files
authored
Merge branch 'master' into user-settings-ignore-incorect-lang-value
2 parents c0fd164 + 0d35ef5 commit 83d0247

File tree

16 files changed

+122
-129
lines changed

16 files changed

+122
-129
lines changed

models/lfs_lock.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,10 @@ package models
77
import (
88
"fmt"
99
"path"
10-
"strconv"
1110
"strings"
1211
"time"
1312

1413
"code.gitea.io/gitea/modules/log"
15-
api "code.gitea.io/gitea/modules/structs"
1614

1715
"xorm.io/xorm"
1816
)
@@ -52,18 +50,6 @@ func cleanPath(p string) string {
5250
return path.Clean("/" + p)[1:]
5351
}
5452

55-
// APIFormat convert a Release to lfs.LFSLock
56-
func (l *LFSLock) APIFormat() *api.LFSLock {
57-
return &api.LFSLock{
58-
ID: strconv.FormatInt(l.ID, 10),
59-
Path: l.Path,
60-
LockedAt: l.Created.Round(time.Second),
61-
Owner: &api.LFSLockOwner{
62-
Name: l.Owner.DisplayName(),
63-
},
64-
}
65-
}
66-
6753
// CreateLFSLock creates a new lock.
6854
func CreateLFSLock(lock *LFSLock) (*LFSLock, error) {
6955
err := CheckLFSAccessForRepo(lock.Owner, lock.Repo, AccessModeWrite)

modules/convert/convert.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ package convert
77

88
import (
99
"fmt"
10+
"strconv"
11+
"time"
1012

1113
"code.gitea.io/gitea/models"
1214
"code.gitea.io/gitea/modules/git"
@@ -365,3 +367,15 @@ func ToCommitStatus(status *models.CommitStatus) *api.Status {
365367

366368
return apiStatus
367369
}
370+
371+
// ToLFSLock convert a LFSLock to api.LFSLock
372+
func ToLFSLock(l *models.LFSLock) *api.LFSLock {
373+
return &api.LFSLock{
374+
ID: strconv.FormatInt(l.ID, 10),
375+
Path: l.Path,
376+
LockedAt: l.Created.Round(time.Second),
377+
Owner: &api.LFSLockOwner{
378+
Name: l.Owner.DisplayName(),
379+
},
380+
}
381+
}

modules/lfs/locks.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111

1212
"code.gitea.io/gitea/models"
1313
"code.gitea.io/gitea/modules/context"
14+
"code.gitea.io/gitea/modules/convert"
1415
"code.gitea.io/gitea/modules/log"
1516
"code.gitea.io/gitea/modules/setting"
1617
api "code.gitea.io/gitea/modules/structs"
@@ -60,7 +61,7 @@ func handleLockListOut(ctx *context.Context, repo *models.Repository, lock *mode
6061
return
6162
}
6263
ctx.JSON(200, api.LFSLockList{
63-
Locks: []*api.LFSLock{lock.APIFormat()},
64+
Locks: []*api.LFSLock{convert.ToLFSLock(lock)},
6465
})
6566
}
6667

@@ -140,7 +141,7 @@ func GetListLockHandler(ctx *context.Context) {
140141
lockListAPI := make([]*api.LFSLock, len(lockList))
141142
next := ""
142143
for i, l := range lockList {
143-
lockListAPI[i] = l.APIFormat()
144+
lockListAPI[i] = convert.ToLFSLock(l)
144145
}
145146
if limit > 0 && len(lockList) == limit {
146147
next = strconv.Itoa(cursor + 1)
@@ -198,7 +199,7 @@ func PostLockHandler(ctx *context.Context) {
198199
if err != nil {
199200
if models.IsErrLFSLockAlreadyExist(err) {
200201
ctx.JSON(409, api.LFSLockError{
201-
Lock: lock.APIFormat(),
202+
Lock: convert.ToLFSLock(lock),
202203
Message: "already created lock",
203204
})
204205
return
@@ -216,7 +217,7 @@ func PostLockHandler(ctx *context.Context) {
216217
})
217218
return
218219
}
219-
ctx.JSON(201, api.LFSLockResponse{Lock: lock.APIFormat()})
220+
ctx.JSON(201, api.LFSLockResponse{Lock: convert.ToLFSLock(lock)})
220221
}
221222

222223
// VerifyLockHandler list locks for verification
@@ -274,9 +275,9 @@ func VerifyLockHandler(ctx *context.Context) {
274275
lockTheirsListAPI := make([]*api.LFSLock, 0, len(lockList))
275276
for _, l := range lockList {
276277
if l.Owner.ID == ctx.User.ID {
277-
lockOursListAPI = append(lockOursListAPI, l.APIFormat())
278+
lockOursListAPI = append(lockOursListAPI, convert.ToLFSLock(l))
278279
} else {
279-
lockTheirsListAPI = append(lockTheirsListAPI, l.APIFormat())
280+
lockTheirsListAPI = append(lockTheirsListAPI, convert.ToLFSLock(l))
280281
}
281282
}
282283
ctx.JSON(200, api.LFSLockListVerify{
@@ -340,5 +341,5 @@ func UnLockHandler(ctx *context.Context) {
340341
})
341342
return
342343
}
343-
ctx.JSON(200, api.LFSLockResponse{Lock: lock.APIFormat()})
344+
ctx.JSON(200, api.LFSLockResponse{Lock: convert.ToLFSLock(lock)})
344345
}

modules/markup/html.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,25 @@ func RenderCommitMessageSubject(
268268
return ctx.postProcess(rawHTML)
269269
}
270270

271+
// RenderIssueTitle to process title on individual issue/pull page
272+
func RenderIssueTitle(
273+
rawHTML []byte,
274+
urlPrefix string,
275+
metas map[string]string,
276+
) ([]byte, error) {
277+
ctx := &postProcessCtx{
278+
metas: metas,
279+
urlPrefix: urlPrefix,
280+
procs: []processor{
281+
issueIndexPatternProcessor,
282+
sha1CurrentPatternProcessor,
283+
emojiShortCodeProcessor,
284+
emojiProcessor,
285+
},
286+
}
287+
return ctx.postProcess(rawHTML)
288+
}
289+
271290
// RenderDescriptionHTML will use similar logic as PostProcess, but will
272291
// use a single special linkProcessor.
273292
func RenderDescriptionHTML(

modules/structs/settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ type GeneralRepoSettings struct {
1212

1313
// GeneralUISettings contains global ui settings exposed by API
1414
type GeneralUISettings struct {
15+
DefaultTheme string `json:"default_theme"`
1516
AllowedReactions []string `json:"allowed_reactions"`
1617
}
1718

modules/templates/helper.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ func NewFuncMap() []template.FuncMap {
154154
"RenderCommitMessageLink": RenderCommitMessageLink,
155155
"RenderCommitMessageLinkSubject": RenderCommitMessageLinkSubject,
156156
"RenderCommitBody": RenderCommitBody,
157+
"RenderIssueTitle": RenderIssueTitle,
157158
"RenderEmoji": RenderEmoji,
158159
"RenderEmojiPlain": emoji.ReplaceAliases,
159160
"ReactionToEmoji": ReactionToEmoji,
@@ -630,6 +631,16 @@ func RenderCommitBody(msg, urlPrefix string, metas map[string]string) template.H
630631
return template.HTML(renderedMessage)
631632
}
632633

634+
// RenderIssueTitle renders issue/pull title with defined post processors
635+
func RenderIssueTitle(text, urlPrefix string, metas map[string]string) template.HTML {
636+
renderedText, err := markup.RenderIssueTitle([]byte(template.HTMLEscapeString(text)), urlPrefix, metas)
637+
if err != nil {
638+
log.Error("RenderIssueTitle: %v", err)
639+
return template.HTML("")
640+
}
641+
return template.HTML(renderedText)
642+
}
643+
633644
// RenderEmoji renders html text with emoji post processors
634645
func RenderEmoji(text string) template.HTML {
635646
renderedText, err := markup.RenderEmoji([]byte(template.HTMLEscapeString(text)))

routers/api/v1/settings/settings.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func GetGeneralUISettings(ctx *context.APIContext) {
2323
// "200":
2424
// "$ref": "#/responses/GeneralUISettings"
2525
ctx.JSON(http.StatusOK, api.GeneralUISettings{
26+
DefaultTheme: setting.UI.DefaultTheme,
2627
AllowedReactions: setting.UI.Reactions,
2728
})
2829
}

templates/base/head.tmpl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<title>{{if .Title}}{{.Title | RenderEmojiPlain}} - {{end}} {{if .Repository.Name}}{{.Repository.Name}} - {{end}}{{AppName}} </title>
88
<link rel="manifest" href="{{AppSubUrl}}/manifest.json" crossorigin="use-credentials">
99
<meta name="theme-color" content="{{ThemeColorMetaTag}}">
10+
<meta name="default-theme" content="{{DefaultTheme}}" />
1011
<meta name="author" content="{{if .Repository}}{{.Owner.Name}}{{else}}{{MetaAuthor}}{{end}}" />
1112
<meta name="description" content="{{if .Repository}}{{.Repository.Name}}{{if .Repository.Description}} - {{.Repository.Description}}{{end}}{{else}}{{MetaDescription}}{{end}}" />
1213
<meta name="keywords" content="{{MetaKeywords}}">

templates/repo/diff/box.tmpl

Lines changed: 3 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -150,80 +150,19 @@
150150
{{end}}
151151
</tr>
152152
{{if gt (len $line.Comments) 0}}
153-
{{$resolved := (index $line.Comments 0).IsResolved}}
154-
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
155-
{{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
156153
<tr class="add-code-comment">
157154
<td class="lines-num"></td>
158155
<td class="lines-type-marker"></td>
159156
<td class="add-comment-left">
160-
{{if and $resolved (eq $line.GetCommentSide "previous")}}
161-
<div class="ui top attached header resolved-placeholder">
162-
<span class="ui grey text left"><b>{{$resolveDoer.Name}}</b> {{$.i18n.Tr "repo.issues.review.resolved_by"}}</span>
163-
<button id="show-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="ui tiny right labeled button show-outdated">
164-
{{svg "octicon-unfold"}}
165-
{{$.i18n.Tr "repo.issues.review.show_resolved"}}
166-
</button>
167-
<button id="hide-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="hide ui tiny right labeled button hide-outdated">
168-
{{svg "octicon-fold"}}
169-
{{$.i18n.Tr "repo.issues.review.hide_resolved"}}
170-
</button>
171-
</div>
172-
{{end}}
173157
{{if eq $line.GetCommentSide "previous"}}
174-
<div id="code-comments-{{(index $line.Comments 0).ID}}" class="field comment-code-cloud {{if $resolved}}hide{{end}}">
175-
<div class="comment-list">
176-
<ui class="ui comments">
177-
{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
178-
</ui>
179-
</div>
180-
{{template "repo/diff/comment_form_datahandler" dict "reply" (index $line.Comments 0).ReviewID "hidden" true "root" $ "comment" (index $line.Comments 0)}}
181-
{{if and $.CanMarkConversation $isNotPending}}
182-
<button class="ui icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
183-
{{if $resolved}}
184-
{{$.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
185-
{{else}}
186-
{{$.i18n.Tr "repo.issues.review.resolve_conversation"}}
187-
{{end}}
188-
</button>
189-
{{end}}
190-
</div>
158+
{{template "repo/diff/conversation" mergeinto $ "comments" $line.Comments}}
191159
{{end}}
192160
</td>
193161
<td class="lines-num"></td>
194162
<td class="lines-type-marker"></td>
195-
<td class="add-comment-right resolved-placeholder">
196-
{{if and $resolved (eq $line.GetCommentSide "proposed")}}
197-
<div class="ui top attached header">
198-
<span class="ui grey text left"><b>{{$resolveDoer.Name}}</b> {{$.i18n.Tr "repo.issues.review.resolved_by"}}</span>
199-
<button id="show-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="ui tiny right labeled button show-outdated">
200-
{{svg "octicon-unfold"}}
201-
{{$.i18n.Tr "repo.issues.review.show_resolved"}}
202-
</button>
203-
<button id="hide-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="hide ui tiny right labeled button hide-outdated">
204-
{{svg "octicon-fold"}}
205-
{{$.i18n.Tr "repo.issues.review.hide_resolved"}}
206-
</button>
207-
</div>
208-
{{end}}
163+
<td class="add-comment-right">
209164
{{if eq $line.GetCommentSide "proposed"}}
210-
<div id="code-comments-{{(index $line.Comments 0).ID}}" class="field comment-code-cloud {{if $resolved}}hide{{end}}">
211-
<div class="comment-list">
212-
<ui class="ui comments">
213-
{{ template "repo/diff/comments" dict "root" $ "comments" $line.Comments}}
214-
</ui>
215-
</div>
216-
{{template "repo/diff/comment_form_datahandler" dict "reply" (index $line.Comments 0).ReviewID "hidden" true "root" $ "comment" (index $line.Comments 0)}}
217-
{{if and $.CanMarkConversation $isNotPending}}
218-
<button class="ui icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
219-
{{if $resolved}}
220-
{{$.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
221-
{{else}}
222-
{{$.i18n.Tr "repo.issues.review.resolve_conversation"}}
223-
{{end}}
224-
</button>
225-
{{end}}
226-
</div>
165+
{{template "repo/diff/conversation" mergeinto $ "comments" $line.Comments}}
227166
{{end}}
228167
</td>
229168
</tr>

templates/repo/diff/conversation.tmpl

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{{$resolved := (index .comments 0).IsResolved}}
2+
{{$resolveDoer := (index .comments 0).ResolveDoer}}
3+
{{$isNotPending := (not (eq (index .comments 0).Review.Type 0))}}
4+
<div class="conversation-holder">
5+
{{if $resolved}}
6+
<div class="ui attached header resolved-placeholder">
7+
<span class="ui grey text left"><b>{{$resolveDoer.Name}}</b> {{$.i18n.Tr "repo.issues.review.resolved_by"}}</span>
8+
<button id="show-outdated-{{(index .comments 0).ID}}" data-comment="{{(index .comments 0).ID}}" class="ui tiny right labeled button show-outdated">
9+
{{svg "octicon-unfold"}}
10+
{{$.i18n.Tr "repo.issues.review.show_resolved"}}
11+
</button>
12+
<button id="hide-outdated-{{(index .comments 0).ID}}" data-comment="{{(index .comments 0).ID}}" class="hide ui tiny right labeled button hide-outdated">
13+
{{svg "octicon-fold"}}
14+
{{$.i18n.Tr "repo.issues.review.hide_resolved"}}
15+
</button>
16+
</div>
17+
{{end}}
18+
<div id="code-comments-{{(index .comments 0).ID}}" class="field comment-code-cloud {{if $resolved}}hide{{end}}">
19+
<div class="comment-list">
20+
<ui class="ui comments">
21+
{{template "repo/diff/comments" dict "root" $ "comments" .comments}}
22+
</ui>
23+
</div>
24+
{{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" (index .comments 0).ReviewID "root" $ "comment" (index .comments 0)}}
25+
{{if and $.CanMarkConversation $isNotPending}}
26+
<button class="ui icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index .comments 0).ID}}" data-update-url="{{$.RepoLink}}/issues/resolve_conversation" >
27+
{{if $resolved}}
28+
{{$.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
29+
{{else}}
30+
{{$.i18n.Tr "repo.issues.review.resolve_conversation"}}
31+
{{end}}
32+
</button>
33+
{{end}}
34+
</div>
35+
</div>

templates/repo/diff/section_unified.tmpl

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,42 +33,10 @@
3333
{{end}}
3434
</tr>
3535
{{if gt (len $line.Comments) 0}}
36-
{{$resolved := (index $line.Comments 0).IsResolved}}
37-
{{$resolveDoer := (index $line.Comments 0).ResolveDoer}}
38-
{{$isNotPending := (not (eq (index $line.Comments 0).Review.Type 0))}}
3936
<tr>
4037
<td colspan="2" class="lines-num"></td>
4138
<td class="add-comment-left add-comment-right" colspan="2">
42-
{{if $resolved}}
43-
<div class="ui attached header resolved-placeholder">
44-
<span class="ui grey text left"><b>{{$resolveDoer.Name}}</b> {{$.root.i18n.Tr "repo.issues.review.resolved_by"}}</span>
45-
<button id="show-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="ui tiny right labeled button show-outdated">
46-
{{svg "octicon-unfold"}}
47-
{{$.root.i18n.Tr "repo.issues.review.show_resolved"}}
48-
</button>
49-
<button id="hide-outdated-{{(index $line.Comments 0).ID}}" data-comment="{{(index $line.Comments 0).ID}}" class="hide ui tiny right labeled button hide-outdated">
50-
{{svg "octicon-fold"}}
51-
{{$.root.i18n.Tr "repo.issues.review.hide_resolved"}}
52-
</button>
53-
</div>
54-
{{end}}
55-
<div id="code-comments-{{(index $line.Comments 0).ID}}" class="field comment-code-cloud {{if $resolved}}hide{{end}}">
56-
<div class="comment-list">
57-
<ui class="ui comments">
58-
{{ template "repo/diff/comments" dict "root" $.root "comments" $line.Comments}}
59-
</ui>
60-
</div>
61-
{{template "repo/diff/comment_form_datahandler" dict "hidden" true "reply" (index $line.Comments 0).ReviewID "root" $.root "comment" (index $line.Comments 0)}}
62-
{{if and $.root.CanMarkConversation $isNotPending}}
63-
<button class="ui icon tiny button resolve-conversation" data-action="{{if not $resolved}}Resolve{{else}}UnResolve{{end}}" data-comment-id="{{(index $line.Comments 0).ID}}" data-update-url="{{$.root.RepoLink}}/issues/resolve_conversation" >
64-
{{if $resolved}}
65-
{{$.root.i18n.Tr "repo.issues.review.un_resolve_conversation"}}
66-
{{else}}
67-
{{$.root.i18n.Tr "repo.issues.review.resolve_conversation"}}
68-
{{end}}
69-
</button>
70-
{{end}}
71-
</div>
39+
{{template "repo/diff/conversation" mergeinto $.root "comments" $line.Comments}}
7240
</td>
7341
</tr>
7442
{{end}}

templates/repo/issue/view_title.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
</div>
77
{{end}}
88
<h1>
9-
<span id="issue-title">{{RenderEmoji .Issue.Title}}</span>
9+
<span id="issue-title">{{RenderIssueTitle .Issue.Title $.RepoLink $.Repository.ComposeMetas}}</span>
1010
<span class="index">#{{.Issue.Index}}</span>
1111
<div id="edit-title-input" class="ui input" style="display: none">
1212
<input value="{{.Issue.Title}}" maxlength="255">

templates/repo/view_file.tmpl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
</div>
3333
{{if not .ReadmeInList}}
3434
<div class="file-header-right file-actions df ac">
35-
<div class="ui buttons">
36-
<a class="ui tiny button" href="{{EscapePound $.RawFileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
35+
<div class="ui buttons mr-2">
36+
<a class="ui mini basic button" href="{{EscapePound $.RawFileLink}}">{{.i18n.Tr "repo.file_raw"}}</a>
3737
{{if not .IsViewCommit}}
38-
<a class="ui tiny button" href="{{.RepoLink}}/src/commit/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_permalink"}}</a>
38+
<a class="ui mini basic button" href="{{.RepoLink}}/src/commit/{{.CommitID}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_permalink"}}</a>
3939
{{end}}
4040
{{if .IsTextFile}}
41-
<a class="ui tiny button" href="{{.RepoLink}}/blame/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.blame"}}</a>
41+
<a class="ui mini basic button" href="{{.RepoLink}}/blame/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.blame"}}</a>
4242
{{end}}
43-
<a class="ui tiny button" href="{{.RepoLink}}/commits/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
43+
<a class="ui mini basic button" href="{{.RepoLink}}/commits/{{EscapePound .BranchNameSubURL}}/{{EscapePound .TreePath}}">{{.i18n.Tr "repo.file_history"}}</a>
4444
</div>
4545
{{if .Repository.CanEnableEditor}}
4646
{{if .CanEditFile}}

0 commit comments

Comments
 (0)