Skip to content

Commit 88c7bd9

Browse files
committed
improve
1 parent 56d4893 commit 88c7bd9

File tree

9 files changed

+15
-24
lines changed

9 files changed

+15
-24
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
@@ -1450,8 +1450,8 @@ func RegisterRoutes(m *web.Route) {
14501450
m.Get("/cherry-pick/{sha:([a-f0-9]{7,40})$}", repo.SetEditorconfigIfExists, repo.CherryPick)
14511451
}, repo.MustBeNotEmpty, context.RepoRef(), reqRepoCodeReader)
14521452

1453-
m.Get("/rss/branch/*", context.RepoRefByType(context.RepoRefBranch), feed.RenderBranchFeed)
1454-
m.Get("/atom/branch/*", context.RepoRefByType(context.RepoRefBranch), feed.RenderBranchFeed)
1453+
m.Get("/rss/branch/*", context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed)
1454+
m.Get("/atom/branch/*", context.RepoRefByType(context.RepoRefBranch), feedEnabled, feed.RenderBranchFeed)
14551455

14561456
m.Group("/src", func() {
14571457
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}}

web_src/js/components/RepoBranchTagSelector.vue

+1-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>

0 commit comments

Comments
 (0)