mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-01-01 20:44:32 +01:00
Merge pull request '[v10.0/forgejo] feat: When comparing in repos, mention that pull request creation requires sign-in' (#6398) from bp-v10.0/forgejo-dd4a110 into v10.0/forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6398 Reviewed-by: 0ko <0ko@noreply.codeberg.org>
This commit is contained in:
commit
0eab84d02e
4 changed files with 46 additions and 0 deletions
|
@ -1845,6 +1845,7 @@ pulls.new = New pull request
|
|||
pulls.view = View pull request
|
||||
pulls.edit.already_changed = Unable to save changes to the pull request. It appears the content has already been changed by another user. Please refresh the page and try editing again to avoid overwriting their changes
|
||||
pulls.compare_changes = New pull request
|
||||
pulls.sign_in_require = <a href="%s">Sign in</a> to create a new pull request.
|
||||
pulls.allow_edits_from_maintainers = Allow edits from maintainers
|
||||
pulls.allow_edits_from_maintainers_desc = Users with write access to the base branch can also push to this branch
|
||||
pulls.allow_edits_from_maintainers_err = Updating failed
|
||||
|
|
|
@ -51,6 +51,7 @@ const (
|
|||
func setCompareContext(ctx *context.Context, before, head *git.Commit, headOwner, headName string) {
|
||||
ctx.Data["BeforeCommit"] = before
|
||||
ctx.Data["HeadCommit"] = head
|
||||
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/login?redirect_to=" + url.QueryEscape(ctx.Data["Link"].(string))
|
||||
|
||||
ctx.Data["GetBlobByPathForCommit"] = func(commit *git.Commit, path string) *git.Blob {
|
||||
if commit == nil {
|
||||
|
|
|
@ -215,6 +215,10 @@
|
|||
{{ctx.Locale.Tr "repo.archive.title_date" (DateUtils.AbsoluteLong .Repository.ArchivedUnix)}}
|
||||
{{end}}
|
||||
</div>
|
||||
{{else}}
|
||||
<div class="ui warning message tw-mb-4">
|
||||
{{ctx.Locale.Tr "repo.pulls.sign_in_require" .SignInLink}}
|
||||
</div>
|
||||
{{end}}
|
||||
{{if $.IsSigned}}
|
||||
<div class="pullrequest-form {{if not .Flash}}tw-hidden{{end}}">
|
||||
|
|
|
@ -291,3 +291,43 @@ func TestCompareCodeExpand(t *testing.T) {
|
|||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestCompareSignedIn(t *testing.T) {
|
||||
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
|
||||
// Setup the test with a connected user
|
||||
session := loginUser(t, "user1")
|
||||
testRepoFork(t, session, "user2", "repo1", "user1", "repo1")
|
||||
testCreateBranch(t, session, "user1", "repo1", "branch/master", "recent-push", http.StatusSeeOther)
|
||||
testEditFile(t, session, "user1", "repo1", "recent-push", "README.md", "Hello recently!\n")
|
||||
|
||||
newPrSelector := "button.ui.button.primary.show-form"
|
||||
|
||||
t.Run("PR creation button displayed if logged in", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", "/user1/repo1/compare/master...recent-push")
|
||||
resp := session.MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
// Check that the "Sign in" button doesn't show up
|
||||
htmlDoc.AssertElement(t, "a[href='/user/login?redirect_to=%2Fuser1%2Frepo1%2Fcompare%2Fmaster...recent-push']", false)
|
||||
|
||||
// Check that the "New pull request" button shows up
|
||||
htmlDoc.AssertElement(t, newPrSelector, true)
|
||||
})
|
||||
|
||||
t.Run("no PR creation button but display warning", func(t *testing.T) {
|
||||
defer tests.PrintCurrentTest(t)()
|
||||
|
||||
req := NewRequest(t, "GET", "/user1/repo1/compare/master...recent-push")
|
||||
resp := MakeRequest(t, req, http.StatusOK)
|
||||
htmlDoc := NewHTMLParser(t, resp.Body)
|
||||
|
||||
// Check that the "Sign in" button shows up
|
||||
htmlDoc.AssertElement(t, "a[href='/user/login?redirect_to=%2Fuser1%2Frepo1%2Fcompare%2Fmaster...recent-push']", true)
|
||||
|
||||
// Check that the "New pull request" button doesn't show up
|
||||
htmlDoc.AssertElement(t, newPrSelector, false)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue