mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-08-28 05:03:51 +00:00
fix(ui): compare branches even with pull requests disabled (#8496)
Resolves #8428 Its currently showing the diff of two branches, even if the PR-unit is disabled. But the POST to create the PR is still returning an error when the unit is disabled, so its only a change for UI. Preview: https://codeberg.org/attachments/610d6b81-a50f-4c43-91c2-db4c38e7b701 Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8496 Reviewed-by: 0ko <0ko@noreply.codeberg.org> Co-authored-by: zokki <zokki.softwareschmiede@gmail.com> Co-committed-by: zokki <zokki.softwareschmiede@gmail.com>
This commit is contained in:
parent
4392dee96d
commit
64193310ee
5 changed files with 21 additions and 19 deletions
|
@ -111,5 +111,6 @@
|
||||||
"settings.visibility.description": "Profile visibility affects others' ability to access your non-private repositories. <a href=\"%s\" target=\"_blank\">Learn more</a>.",
|
"settings.visibility.description": "Profile visibility affects others' ability to access your non-private repositories. <a href=\"%s\" target=\"_blank\">Learn more</a>.",
|
||||||
"avatar.constraints_hint": "Custom avatar may not exceed %[1]s in size or be larger than %[2]dx%[3]d pixels",
|
"avatar.constraints_hint": "Custom avatar may not exceed %[1]s in size or be larger than %[2]dx%[3]d pixels",
|
||||||
"og.repo.summary_card.alt_description": "Summary card of repository %[1]s, described as: %[2]s",
|
"og.repo.summary_card.alt_description": "Summary card of repository %[1]s, described as: %[2]s",
|
||||||
|
"compare.branches.title": "Compare branches",
|
||||||
"meta.last_line": "Thank you for translating Forgejo! This line isn't seen by the users but it serves other purposes in the translation management. You can place a fun fact in the translation instead of translating it."
|
"meta.last_line": "Thank you for translating Forgejo! This line isn't seen by the users but it serves other purposes in the translation management. You can place a fun fact in the translation instead of translating it."
|
||||||
}
|
}
|
||||||
|
|
|
@ -520,17 +520,6 @@ func ParseCompareInfo(ctx *context.Context) *common.CompareInfo {
|
||||||
ctx.Data["PageIsComparePull"] = headIsBranch && baseIsBranch
|
ctx.Data["PageIsComparePull"] = headIsBranch && baseIsBranch
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx.Data["PageIsComparePull"] == true && !permBase.CanReadIssuesOrPulls(true) {
|
|
||||||
if log.IsTrace() {
|
|
||||||
log.Trace("Permission Denied: User: %-v cannot create/read pull requests in Repo: %-v\nUser in baseRepo has Permissions: %-+v",
|
|
||||||
ctx.Doer,
|
|
||||||
baseRepo,
|
|
||||||
permBase)
|
|
||||||
}
|
|
||||||
ctx.NotFound("ParseCompareInfo", nil)
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
baseBranchRef := ci.BaseBranch
|
baseBranchRef := ci.BaseBranch
|
||||||
if baseIsBranch {
|
if baseIsBranch {
|
||||||
baseBranchRef = git.BranchPrefix + ci.BaseBranch
|
baseBranchRef = git.BranchPrefix + ci.BaseBranch
|
||||||
|
|
|
@ -121,7 +121,11 @@
|
||||||
{{end}}
|
{{end}}
|
||||||
</td>
|
</td>
|
||||||
<td class="two wide right aligned">
|
<td class="two wide right aligned">
|
||||||
{{if not .LatestPullRequest}}
|
{{if not ($.Permission.CanRead $.UnitTypePullRequests)}}
|
||||||
|
<a href="{{$.RepoLink}}/compare/{{PathEscapeSegments $.DefaultBranchBranch.DBBranch.Name}}...{{if ne $.Repository.Owner.Name $.Owner.Name}}{{PathEscape $.Owner.Name}}:{{end}}{{PathEscapeSegments .DBBranch.Name}}">
|
||||||
|
<button class="ui compact basic button tw-mr-0">{{ctx.Locale.Tr "compare.branches.title"}}</button>
|
||||||
|
</a>
|
||||||
|
{{else if not .LatestPullRequest}}
|
||||||
{{if .IsIncluded}}
|
{{if .IsIncluded}}
|
||||||
<span class="ui orange large label" data-tooltip-content="{{ctx.Locale.Tr "repo.branch.included_desc"}}">
|
<span class="ui orange large label" data-tooltip-content="{{ctx.Locale.Tr "repo.branch.included_desc"}}">
|
||||||
{{svg "octicon-git-pull-request"}} {{ctx.Locale.Tr "repo.branch.included"}}
|
{{svg "octicon-git-pull-request"}} {{ctx.Locale.Tr "repo.branch.included"}}
|
||||||
|
|
|
@ -2,11 +2,16 @@
|
||||||
<div role="main" aria-label="{{.Title}}" class="page-content repository diff {{if .PageIsComparePull}}compare pull{{end}}">
|
<div role="main" aria-label="{{.Title}}" class="page-content repository diff {{if .PageIsComparePull}}compare pull{{end}}">
|
||||||
{{template "repo/header" .}}
|
{{template "repo/header" .}}
|
||||||
{{$showDiffBox := false}}
|
{{$showDiffBox := false}}
|
||||||
|
{{$canReadPullRequests := .Permission.CanRead $.UnitTypePullRequests}}
|
||||||
<div class="ui container fluid padded">
|
<div class="ui container fluid padded">
|
||||||
<h2 class="ui header">
|
<h2 class="ui header">
|
||||||
{{if and $.PageIsComparePull $.IsSigned (not .Repository.IsArchived)}}
|
{{if and $.PageIsComparePull $.IsSigned (not .Repository.IsArchived)}}
|
||||||
{{ctx.Locale.Tr "repo.pulls.compare_changes"}}
|
{{if $canReadPullRequests}}
|
||||||
<div class="sub header">{{ctx.Locale.Tr "repo.pulls.compare_changes_desc"}}</div>
|
{{ctx.Locale.Tr "repo.pulls.compare_changes"}}
|
||||||
|
<div class="sub header">{{ctx.Locale.Tr "repo.pulls.compare_changes_desc"}}</div>
|
||||||
|
{{else}}
|
||||||
|
{{ctx.Locale.Tr "compare.branches.title"}}
|
||||||
|
{{end}}
|
||||||
{{else}}
|
{{else}}
|
||||||
{{ctx.Locale.Tr "action.compare_commits_general"}}
|
{{ctx.Locale.Tr "action.compare_commits_general"}}
|
||||||
{{end}}
|
{{end}}
|
||||||
|
@ -166,7 +171,7 @@
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class="ui segment">{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_have_tag"}}</div>
|
<div class="ui segment">{{ctx.Locale.Tr "repo.pulls.nothing_to_compare_have_tag"}}</div>
|
||||||
{{end}}
|
{{end}}
|
||||||
{{else if and .PageIsComparePull (gt .CommitCount 0)}}
|
{{else if and .PageIsComparePull (gt .CommitCount 0) $canReadPullRequests}}
|
||||||
{{if .HasPullRequest}}
|
{{if .HasPullRequest}}
|
||||||
<div class="ui segment grid title">
|
<div class="ui segment grid title">
|
||||||
<div class="twelve wide column issue-title">
|
<div class="twelve wide column issue-title">
|
||||||
|
|
|
@ -267,13 +267,14 @@ func TestCompareWithPRsDisabled(t *testing.T) {
|
||||||
[]unit_model.Type{unit_model.TypePullRequests})
|
[]unit_model.Type{unit_model.TypePullRequests})
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
t.Run("branch view doesn't offer creating PRs", func(t *testing.T) {
|
t.Run("branch view offer comparing branches", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/user1/repo1/branches")
|
req := NewRequest(t, "GET", "/user1/repo1/branches")
|
||||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
htmlDoc.AssertElement(t, "a[href='/user1/repo1/compare/master...recent-push']", false)
|
compareLink := htmlDoc.Find("a[href='/user1/repo1/compare/master...recent-push']")
|
||||||
|
assert.Equal(t, "Compare branches", strings.TrimSpace(compareLink.Text()))
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("compare doesn't offer local branches", func(t *testing.T) {
|
t.Run("compare doesn't offer local branches", func(t *testing.T) {
|
||||||
|
@ -290,11 +291,13 @@ func TestCompareWithPRsDisabled(t *testing.T) {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
t.Run("comparing against a disabled-PR repo is 404", func(t *testing.T) {
|
t.Run("comparing against a disabled-PR repo", func(t *testing.T) {
|
||||||
defer tests.PrintCurrentTest(t)()
|
defer tests.PrintCurrentTest(t)()
|
||||||
|
|
||||||
req := NewRequest(t, "GET", "/user1/repo1/compare/master...recent-push")
|
req := NewRequest(t, "GET", "/user1/repo1/compare/master...recent-push")
|
||||||
session.MakeRequest(t, req, http.StatusNotFound)
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||||
|
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||||
|
assert.Equal(t, "Compare branches", strings.TrimSpace(htmlDoc.Find("h2.header").Text()))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue