Skip to content

Commit 59d0606

Browse files
wxiaoguang6543silverwind
authored
Improve RSS (#24335)
Follow #22719 ### Major changes 1. `ServerError` doesn't do format, so remove the `%s` 2. Simplify `RenderBranchFeed` (slightly) 3. Remove unused `BranchFeedRSS` 4. Make `feed.RenderBranchFeed` respect `EnableFeed` config 5. Make `RepoBranchTagSelector.vue` respect `EnableFeed` setting, otherwise there is always RSS icon 6. The `(branchURLPrefix + item.url).replace('src', 'rss')` doesn't seem right for all cases, for example, the string `src` could appear in `branchURLPrefix`, so we need a separate `rssURLPrefix` 7. The `<a>` in Vue menu needs `@click.stop`, otherwise the menu itself would be triggered at the same time 8. Change `<a><button></button></a>` to `<a role=button>` 9. Use `{{PathEscapeSegments .TreePath}}` instead of `{{range $i, $v := .TreeNames}}/{{$v}}{{end}}` Screenshot of changed parts: <details> ![image](https://user-images.githubusercontent.com/2114189/234315538-66603694-9093-48a8-af33-83575fd7a018.png) ![image](https://user-images.githubusercontent.com/2114189/234315786-f1efa60b-012e-490b-8ce2-d448dc6fe5c9.png) ![image](https://user-images.githubusercontent.com/2114189/234334941-446941bc-1baa-4256-8850-ccc439476cda.png) </details> ### Other thoughts Should we remove the RSS icon from the branch dropdown list? It seems too complex for a list UI, and users already have the chance to get the RSS feed URL from "branches" page. --------- Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: silverwind <me@silverwind.io>
1 parent 5f21e0f commit 59d0606

File tree

10 files changed

+25
-25
lines changed

10 files changed

+25
-25
lines changed

routers/web/feed/branch.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func ShowBranchFeed(ctx *context.Context, repo *repo.Repository, formatType string) {
1919
commits, err := ctx.Repo.Commit.CommitsByRange(0, 10)
2020
if err != nil {
21-
ctx.ServerError("ShowBranchFeed %s", err)
21+
ctx.ServerError("ShowBranchFeed", err)
2222
return
2323
}
2424

routers/web/feed/file.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func ShowFileFeed(ctx *context.Context, repo *repo.Repository, formatType string
2323
}
2424
commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(ctx.Repo.RefName, fileName, 1)
2525
if err != nil {
26-
ctx.ServerError("ShowBranchFeed %s", err)
26+
ctx.ServerError("ShowBranchFeed", err)
2727
return
2828
}
2929

routers/web/feed/render.go

+4-8
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,15 @@
44
package feed
55

66
import (
7-
model "code.gitea.io/gitea/models/repo"
87
"code.gitea.io/gitea/modules/context"
98
)
109

1110
// RenderBranchFeed render format for branch or file
1211
func RenderBranchFeed(ctx *context.Context) {
1312
_, _, showFeedType := GetFeedType(ctx.Params(":reponame"), ctx.Req)
14-
var renderer func(ctx *context.Context, repo *model.Repository, formatType string)
15-
switch {
16-
case ctx.Repo.TreePath == "":
17-
renderer = ShowBranchFeed
18-
case ctx.Repo.TreePath != "":
19-
renderer = ShowFileFeed
13+
if ctx.Repo.TreePath == "" {
14+
ShowBranchFeed(ctx, ctx.Repo.Repository, showFeedType)
15+
} else {
16+
ShowFileFeed(ctx, ctx.Repo.Repository, showFeedType)
2017
}
21-
renderer(ctx, ctx.Repo.Repository, showFeedType)
2218
}

routers/web/repo/branch.go

-6
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ import (
2525
"code.gitea.io/gitea/modules/util"
2626
"code.gitea.io/gitea/modules/web"
2727
"code.gitea.io/gitea/routers/utils"
28-
"code.gitea.io/gitea/routers/web/feed"
2928
"code.gitea.io/gitea/services/forms"
3029
release_service "code.gitea.io/gitea/services/release"
3130
repo_service "code.gitea.io/gitea/services/repository"
@@ -341,11 +340,6 @@ func getDeletedBranches(ctx *context.Context) ([]*Branch, error) {
341340
return branches, nil
342341
}
343342

344-
// BranchFeedRSS get feeds for tags in RSS format
345-
func BranchFeedRSS(ctx *context.Context) {
346-
feed.ShowBranchFeed(ctx, ctx.Repo.Repository, "rss")
347-
}
348-
349343
// CreateBranch creates new branch in repository
350344
func CreateBranch(ctx *context.Context) {
351345
form := web.GetForm(ctx).(*forms.NewBranchForm)

routers/web/web.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -1454,8 +1454,8 @@ func RegisterRoutes(m *web.Route) {
14541454
m.Get("/cherry-pick/{sha:([a-f0-9]{7,40})$}", repo.SetEditorconfigIfExists, repo.CherryPick)
14551455
}, repo.MustBeNotEmpty, context.RepoRef(), reqRepoCodeReader)
14561456

1457-
m.Get("/rss/branch/*", context.RepoRefByType(context.RepoRefBranch), feed.RenderBranchFeed)
1458-
m.Get("/atom/branch/*", context.RepoRefByType(context.RepoRefBranch), feed.RenderBranchFeed)
1457+
m.Get("/rss/branch/*", context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed)
1458+
m.Get("/atom/branch/*", context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed)
14591459

14601460
m.Group("/src", func() {
14611461
m.Get("/branch/*", context.RepoRefByType(context.RepoRefBranch), repo.Home)

templates/repo/branch_dropdown.tmpl

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
'branches': {{.root.Branches}},
4343
'tags': {{.root.Tags}},
4444
'defaultBranch': {{$defaultBranch}},
45+
'enableFeed': {{.root.EnableFeed}},
46+
'rssURLPrefix': '{{$.root.RepoLink}}/rss/branch/',
4547
'branchURLPrefix': '{{if .branchURLPrefix}}{{.branchURLPrefix}}{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/branch/{{end}}',
4648
'branchURLSuffix': '{{if .branchURLSuffix}}{{.branchURLSuffix}}{{else}}{{if $.root.TreePath}}/{{PathEscapeSegments $.root.TreePath}}{{end}}{{end}}',
4749
'tagURLPrefix': '{{if .tagURLPrefix}}{{.tagURLPrefix}}{{else if .release}}{{$.root.RepoLink}}/compare/{{else}}{{$.root.RepoLink}}/{{if $.root.PageIsCommits}}commits{{else}}src{{end}}/tag/{{end}}',

templates/repo/home.tmpl

+3-2
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@
6464
{{$l := Eval $n "-" 1}}
6565
<!-- If home page, show new pr. If not, show breadcrumb -->
6666
{{if and (eq $n 0) .CanCompareOrPull .IsViewBranch (not .Repository.IsArchived)}}
67-
<a href="{{CompareLink .BaseRepo .Repository .BranchName}}">
68-
<button id="new-pull-request" class="ui compact basic button" data-tooltip-content="{{if .PullRequestCtx.Allowed}}{{.locale.Tr "repo.pulls.compare_changes"}}{{else}}{{.locale.Tr "action.compare_branch"}}{{end}}"><span class="text">{{svg "octicon-git-pull-request"}}</span></button>
67+
<a id="new-pull-request" role="button" class="ui compact basic button" href="{{CompareLink .BaseRepo .Repository .BranchName}}"
68+
data-tooltip-content="{{if .PullRequestCtx.Allowed}}{{.locale.Tr "repo.pulls.compare_changes"}}{{else}}{{.locale.Tr "action.compare_branch"}}{{end}}">
69+
{{svg "octicon-git-pull-request"}}
6970
</a>
7071
{{end}}
7172
{{if eq $n 0}}

templates/repo/view_file.tmpl

+1-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,7 @@
4343
<a download href="{{$.RawFileLink}}"><span class="btn-octicon" data-tooltip-content="{{.locale.Tr "repo.download_file"}}">{{svg "octicon-download"}}</span></a>
4444
<a id="copy-content" class="btn-octicon {{if not .CanCopyContent}} disabled{{end}}"{{if or .IsImageFile (and .HasSourceRenderedToggle (not .IsDisplayingSource))}} data-link="{{$.RawFileLink}}"{{end}} data-tooltip-content="{{if .CanCopyContent}}{{.locale.Tr "copy_content"}}{{else}}{{.locale.Tr "copy_type_unsupported"}}{{end}}">{{svg "octicon-copy" 14}}</a>
4545
{{if .EnableFeed}}
46-
<a class="btn-octicon" href="{{$.FeedURL}}/rss/{{$.BranchNameSubURL}}{{range $i, $v := .TreeNames}}/{{$v}}{{end}}">
47-
{{svg "octicon-rss" 14}}
48-
</a>
46+
<a class="btn-octicon" href="{{$.FeedURL}}/rss/{{$.BranchNameSubURL}}/{{PathEscapeSegments .TreePath}}">{{svg "octicon-rss" 14}}</a>
4947
{{end}}
5048
{{if .Repository.CanEnableEditor}}
5149
{{if .CanEditFile}}

tests/integration/pull_create_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func testPullCreate(t *testing.T, session *TestSession, user, repo, branch, titl
2222

2323
// Click the PR button to create a pull
2424
htmlDoc := NewHTMLParser(t, resp.Body)
25-
link, exists := htmlDoc.doc.Find("#new-pull-request").Parent().Attr("href")
25+
link, exists := htmlDoc.doc.Find("#new-pull-request").Attr("href")
2626
assert.True(t, exists, "The template has changed")
2727
if branch != "master" {
2828
link = strings.Replace(link, ":master", ":"+branch, 1)

web_src/js/components/RepoBranchTagSelector.vue

+10-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<div class="scrolling menu" ref="scrollContainer">
4040
<div v-for="(item, index) in filteredItems" :key="item.name" class="item" :class="{selected: item.selected, active: active === index}" @click="selectItem(item)" :ref="'listItem' + index">
4141
{{ item.name }}
42-
<a v-if="mode === 'branches'" role="button" class="ui compact muted right" :href="(branchURLPrefix + item.url).replace('src', 'rss')">
42+
<a v-if="enableFeed && mode === 'branches'" role="button" class="ui compact muted right" :href="rssURLPrefix + item.url" target="_blank" @click.stop>
4343
<svg-icon name="octicon-rss" :size="14"/>
4444
</a>
4545
</div>
@@ -294,3 +294,12 @@ export function initRepoBranchTagSelector(selector) {
294294
295295
export default sfc; // activate IDE's Vue plugin
296296
</script>
297+
298+
<style scoped>
299+
.menu .item a {
300+
display: none; /* only show RSS icon on hover */
301+
}
302+
.menu .item:hover a {
303+
display: inline-block;
304+
}
305+
</style>

0 commit comments

Comments
 (0)