Skip to content

Commit 0e2098a

Browse files
authored
Merge branch 'main' into fix-21448
2 parents c25416c + b9cd6fb commit 0e2098a

File tree

10 files changed

+55
-25
lines changed

10 files changed

+55
-25
lines changed

CONTRIBUTING.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,16 @@ If your PR could cause a breaking change you must add a BREAKING section to this
146146

147147
To explain how this could affect users and how to mitigate these changes.
148148

149+
Once code review starts on your PR, do not rebase nor squash your branch as it makes it
150+
difficult to review the new changes. Only if there is a need, sync your branch by merging
151+
the base branch into yours. Don't worry about merge commits messing up your tree as
152+
the final merge process squashes all commits into one, with the visible commit message (first
153+
line) being the PR title + PR index and description being the PR's first comment.
154+
155+
Once your PR gets the `lgtm/done` label, don't worry about keeping it up-to-date or breaking
156+
builds (unless there's a merge conflict or a request is made by a maintainer to make
157+
modifications). It is the maintainer team's responsibility from this point to get it merged.
158+
149159
## Styleguide
150160

151161
For imports you should use the following format (*without* the comments)

modules/templates/helper.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,7 @@ func NewFuncMap() []template.FuncMap {
161161
"RenderCommitMessageLink": RenderCommitMessageLink,
162162
"RenderCommitMessageLinkSubject": RenderCommitMessageLinkSubject,
163163
"RenderCommitBody": RenderCommitBody,
164+
"RenderCodeBlock": RenderCodeBlock,
164165
"RenderIssueTitle": RenderIssueTitle,
165166
"RenderEmoji": RenderEmoji,
166167
"RenderEmojiPlain": emoji.ReplaceAliases,
@@ -795,6 +796,16 @@ func RenderCommitBody(ctx context.Context, msg, urlPrefix string, metas map[stri
795796
return template.HTML(renderedMessage)
796797
}
797798

799+
// Match text that is between back ticks.
800+
var codeMatcher = regexp.MustCompile("`([^`]+)`")
801+
802+
// RenderCodeBlock renders "`…`" as highlighted "<code>" block.
803+
// Intended for issue and PR titles, these containers should have styles for "<code>" elements
804+
func RenderCodeBlock(htmlEscapedTextToRender template.HTML) template.HTML {
805+
htmlWithCodeTags := codeMatcher.ReplaceAllString(string(htmlEscapedTextToRender), "<code>$1</code>") // replace with HTML <code> tags
806+
return template.HTML(htmlWithCodeTags)
807+
}
808+
798809
// RenderIssueTitle renders issue/pull title with defined post processors
799810
func RenderIssueTitle(ctx context.Context, text, urlPrefix string, metas map[string]string) template.HTML {
800811
renderedText, err := markup.RenderIssueTitle(&markup.RenderContext{

routers/web/repo/wiki.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func findUncycloRepoCommit(ctx *context.Context) (*git.Repository, *git.Commit, err
9999
return nil, nil, err
100100
}
101101

102-
commit, err := wikiRepo.GetBranchCommit("master")
102+
commit, err := wikiRepo.GetBranchCommit(wiki_service.DefaultBranch)
103103
if err != nil {
104104
return wikiRepo, nil, err
105105
}
@@ -302,7 +302,7 @@ func renderViewPage(ctx *context.Context) (*git.Repository, *git.TreeEntry) {
302302
ctx.Data["toc"] = rctx.TableOfContents
303303

304304
// get commit count - wiki revisions
305-
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
305+
commitsCount, _ := wikiRepo.FileCommitsCount(wiki_service.DefaultBranch, pageFilename)
306306
ctx.Data["CommitCount"] = commitsCount
307307

308308
return wikiRepo, entry
@@ -351,7 +351,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
351351
ctx.Data["footerContent"] = ""
352352

353353
// get commit count - wiki revisions
354-
commitsCount, _ := wikiRepo.FileCommitsCount("master", pageFilename)
354+
commitsCount, _ := wikiRepo.FileCommitsCount(wiki_service.DefaultBranch, pageFilename)
355355
ctx.Data["CommitCount"] = commitsCount
356356

357357
// get page
@@ -361,7 +361,7 @@ func renderRevisionPage(ctx *context.Context) (*git.Repository, *git.TreeEntry)
361361
}
362362

363363
// get Commit Count
364-
commitsHistory, err := wikiRepo.CommitsByFileAndRange("master", pageFilename, page)
364+
commitsHistory, err := wikiRepo.CommitsByFileAndRange(wiki_service.DefaultBranch, pageFilename, page)
365365
if err != nil {
366366
if wikiRepo != nil {
367367
wikiRepo.Close()

services/wiki/wiki.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ var (
3030
wikiWorkingPool = sync.NewExclusivePool()
3131
)
3232

33+
const (
34+
DefaultRemote = "origin"
35+
DefaultBranch = "master"
36+
)
37+
3338
func nameAllowed(name string) error {
3439
if util.IsStringInSlice(name, reservedUncycloNames) {
3540
return repo_model.ErrUncycloReservedName{
@@ -81,7 +86,7 @@ func InitUncyclo(ctx context.Context, repo *repo_model.Repository) error {
8186
return fmt.Errorf("InitRepository: %v", err)
8287
} else if err = repo_module.CreateDelegateHooks(repo.UncycloPath()); err != nil {
8388
return fmt.Errorf("createDelegateHooks: %v", err)
84-
} else if _, _, err = git.NewCommand(ctx, "symbolic-ref", "HEAD", git.BranchPrefix+"master").RunStdString(&git.RunOpts{Dir: repo.UncycloPath()}); err != nil {
89+
} else if _, _, err = git.NewCommand(ctx, "symbolic-ref", "HEAD", git.BranchPrefix+DefaultBranch).RunStdString(&git.RunOpts{Dir: repo.UncycloPath()}); err != nil {
8590
return fmt.Errorf("unable to set default wiki branch to master: %v", err)
8691
}
8792
return nil
@@ -94,7 +99,7 @@ func prepareUncycloFileName(gitRepo *git.Repository, wikiName string) (bool, string
9499
escaped := NameToFilename(wikiName)
95100

96101
// Look for both files
97-
filesInIndex, err := gitRepo.LsTree("master", unescaped, escaped)
102+
filesInIndex, err := gitRepo.LsTree(DefaultBranch, unescaped, escaped)
98103
if err != nil {
99104
if strings.Contains(err.Error(), "Not a valid object name master") {
100105
return false, escaped, nil
@@ -130,7 +135,7 @@ func updateUncycloPage(ctx context.Context, doer *user_model.User, repo *repo_model
130135
return fmt.Errorf("InitUncyclo: %v", err)
131136
}
132137

133-
hasMasterBranch := git.IsBranchExist(ctx, repo.UncycloPath(), "master")
138+
hasMasterBranch := git.IsBranchExist(ctx, repo.UncycloPath(), DefaultBranch)
134139

135140
basePath, err := repo_module.CreateTemporaryPath("update-wiki")
136141
if err != nil {
@@ -148,7 +153,7 @@ func updateUncycloPage(ctx context.Context, doer *user_model.User, repo *repo_model
148153
}
149154

150155
if hasMasterBranch {
151-
cloneOpts.Branch = "master"
156+
cloneOpts.Branch = DefaultBranch
152157
}
153158

154159
if err := git.Clone(ctx, repo.UncycloPath(), basePath, cloneOpts); err != nil {
@@ -246,8 +251,8 @@ func updateUncycloPage(ctx context.Context, doer *user_model.User, repo *repo_model
246251
}
247252

248253
if err := git.Push(gitRepo.Ctx, basePath, git.PushOptions{
249-
Remote: "origin",
250-
Branch: fmt.Sprintf("%s:%s%s", commitHash.String(), git.BranchPrefix, "master"),
254+
Remote: DefaultRemote,
255+
Branch: fmt.Sprintf("%s:%s%s", commitHash.String(), git.BranchPrefix, DefaultBranch),
251256
Env: repo_module.FullPushingEnvironment(
252257
doer,
253258
doer,
@@ -299,7 +304,7 @@ func DeleteUncycloPage(ctx context.Context, doer *user_model.User, repo *repo_model
299304
if err := git.Clone(ctx, repo.UncycloPath(), basePath, git.CloneRepoOptions{
300305
Bare: true,
301306
Shared: true,
302-
Branch: "master",
307+
Branch: DefaultBranch,
303308
}); err != nil {
304309
log.Error("Failed to clone repository: %s (%v)", repo.FullName(), err)
305310
return fmt.Errorf("Failed to clone repository: %s (%v)", repo.FullName(), err)
@@ -360,8 +365,8 @@ func DeleteUncycloPage(ctx context.Context, doer *user_model.User, repo *repo_model
360365
}
361366

362367
if err := git.Push(gitRepo.Ctx, basePath, git.PushOptions{
363-
Remote: "origin",
364-
Branch: fmt.Sprintf("%s:%s%s", commitHash.String(), git.BranchPrefix, "master"),
368+
Remote: DefaultRemote,
369+
Branch: fmt.Sprintf("%s:%s%s", commitHash.String(), git.BranchPrefix, DefaultBranch),
365370
Env: repo_module.PushingEnvironment(doer, repo),
366371
}); err != nil {
367372
if git.IsErrPushOutOfDate(err) || git.IsErrPushRejected(err) {

services/wiki/wiki_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func TestRepository_AddUncycloPage(t *testing.T) {
140140
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.UncycloPath())
141141
assert.NoError(t, err)
142142
defer gitRepo.Close()
143-
masterTree, err := gitRepo.GetTree("master")
143+
masterTree, err := gitRepo.GetTree(DefaultBranch)
144144
assert.NoError(t, err)
145145
wikiPath := NameToFilename(wikiName)
146146
entry, err := masterTree.GetTreeEntryByPath(wikiPath)
@@ -184,7 +184,7 @@ func TestRepository_EditUncycloPage(t *testing.T) {
184184
// Now need to show that the page has been added:
185185
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.UncycloPath())
186186
assert.NoError(t, err)
187-
masterTree, err := gitRepo.GetTree("master")
187+
masterTree, err := gitRepo.GetTree(DefaultBranch)
188188
assert.NoError(t, err)
189189
wikiPath := NameToFilename(newUncycloName)
190190
entry, err := masterTree.GetTreeEntryByPath(wikiPath)
@@ -209,7 +209,7 @@ func TestRepository_DeleteUncycloPage(t *testing.T) {
209209
gitRepo, err := git.OpenRepository(git.DefaultContext, repo.UncycloPath())
210210
assert.NoError(t, err)
211211
defer gitRepo.Close()
212-
masterTree, err := gitRepo.GetTree("master")
212+
masterTree, err := gitRepo.GetTree(DefaultBranch)
213213
assert.NoError(t, err)
214214
wikiPath := NameToFilename("Home")
215215
_, err = masterTree.GetTreeEntryByPath(wikiPath)

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">{{RenderIssueTitle $.Context .Issue.Title $.RepoLink $.Repository.ComposeMetas}}</span>
9+
<span id="issue-title">{{RenderIssueTitle $.Context .Issue.Title $.RepoLink $.Repository.ComposeMetas | RenderCodeBlock}}</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" autocomplete="off">

templates/shared/issuelist.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
</div>
3636
<div class="issue-item-main f1 fc df">
3737
<div class="issue-item-top-row">
38-
<a class="title tdn" href="{{if .HTMLURL}}{{.HTMLURL}}{{else}}{{$.Link}}/{{.Index}}{{end}}">{{RenderEmoji .Title}}</a>
38+
<a class="title tdn issue-title" href="{{if .HTMLURL}}{{.HTMLURL}}{{else}}{{$.Link}}/{{.Index}}{{end}}">{{RenderEmoji .Title | RenderCodeBlock}}</a>
3939
{{if .IsPull}}
4040
{{if (index $.CommitStatuses .PullRequest.ID)}}
4141
{{template "repo/commit_statuses" dict "Status" (index $.CommitLastStatus .PullRequest.ID) "Statuses" (index $.CommitStatuses .PullRequest.ID) "root" $}}

templates/user/dashboard/feeds.tmpl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,17 @@
9999
</ul>
100100
</div>
101101
{{else if eq .GetOpType 6}}
102-
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji}}</span>
102+
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}}</span>
103103
{{else if eq .GetOpType 7}}
104-
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji}}</span>
104+
<span class="text truncate issue title">{{index .GetIssueInfos 1 | RenderEmoji | RenderCodeBlock}}</span>
105105
{{else if or (eq .GetOpType 10) (eq .GetOpType 21) (eq .GetOpType 22) (eq .GetOpType 23)}}
106-
<a href="{{.GetCommentLink}}" class="text truncate issue title">{{.GetIssueTitle | RenderEmoji}}</a>
106+
<a href="{{.GetCommentLink}}" class="text truncate issue title">{{.GetIssueTitle | RenderEmoji | RenderCodeBlock}}</a>
107107
{{$comment := index .GetIssueInfos 1}}
108108
{{if gt (len $comment) 0}}<p class="text light grey">{{$comment | RenderEmoji}}</p>{{end}}
109109
{{else if eq .GetOpType 11}}
110110
<p class="text light grey">{{index .GetIssueInfos 1}}</p>
111111
{{else if or (eq .GetOpType 12) (eq .GetOpType 13) (eq .GetOpType 14) (eq .GetOpType 15)}}
112-
<span class="text truncate issue title">{{.GetIssueTitle | RenderEmoji}}</span>
112+
<span class="text truncate issue title">{{.GetIssueTitle | RenderEmoji | RenderCodeBlock}}</span>
113113
{{else if eq .GetOpType 25}}
114114
<p class="text light grey">{{$.locale.Tr "action.review_dismissed_reason"}}</p>
115115
<p class="text light grey">{{index .GetIssueInfos 2 | RenderEmoji}}</p>

web_src/less/_base.less

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,11 @@ a.commit-statuses-trigger {
332332
&:extend(.unselectable);
333333
}
334334

335+
.issue-title code {
336+
padding: 2px 4px;
337+
border-radius: 6px;
338+
background-color: var(--color-markup-code-block);
339+
}
335340
/* try to match button with no icons in height */
336341
.icon-button {
337342
padding-top: 7.42px !important;

web_src/less/_dashboard.less

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,9 @@
141141
}
142142

143143
code {
144-
padding: 1px;
145-
font-size: 85%;
146-
background-color: rgba(0, 0, 0, .04);
144+
padding: 2px 4px;
147145
border-radius: 3px;
146+
background-color: var(--color-markup-code-block);
148147
word-break: break-all;
149148
}
150149

0 commit comments

Comments
 (0)