feat(ui): Display to maintainers in PR when it is editable

This commit is contained in:
Beowulf 2025-02-09 00:35:14 +01:00
parent 93f84db542
commit c6ab10c1ba
No known key found for this signature in database
GPG key ID: 44225F5F2792841D
3 changed files with 62 additions and 0 deletions

View file

@ -1996,6 +1996,9 @@ pulls.reopen_failed.base_branch = The pull request cannot be reopened, because t
pulls.made_using_agit = AGit pulls.made_using_agit = AGit
pulls.agit_explanation = Created using the AGit workflow. AGit lets contributors propose changes using "git push" without creating a fork or a new branch. pulls.agit_explanation = Created using the AGit workflow. AGit lets contributors propose changes using "git push" without creating a fork or a new branch.
pulls.editable = Editable
pulls.editable_explanation = This pull request allows edits from maintainers. You can contribute directly to it.
pulls.auto_merge_button_when_succeed = (When checks succeed) pulls.auto_merge_button_when_succeed = (When checks succeed)
pulls.auto_merge_when_succeed = Auto merge when all checks succeed pulls.auto_merge_when_succeed = Auto merge when all checks succeed
pulls.auto_merge_newly_scheduled = The pull request was scheduled to merge when all checks succeed. pulls.auto_merge_newly_scheduled = The pull request was scheduled to merge when all checks succeed.

View file

@ -95,6 +95,11 @@
</span> </span>
</a> </a>
{{end}} {{end}}
{{if and .Issue.PullRequest.AllowMaintainerEdit .CanWriteCode}}
<span id="editable-label" data-tooltip-content="{{ctx.Locale.Tr "repo.pulls.editable_explanation"}}" class="ui small label">
{{ctx.Locale.Tr "repo.pulls.editable"}}
</span>
{{end}}
<span id="pull-desc-editor" class="tw-hidden flex-text-block" data-target-update-url="{{$.RepoLink}}/pull/{{.Issue.Index}}/target_branch"> <span id="pull-desc-editor" class="tw-hidden flex-text-block" data-target-update-url="{{$.RepoLink}}/pull/{{.Issue.Index}}/target_branch">
<div class="ui floating filter dropdown"> <div class="ui floating filter dropdown">
<div class="ui basic small button tw-mr-0"> <div class="ui basic small button tw-mr-0">

View file

@ -0,0 +1,54 @@
// Copyright 2025 The Forgejo Authors. All rights reserved.
// SPDX-License-Identifier: GPL-3.0-or-later
package integration
import (
"net/http"
"net/url"
"testing"
auth_model "code.gitea.io/gitea/models/auth"
api "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/tests"
)
func TestPullEditable_ShowEditableLabel(t *testing.T) {
onGiteaRun(t, func(t *testing.T, forgejoURL *url.URL) {
t.Run("Show editable label if PR is editable", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
editable := true
setPREditable(t, editable)
testEditableLabelShown(t, editable)
})
t.Run("Don't show editable label if PR is not editable", func(t *testing.T) {
defer tests.PrintCurrentTest(t)()
editable := false
setPREditable(t, editable)
testEditableLabelShown(t, editable)
})
})
}
func setPREditable(t *testing.T, editable bool) {
t.Helper()
session := loginUser(t, "user1")
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteRepository)
req := NewRequestWithJSON(t, "PATCH", "/api/v1/repos/user2/repo1/pulls/3", &api.EditPullRequestOption{
AllowMaintainerEdit: &editable,
}).AddTokenAuth(token)
session.MakeRequest(t, req, http.StatusCreated)
}
func testEditableLabelShown(t *testing.T, expectLabel bool) {
t.Helper()
session := loginUser(t, "user2")
req := NewRequest(t, "GET", "/user2/repo1/pulls/3")
resp := session.MakeRequest(t, req, http.StatusOK)
htmlDoc := NewHTMLParser(t, resp.Body)
htmlDoc.AssertElement(t, "#editable-label", expectLabel)
}