Skip to content

Commit d4f3fc7

Browse files
committed
Merge remote-tracking branch 'upstream/main'
* upstream/main: Replace a few fontawesome icons with svg (go-gitea#23602) Fix pagination on `/notifications/watching` (go-gitea#23564) Fix `.locale.Tr` function not found in delete modal (go-gitea#23468) fix submodule is nil panic (go-gitea#23588) `Publish Review` buttons should indicate why they are disabled (go-gitea#23598) Improve template error reporting (go-gitea#23396) Polyfill the window.customElements (go-gitea#23592) Add CHANGELOG for 1.19.0 (go-gitea#23583)
2 parents 025c6c0 + 34a2cf5 commit d4f3fc7

File tree

16 files changed

+477
-32
lines changed

16 files changed

+477
-32
lines changed

CHANGELOG.md

Lines changed: 350 additions & 0 deletions
Large diffs are not rendered by default.

modules/context/context.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ import (
1616
"net/http"
1717
"net/url"
1818
"path"
19+
"regexp"
1920
"strconv"
2021
"strings"
22+
texttemplate "text/template"
2123
"time"
2224

2325
"code.gitea.io/gitea/models/db"
@@ -213,6 +215,8 @@ func (ctx *Context) RedirectToFirst(location ...string) {
213215
ctx.Redirect(setting.AppSubURL + "/")
214216
}
215217

218+
var templateExecutingErr = regexp.MustCompile(`^template: (.*):([1-9][0-9]*):([1-9][0-9]*): executing (?:"(.*)" at <(.*)>: )?`)
219+
216220
// HTML calls Context.HTML and renders the template to HTTP response
217221
func (ctx *Context) HTML(status int, name base.TplName) {
218222
log.Debug("Template: %s", name)
@@ -228,6 +232,34 @@ func (ctx *Context) HTML(status int, name base.TplName) {
228232
ctx.PlainText(http.StatusInternalServerError, "Unable to find status/500 template")
229233
return
230234
}
235+
if execErr, ok := err.(texttemplate.ExecError); ok {
236+
if groups := templateExecutingErr.FindStringSubmatch(err.Error()); len(groups) > 0 {
237+
errorTemplateName, lineStr, posStr := groups[1], groups[2], groups[3]
238+
target := ""
239+
if len(groups) == 6 {
240+
target = groups[5]
241+
}
242+
line, _ := strconv.Atoi(lineStr) // Cannot error out as groups[2] is [1-9][0-9]*
243+
pos, _ := strconv.Atoi(posStr) // Cannot error out as groups[3] is [1-9][0-9]*
244+
filename, filenameErr := templates.GetAssetFilename("templates/" + errorTemplateName + ".tmpl")
245+
if filenameErr != nil {
246+
filename = "(template) " + errorTemplateName
247+
}
248+
if errorTemplateName != string(name) {
249+
filename += " (subtemplate of " + string(name) + ")"
250+
}
251+
err = fmt.Errorf("%w\nin template file %s:\n%s", err, filename, templates.GetLineFromTemplate(errorTemplateName, line, target, pos))
252+
} else {
253+
filename, filenameErr := templates.GetAssetFilename("templates/" + execErr.Name + ".tmpl")
254+
if filenameErr != nil {
255+
filename = "(template) " + execErr.Name
256+
}
257+
if execErr.Name != string(name) {
258+
filename += " (subtemplate of " + string(name) + ")"
259+
}
260+
err = fmt.Errorf("%w\nin template file %s", err, filename)
261+
}
262+
}
231263
ctx.ServerError("Render failed", err)
232264
}
233265
}

modules/templates/htmlrenderer.go

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func handleGenericTemplateError(err error) (string, []interface{}) {
118118

119119
lineNumber, _ := strconv.Atoi(lineNumberStr)
120120

121-
line := getLineFromAsset(templateName, lineNumber, "")
121+
line := GetLineFromTemplate(templateName, lineNumber, "", -1)
122122

123123
return "PANIC: Unable to compile templates!\n%s in template file %s at line %d:\n\n%s\nStacktrace:\n\n%s", []interface{}{message, filename, lineNumber, log.NewColoredValue(line, log.Reset), log.Stack(2)}
124124
}
@@ -140,7 +140,7 @@ func handleNotDefinedPanicError(err error) (string, []interface{}) {
140140

141141
lineNumber, _ := strconv.Atoi(lineNumberStr)
142142

143-
line := getLineFromAsset(templateName, lineNumber, functionName)
143+
line := GetLineFromTemplate(templateName, lineNumber, functionName, -1)
144144

145145
return "PANIC: Unable to compile templates!\nUndefined function %q in template file %s at line %d:\n\n%s", []interface{}{functionName, filename, lineNumber, log.NewColoredValue(line, log.Reset)}
146146
}
@@ -161,7 +161,7 @@ func handleUnexpected(err error) (string, []interface{}) {
161161

162162
lineNumber, _ := strconv.Atoi(lineNumberStr)
163163

164-
line := getLineFromAsset(templateName, lineNumber, unexpected)
164+
line := GetLineFromTemplate(templateName, lineNumber, unexpected, -1)
165165

166166
return "PANIC: Unable to compile templates!\nUnexpected %q in template file %s at line %d:\n\n%s", []interface{}{unexpected, filename, lineNumber, log.NewColoredValue(line, log.Reset)}
167167
}
@@ -181,14 +181,15 @@ func handleExpectedEnd(err error) (string, []interface{}) {
181181

182182
lineNumber, _ := strconv.Atoi(lineNumberStr)
183183

184-
line := getLineFromAsset(templateName, lineNumber, unexpected)
184+
line := GetLineFromTemplate(templateName, lineNumber, unexpected, -1)
185185

186186
return "PANIC: Unable to compile templates!\nMissing end with unexpected %q in template file %s at line %d:\n\n%s", []interface{}{unexpected, filename, lineNumber, log.NewColoredValue(line, log.Reset)}
187187
}
188188

189189
const dashSeparator = "----------------------------------------------------------------------\n"
190190

191-
func getLineFromAsset(templateName string, targetLineNum int, target string) string {
191+
// GetLineFromTemplate returns a line from a template with some context
192+
func GetLineFromTemplate(templateName string, targetLineNum int, target string, position int) string {
192193
bs, err := GetAsset("templates/" + templateName + ".tmpl")
193194
if err != nil {
194195
return fmt.Sprintf("(unable to read template file: %v)", err)
@@ -229,23 +230,29 @@ func getLineFromAsset(templateName string, targetLineNum int, target string) str
229230
// If there is a provided target to look for in the line add a pointer to it
230231
// e.g. ^^^^^^^
231232
if target != "" {
232-
idx := bytes.Index(lineBs, []byte(target))
233-
234-
if idx >= 0 {
235-
// take the current line and replace preceding text with whitespace (except for tab)
236-
for i := range lineBs[:idx] {
237-
if lineBs[i] != '\t' {
238-
lineBs[i] = ' '
239-
}
233+
targetPos := bytes.Index(lineBs, []byte(target))
234+
if targetPos >= 0 {
235+
position = targetPos
236+
}
237+
}
238+
if position >= 0 {
239+
// take the current line and replace preceding text with whitespace (except for tab)
240+
for i := range lineBs[:position] {
241+
if lineBs[i] != '\t' {
242+
lineBs[i] = ' '
240243
}
244+
}
241245

242-
// write the preceding "space"
243-
_, _ = sb.Write(lineBs[:idx])
246+
// write the preceding "space"
247+
_, _ = sb.Write(lineBs[:position])
244248

245-
// Now write the ^^ pointer
246-
_, _ = sb.WriteString(strings.Repeat("^", len(target)))
247-
_ = sb.WriteByte('\n')
249+
// Now write the ^^ pointer
250+
targetLen := len(target)
251+
if targetLen == 0 {
252+
targetLen = 1
248253
}
254+
_, _ = sb.WriteString(strings.Repeat("^", targetLen))
255+
_ = sb.WriteByte('\n')
249256
}
250257

251258
// Finally write the footer

options/locale/locale_en-US.ini

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,7 +2265,9 @@ diff.review.header = Submit review
22652265
diff.review.placeholder = Review comment
22662266
diff.review.comment = Comment
22672267
diff.review.approve = Approve
2268+
diff.review.self_reject = Pull request authors can't request changes on their own pull request
22682269
diff.review.reject = Request changes
2270+
diff.review.self_approve = Pull request authors can't approve their own pull request
22692271
diff.committed_by = committed by
22702272
diff.protected = Protected
22712273
diff.image.side_by_side = Side by Side

package-lock.json

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"@mcaptcha/vanilla-glue": "0.1.0-alpha-3",
1616
"@primer/octicons": "18.2.0",
1717
"@vue/compiler-sfc": "3.2.47",
18+
"@webcomponents/custom-elements": "1.5.1",
1819
"add-asset-webpack-plugin": "2.0.1",
1920
"ansi-to-html": "0.7.2",
2021
"asciinema-player": "3.2.0",

routers/web/user/notification.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ func NotificationWatching(ctx *context.Context) {
344344
page = 1
345345
}
346346

347+
keyword := ctx.FormTrim("q")
348+
ctx.Data["Keyword"] = keyword
349+
347350
var orderBy db.SearchOrderBy
348351
ctx.Data["SortType"] = ctx.FormString("sort")
349352
switch ctx.FormString("sort") {
@@ -378,7 +381,7 @@ func NotificationWatching(ctx *context.Context) {
378381
Page: page,
379382
},
380383
Actor: ctx.Doer,
381-
Keyword: ctx.FormTrim("q"),
384+
Keyword: keyword,
382385
OrderBy: orderBy,
383386
Private: ctx.IsSigned,
384387
WatchedByID: ctx.Doer.ID,

services/repository/files/content.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,9 @@ func GetContents(ctx context.Context, repo *repo_model.Repository, treePath, ref
214214
if err != nil {
215215
return nil, err
216216
}
217-
contentsResponse.SubmoduleGitURL = &submodule.URL
217+
if submodule != nil && submodule.URL != "" {
218+
contentsResponse.SubmoduleGitURL = &submodule.URL
219+
}
218220
}
219221
// Handle links
220222
if entry.IsRegular() || entry.IsLink() {

templates/admin/repo/unadopted.tmpl

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,16 @@
4343
<input type="hidden" name="action" value="adopt">
4444
<input type="hidden" name="q" value="{{$.Keyword}}">
4545
<input type="hidden" name="page" value="{{$.CurrentPage}}">
46-
{{template "base/delete_modal_actions" .}}
46+
<div class="actions">
47+
<button class="ui red basic inverted cancel button">
48+
{{svg "octicon-trash" 16 "gt-mr-2"}}
49+
{{$.locale.Tr "modal.no"}}
50+
</button>
51+
<button class="ui green basic inverted ok button">
52+
{{svg "octicon-check" 16 "gt-mr-2"}}
53+
{{$.locale.Tr "modal.yes"}}
54+
</button>
55+
</div>
4756
</form>
4857
</div>
4958
<button class="ui button submit tiny red delete show-modal" data-modal="#delete-unadopted-modal-{{$dirI}}"><span class="icon">{{svg "octicon-x"}}</span><span class="label">{{$.locale.Tr "repo.delete_preexisting_label"}}</span></button>
@@ -61,7 +70,16 @@
6170
<input type="hidden" name="action" value="delete">
6271
<input type="hidden" name="q" value="{{$.Keyword}}">
6372
<input type="hidden" name="page" value="{{$.CurrentPage}}">
64-
{{template "base/delete_modal_actions" .}}
73+
<div class="actions">
74+
<button class="ui red basic inverted cancel button">
75+
{{svg "octicon-trash" 16 "gt-mr-2"}}
76+
{{$.locale.Tr "modal.no"}}
77+
</button>
78+
<button class="ui green basic inverted ok button">
79+
{{svg "octicon-check" 16 "gt-mr-2"}}
80+
{{$.locale.Tr "modal.yes"}}
81+
</button>
82+
</div>
6583
</form>
6684
</div>
6785
</div>

templates/org/team/repositories.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@
7777

7878
<div class="ui small basic addall modal">
7979
<div class="ui icon header">
80-
<i class="globe icon"></i>
80+
{{svg "octicon-globe"}}
8181
{{.locale.Tr "org.teams.add_all_repos_title"}}
8282
</div>
8383
<div class="content">

templates/repo/diff/new_review.tmpl

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,22 @@
2222
</div>
2323
{{end}}
2424
<div class="ui divider"></div>
25-
<button type="submit" name="type" value="approve" {{if and $.IsSigned ($.Issue.IsPoster $.SignedUser.ID)}} disabled {{end}} class="ui submit green tiny button btn-submit">{{$.locale.Tr "repo.diff.review.approve"}}</button>
25+
{{$showSelfTooltip := (and $.IsSigned ($.Issue.IsPoster $.SignedUser.ID))}}
26+
{{if $showSelfTooltip}}
27+
<span class="gt-dib tooltip" data-content="{{$.locale.Tr "repo.diff.review.self_approve"}}">
28+
<button type="submit" name="type" value="approve" disabled class="ui submit green tiny button btn-submit">{{$.locale.Tr "repo.diff.review.approve"}}</button>
29+
</span>
30+
{{else}}
31+
<button type="submit" name="type" value="approve" class="ui submit green tiny button btn-submit">{{$.locale.Tr "repo.diff.review.approve"}}</button>
32+
{{end}}
2633
<button type="submit" name="type" value="comment" class="ui submit tiny basic button btn-submit">{{$.locale.Tr "repo.diff.review.comment"}}</button>
27-
<button type="submit" name="type" value="reject" {{if and $.IsSigned ($.Issue.IsPoster $.SignedUser.ID)}} disabled {{end}} class="ui submit red tiny button btn-submit">{{$.locale.Tr "repo.diff.review.reject"}}</button>
34+
{{if $showSelfTooltip}}
35+
<span class="gt-dib tooltip" data-content="{{$.locale.Tr "repo.diff.review.self_reject"}}">
36+
<button type="submit" name="type" value="reject" disabled class="ui submit red tiny button btn-submit">{{$.locale.Tr "repo.diff.review.reject"}}</button>
37+
</span>
38+
{{else}}
39+
<button type="submit" name="type" value="reject" class="ui submit red tiny button btn-submit">{{$.locale.Tr "repo.diff.review.reject"}}</button>
40+
{{end}}
2841
</form>
2942
</div>
3043
</div>

templates/repo/editor/edit.tmpl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,19 +58,19 @@
5858

5959
<div class="ui small basic modal" id="edit-empty-content-modal">
6060
<div class="ui icon header">
61-
<i class="file icon"></i>
61+
{{svg "octicon-file"}}
6262
{{.locale.Tr "repo.editor.commit_empty_file_header"}}
6363
</div>
6464
<div class="center content">
6565
<p>{{.locale.Tr "repo.editor.commit_empty_file_text"}}</p>
6666
</div>
6767
<div class="actions">
6868
<button class="ui red basic cancel inverted button">
69-
<i class="remove icon"></i>
69+
{{svg "octicon-x"}}
7070
{{.locale.Tr "repo.editor.cancel"}}
7171
</button>
7272
<button class="ui green basic ok inverted button">
73-
<i class="save icon"></i>
73+
{{svg "fontawesome-save"}}
7474
{{.locale.Tr "repo.editor.commit_changes"}}
7575
</button>
7676
</div>

templates/repo/editor/patch.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838

3939
<div class="ui small basic modal" id="edit-empty-content-modal">
4040
<div class="ui icon header">
41-
<i class="file icon"></i>
41+
{{svg "octicon-file"}}
4242
{{.locale.Tr "repo.editor.commit_empty_file_header"}}
4343
</div>
4444
<div class="center content">

templates/user/auth/webauthn.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
{{.locale.Tr "twofa"}}
77
</h3>
88
<div class="ui attached segment">
9-
<i class="huge key icon"></i>
9+
{{svg "octicon-key" 56}}
1010
<h3>{{.locale.Tr "webauthn_insert_key"}}</h3>
1111
{{template "base/alert" .}}
1212
<p>{{.locale.Tr "webauthn_sign_in"}}</p>

templates/user/settings/repos.tmpl

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@
5050
{{$.CsrfTokenHtml}}
5151
<input type="hidden" name="id" value="{{$dir}}">
5252
<input type="hidden" name="action" value="adopt">
53-
{{template "base/delete_modal_actions" .}}
53+
<div class="actions">
54+
<button class="ui red basic inverted cancel button">
55+
{{svg "octicon-x"}}
56+
{{$.locale.Tr "modal.no"}}
57+
</button>
58+
<button class="ui green basic inverted ok button">
59+
{{svg "octicon-check"}}
60+
{{$.locale.Tr "modal.yes"}}
61+
</button>
62+
</div>
5463
</form>
5564
</div>
5665
{{end}}
@@ -68,7 +77,7 @@
6877
{{$.CsrfTokenHtml}}
6978
<input type="hidden" name="id" value="{{$dir}}">
7079
<input type="hidden" name="action" value="delete">
71-
{{template "base/delete_modal_actions" .}}
80+
{{template "base/delete_modal_actions" $}}
7281
</form>
7382
</div>
7483
{{end}}

web_src/js/webcomponents/GiteaOriginUrl.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import '@webcomponents/custom-elements'; // automatically adds custom elements for older browsers that don't support it
2+
13
// this is a Gitea's private HTML component, it converts an absolute or relative URL to an absolute URL with the current origin
24
window.customElements.define('gitea-origin-url', class extends HTMLElement {
35
connectedCallback() {

0 commit comments

Comments
 (0)