File tree 4 files changed +64
-4
lines changed
4 files changed +64
-4
lines changed Original file line number Diff line number Diff line change
1
+ // Copyright 2021 The Gitea Authors. All rights reserved.
2
+ // Use of this source code is governed by a MIT-style
3
+ // license that can be found in the LICENSE file.
4
+
5
+ package util
6
+
7
+ import "unicode/utf8"
8
+
9
+ // SplitStringAtByteN splits a string at byte n accounting for rune boundaries. (Combining characters are not accounted for.)
10
+ func SplitStringAtByteN (input string , n int ) (left , right string ) {
11
+ if len (input ) <= n {
12
+ left = input
13
+ return
14
+ }
15
+
16
+ if ! utf8 .ValidString (input ) {
17
+ left = input [:n - 3 ] + "..."
18
+ right = "..." + input [n - 3 :]
19
+ return
20
+ }
21
+
22
+ // in UTF8 "…" is 3 bytes so doesn't really gain us anything...
23
+ end := 0
24
+ for end <= n - 3 {
25
+ _ , size := utf8 .DecodeRuneInString (input [end :])
26
+ if end + size > n - 3 {
27
+ break
28
+ }
29
+ end += size
30
+ }
31
+
32
+ left = input [:end ] + "…"
33
+ right = "…" + input [end :]
34
+ return
35
+ }
Original file line number Diff line number Diff line change @@ -24,6 +24,7 @@ import (
24
24
"code.gitea.io/gitea/modules/log"
25
25
"code.gitea.io/gitea/modules/setting"
26
26
"code.gitea.io/gitea/modules/upload"
27
+ "code.gitea.io/gitea/modules/util"
27
28
"code.gitea.io/gitea/services/gitdiff"
28
29
)
29
30
@@ -567,6 +568,18 @@ func PrepareCompareDiff(
567
568
} else {
568
569
title = headBranch
569
570
}
571
+ if len (title ) > 255 {
572
+ var trailer string
573
+ title , trailer = util .SplitStringAtByteN (title , 255 )
574
+ if len (trailer ) > 0 {
575
+ if ctx .Data ["content" ] != nil {
576
+ ctx .Data ["content" ] = fmt .Sprintf ("%s\n \n %s" , trailer , ctx .Data ["content" ])
577
+ } else {
578
+ ctx .Data ["content" ] = trailer + "\n "
579
+ }
580
+ }
581
+ }
582
+
570
583
ctx .Data ["title" ] = title
571
584
ctx .Data ["Username" ] = headUser .Name
572
585
ctx .Data ["Reponame" ] = headRepo .Name
Original file line number Diff line number Diff line change @@ -1001,10 +1001,14 @@ func CompareAndPullRequestPost(ctx *context.Context) {
1001
1001
ctx .Data ["Title" ] = ctx .Tr ("repo.pulls.compare_changes" )
1002
1002
ctx .Data ["PageIsComparePull" ] = true
1003
1003
ctx .Data ["IsDiffCompare" ] = true
1004
+ ctx .Data ["IsRepoToolbarCommits" ] = true
1005
+ ctx .Data ["RequireTribute" ] = true
1006
+ ctx .Data ["RequireSimpleMDE" ] = true
1004
1007
ctx .Data ["RequireHighlightJS" ] = true
1005
1008
ctx .Data ["PullRequestWorkInProgressPrefixes" ] = setting .Repository .PullRequest .WorkInProgressPrefixes
1006
1009
ctx .Data ["IsAttachmentEnabled" ] = setting .Attachment .Enabled
1007
1010
upload .AddUploadContext (ctx , "comment" )
1011
+ ctx .Data ["HasIssuesOrPullsWritePermission" ] = ctx .Repo .CanWrite (models .UnitTypePullRequests )
1008
1012
1009
1013
var (
1010
1014
repo = ctx .Repo .Repository
@@ -1037,6 +1041,14 @@ func CompareAndPullRequestPost(ctx *context.Context) {
1037
1041
return
1038
1042
}
1039
1043
1044
+ if len (form .Title ) > 255 {
1045
+ var trailer string
1046
+ form .Title , trailer = util .SplitStringAtByteN (form .Title , 255 )
1047
+
1048
+ form .Content = trailer + "\n \n " + form .Content
1049
+ }
1050
+ middleware .AssignForm (form , ctx .Data )
1051
+
1040
1052
ctx .HTML (http .StatusOK , tplCompareDiff )
1041
1053
return
1042
1054
}
Original file line number Diff line number Diff line change 176
176
{{if .IsNothingToCompare}}
177
177
{{if and $.IsSigned $.AllowEmptyPr (not .Repository.IsArchived) }}
178
178
<div class="ui segment">{{.i18n.Tr "repo.pulls.nothing_to_compare_and_allow_empty_pr"}}</div>
179
- <div class="ui info message show-form-container">
179
+ <div class="ui info message show-form-container" {{if .Flash}}style="display: none"{{end}} >
180
180
<button class="ui button green show-form">{{.i18n.Tr "repo.pulls.new"}}</button>
181
181
</div>
182
- <div class="pullrequest-form" style="display: none">
182
+ <div class="pullrequest-form" {{if not .Flash}} style="display: none"{{end}} >
183
183
{{template "repo/issue/new_form" .}}
184
184
</div>
185
185
{{else}}
192
192
</div>
193
193
{{else}}
194
194
{{if and $.IsSigned (not .Repository.IsArchived)}}
195
- <div class="ui info message show-form-container">
195
+ <div class="ui info message show-form-container" {{if .Flash}}style="display: none"{{end}} >
196
196
<button class="ui button green show-form">{{.i18n.Tr "repo.pulls.new"}}</button>
197
197
</div>
198
198
{{else if .Repository.IsArchived}}
201
201
</div>
202
202
{{end}}
203
203
{{if $.IsSigned}}
204
- <div class="pullrequest-form" style="display: none">
204
+ <div class="pullrequest-form" {{if not .Flash}} style="display: none"{{end}} >
205
205
{{template "repo/issue/new_form" .}}
206
206
</div>
207
207
{{end}}
You can’t perform that action at this time.
0 commit comments