mirror of
1
Fork 0

Merge pull request 'Offer to remove WIP: prefix in sidebar' (#2660) from 0ko/forgejo:convert-to-normal into forgejo

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2660
Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org>
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
This commit is contained in:
Earl Warren 2024-03-25 10:30:11 +00:00
commit 9397bfd276
3 changed files with 66 additions and 2 deletions

View File

@ -1818,6 +1818,7 @@ pulls.title_wip_desc = `<a href="#">Start the title with <strong>%s</strong></a>
pulls.cannot_merge_work_in_progress = This pull request is marked as a work in progress.
pulls.still_in_progress = Still in progress?
pulls.add_prefix = Add <strong>%s</strong> prefix
pulls.ready_for_review = Ready for review?
pulls.remove_prefix = Remove <strong>%s</strong> prefix
pulls.data_broken = This pull request is broken due to missing fork information.
pulls.files_conflicted = This pull request has changes conflicting with the target branch.

View File

@ -113,10 +113,14 @@
{{end}}
</div>
</div>
{{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .HasMerged) (not .Issue.IsClosed) (not .IsPullWorkInProgress)}}
{{if and (or .HasIssuesOrPullsWritePermission .IsIssuePoster) (not .HasMerged) (not .Issue.IsClosed)}}
<div class="toggle-wip" data-title="{{.Issue.Title}}" data-wip-prefix="{{index .PullRequestWorkInProgressPrefixes 0}}" data-update-url="{{.Issue.Link}}/title">
<a class="muted">
{{if .IsPullWorkInProgress}}
{{ctx.Locale.Tr "repo.pulls.ready_for_review"}} {{ctx.Locale.Tr "repo.pulls.remove_prefix" (index .PullRequestWorkInProgressPrefixes 0)}}
{{else}}
{{ctx.Locale.Tr "repo.pulls.still_in_progress"}} {{ctx.Locale.Tr "repo.pulls.add_prefix" (index .PullRequestWorkInProgressPrefixes 0)}}
{{end}}
</a>
</div>
{{end}}

View File

@ -0,0 +1,59 @@
// Copyright 2024 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: MIT
package integration
import (
"net/http"
"net/url"
"path"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func TestPullWIPConvertSidebar(t *testing.T) {
onGiteaRun(t, func(t *testing.T, u *url.URL) {
testRepo := "repo1"
branchOld := "master"
branchNew := "wip"
userOwner := "user2"
userUnrelated := "user4"
sessionOwner := loginUser(t, userOwner) // Owner of the repo. Expected to see the offers.
sessionUnrelated := loginUser(t, userUnrelated) // Unrelated user. Not expected to see the offers.
// Create a branch with commit, open a PR and check who is seeing the Add WIP offering
testEditFileToNewBranch(t, sessionOwner, userOwner, testRepo, branchOld, branchNew, "README.md", "test of wip offering")
url := path.Join(userOwner, testRepo, "compare", branchOld+"..."+branchNew)
req := NewRequestWithValues(t, "POST", url,
map[string]string{
"_csrf": GetCSRF(t, sessionOwner, url),
"title": "pull used for testing wip offering",
},
)
sessionOwner.MakeRequest(t, req, http.StatusOK)
testPullWIPConvertSidebar(t, sessionOwner, userOwner, testRepo, "6", "Still in progress? Add WIP: prefix")
testPullWIPConvertSidebar(t, sessionUnrelated, userOwner, testRepo, "6", "")
// Add WIP: prefix and check who is seeing the Remove WIP offering
req = NewRequestWithValues(t, "POST", path.Join(userOwner, testRepo, "pulls/6/title"),
map[string]string{
"_csrf": GetCSRF(t, sessionOwner, path.Join(userOwner, testRepo, "pulls/6")),
"title": "WIP: pull used for testing wip offering",
},
)
sessionOwner.MakeRequest(t, req, http.StatusOK)
testPullWIPConvertSidebar(t, sessionOwner, userOwner, testRepo, "6", "Ready for review? Remove WIP: prefix")
testPullWIPConvertSidebar(t, sessionUnrelated, userOwner, testRepo, "6", "")
})
}
func testPullWIPConvertSidebar(t *testing.T, session *TestSession, user, repo, pullNum, expected string) {
t.Helper()
req := NewRequest(t, "GET", path.Join(user, repo, "pulls", pullNum))
resp := session.MakeRequest(t, req, http.StatusOK)
doc := NewHTMLParser(t, resp.Body)
text := strings.TrimSpace(doc.doc.Find(".toggle-wip a").Text())
assert.Equal(t, expected, text)
}