Skip to content

Commit 9769172

Browse files
authored
Merge branch 'release/v1.22' into backport/32079-to-v1.22
2 parents f8cbf5b + 5c73da7 commit 9769172

File tree

10 files changed

+56
-28
lines changed

10 files changed

+56
-28
lines changed

cmd/serv.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,12 @@ func runServ(c *cli.Context) error {
143143
return nil
144144
}
145145

146+
defer func() {
147+
if err := recover(); err != nil {
148+
_ = fail(ctx, "Internal Server Error", "Panic: %v\n%s", err, log.Stack(2))
149+
}
150+
}()
151+
146152
keys := strings.Split(c.Args().First(), "-")
147153
if len(keys) != 2 || keys[0] != "key" {
148154
return fail(ctx, "Key ID format error", "Invalid key argument: %s", c.Args().First())
@@ -189,10 +195,7 @@ func runServ(c *cli.Context) error {
189195
}
190196

191197
verb := words[0]
192-
repoPath := words[1]
193-
if repoPath[0] == '/' {
194-
repoPath = repoPath[1:]
195-
}
198+
repoPath := strings.TrimPrefix(words[1], "/")
196199

197200
var lfsVerb string
198201
if verb == lfsAuthenticateVerb {

routers/web/repo/issue.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ func issues(ctx *context.Context, milestoneID, projectID int64, isPullOption opt
461461
ctx.Data["AssigneeID"] = assigneeID
462462
ctx.Data["PosterID"] = posterID
463463
ctx.Data["Keyword"] = keyword
464+
ctx.Data["IsShowClosed"] = isShowClosed
464465
switch {
465466
case isShowClosed.Value():
466467
ctx.Data["State"] = "closed"

routers/web/web.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1063,7 +1063,7 @@ func registerRoutes(m *web.Route) {
10631063
m.Combo("/edit").Get(repo_setting.SettingsProtectedBranch).
10641064
Post(web.Bind(forms.ProtectBranchForm{}), context.RepoMustNotBeArchived(), repo_setting.SettingsProtectedBranchPost)
10651065
m.Post("/{id}/delete", repo_setting.DeleteProtectedBranchRulePost)
1066-
}, repo.MustBeNotEmpty)
1066+
})
10671067

10681068
m.Group("/tags", func() {
10691069
m.Get("", repo_setting.ProtectedTags)

services/webhook/discord.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"net/url"
1212
"strconv"
1313
"strings"
14+
"unicode/utf8"
1415

1516
webhook_model "code.gitea.io/gitea/models/webhook"
1617
"code.gitea.io/gitea/modules/git"
@@ -149,8 +150,14 @@ func (d discordConvertor) Push(p *api.PushPayload) (DiscordPayload, error) {
149150
var text string
150151
// for each commit, generate attachment text
151152
for i, commit := range p.Commits {
152-
text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL,
153-
strings.TrimRight(commit.Message, "\r\n"), commit.Author.Name)
153+
// limit the commit message display to just the summary, otherwise it would be hard to read
154+
message := strings.TrimRight(strings.SplitN(commit.Message, "\n", 1)[0], "\r")
155+
156+
// a limit of 50 is set because GitHub does the same
157+
if utf8.RuneCountInString(message) > 50 {
158+
message = fmt.Sprintf("%.47s...", message)
159+
}
160+
text += fmt.Sprintf("[%s](%s) %s - %s", commit.ID[:7], commit.URL, message, commit.Author.Name)
154161
// add linebreak to each commit but the last
155162
if i < len(p.Commits)-1 {
156163
text += "\n"

services/webhook/discord_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,20 @@ func TestDiscordPayload(t *testing.T) {
8080
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
8181
})
8282

83+
t.Run("PushWithLongCommitMessage", func(t *testing.T) {
84+
p := pushTestMultilineCommitMessagePayload()
85+
86+
pl, err := dc.Push(p)
87+
require.NoError(t, err)
88+
89+
assert.Len(t, pl.Embeds, 1)
90+
assert.Equal(t, "[test/repo:test] 2 new commits", pl.Embeds[0].Title)
91+
assert.Equal(t, "[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好... - user1\n[2020558](http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778) This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好... - user1", pl.Embeds[0].Description)
92+
assert.Equal(t, p.Sender.UserName, pl.Embeds[0].Author.Name)
93+
assert.Equal(t, setting.AppURL+p.Sender.UserName, pl.Embeds[0].Author.URL)
94+
assert.Equal(t, p.Sender.AvatarURL, pl.Embeds[0].Author.IconURL)
95+
})
96+
8397
t.Run("Issue", func(t *testing.T) {
8498
p := issueTestPayload()
8599

services/webhook/general_test.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,17 @@ func forkTestPayload() *api.ForkPayload {
6464
}
6565

6666
func pushTestPayload() *api.PushPayload {
67+
return pushTestPayloadWithCommitMessage("commit message")
68+
}
69+
70+
func pushTestMultilineCommitMessagePayload() *api.PushPayload {
71+
return pushTestPayloadWithCommitMessage("This is a commit summary ⚠️⚠️⚠️⚠️ containing 你好 ⚠️⚠️️\n\nThis is the message body.")
72+
}
73+
74+
func pushTestPayloadWithCommitMessage(message string) *api.PushPayload {
6775
commit := &api.PayloadCommit{
6876
ID: "2020558fe2e34debb818a514715839cabd25e778",
69-
Message: "commit message",
77+
Message: message,
7078
URL: "http://localhost:3000/test/repo/commit/2020558fe2e34debb818a514715839cabd25e778",
7179
Author: &api.PayloadUser{
7280
Name: "user1",

templates/repo/issue/filter_actions.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<div class="ui secondary filter menu">
22
{{if not .Repository.IsArchived}}
33
<!-- Action Button -->
4-
{{if .IsShowClosed}}
4+
{{if and .IsShowClosed.Has .IsShowClosed.Value}}
55
<button class="ui primary basic button issue-action" data-action="open" data-url="{{$.RepoLink}}/issues/status">{{ctx.Locale.Tr "repo.issues.action_open"}}</button>
6-
{{else}}
6+
{{else if and .IsShowClosed.Has (not .IsShowClosed.Value)}}
77
<button class="ui red basic button issue-action" data-action="close" data-url="{{$.RepoLink}}/issues/status">{{ctx.Locale.Tr "repo.issues.action_close"}}</button>
88
{{end}}
99
{{if $.IsRepoAdmin}}

templates/repo/settings/branches.tmpl

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,17 @@
1515
<form class="tw-flex" action="{{.Link}}" method="post">
1616
{{.CsrfTokenHtml}}
1717
<input type="hidden" name="action" value="default_branch">
18-
{{if not .Repository.IsEmpty}}
19-
<div class="ui dropdown selection search tw-flex-1 tw-mr-2 tw-max-w-96">
20-
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
21-
<input type="hidden" name="branch" value="{{.Repository.DefaultBranch}}">
22-
<div class="default text">{{.Repository.DefaultBranch}}</div>
23-
<div class="menu">
24-
{{range .Branches}}
25-
<div class="item" data-value="{{.}}">{{.}}</div>
26-
{{end}}
27-
</div>
18+
<div class="ui dropdown selection search tw-flex-1 tw-mr-2 tw-max-w-96">
19+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
20+
<input type="hidden" name="branch" value="{{.Repository.DefaultBranch}}">
21+
<div class="default text">{{.Repository.DefaultBranch}}</div>
22+
<div class="menu">
23+
{{range .Branches}}
24+
<div class="item" data-value="{{.}}">{{.}}</div>
25+
{{end}}
2826
</div>
29-
<button class="ui primary button">{{ctx.Locale.Tr "repo.settings.branches.update_default_branch"}}</button>
30-
{{end}}
27+
</div>
28+
<button class="ui primary button"{{if .Repository.IsEmpty}} disabled{{end}}>{{ctx.Locale.Tr "repo.settings.branches.update_default_branch"}}</button>
3129
</form>
3230
</div>
3331

templates/repo/settings/navbar.tmpl

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,9 @@
1313
</a>
1414
{{end}}
1515
{{if .Repository.UnitEnabled $.Context ctx.Consts.RepoUnitTypeCode}}
16-
{{if not .Repository.IsEmpty}}
17-
<a class="{{if .PageIsSettingsBranches}}active {{end}}item" href="{{.RepoLink}}/settings/branches">
18-
{{ctx.Locale.Tr "repo.settings.branches"}}
19-
</a>
20-
{{end}}
16+
<a class="{{if .PageIsSettingsBranches}}active {{end}}item" href="{{.RepoLink}}/settings/branches">
17+
{{ctx.Locale.Tr "repo.settings.branches"}}
18+
</a>
2119
<a class="{{if .PageIsSettingsTags}}active {{end}}item" href="{{.RepoLink}}/settings/tags">
2220
{{ctx.Locale.Tr "repo.settings.tags"}}
2321
</a>

web_src/js/components/DashboardRepoList.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ const sfc = {
7878
searchURL() {
7979
return `${this.subUrl}/repo/search?sort=updated&order=desc&uid=${this.uid}&team_id=${this.teamId}&q=${this.searchQuery
8080
}&page=${this.page}&limit=${this.searchLimit}&mode=${this.repoTypes[this.reposFilter].searchMode
81-
}${this.reposFilter !== 'all' ? '&exclusive=1' : ''
8281
}${this.archivedFilter === 'archived' ? '&archived=true' : ''}${this.archivedFilter === 'unarchived' ? '&archived=false' : ''
8382
}${this.privateFilter === 'private' ? '&is_private=true' : ''}${this.privateFilter === 'public' ? '&is_private=false' : ''
8483
}`;

0 commit comments

Comments
 (0)