Skip to content

Commit b159006

Browse files
0koGusted
authored andcommitted
fix(ui): disable PR review button in archived repos (go-gitea#6729)
* disable the "Finish review" button on PR/files page for archived repos - trying to review PRs in such repos results in JS error * wrap the button in a div and move tooltips here to make them actually display on a disabled button - currently they do not * added simple testing Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6729 Reviewed-by: Gusted <[email protected]> Co-authored-by: 0ko <[email protected]> Co-committed-by: 0ko <[email protected]>
1 parent 4ef00fe commit b159006

File tree

3 files changed

+59
-5
lines changed

3 files changed

+59
-5
lines changed

options/locale/locale_en-US.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,7 @@ archive.title = This repository is archived. You can view files and clone it, bu
11931193
archive.title_date = This repository has been archived on %s. You can view files and clone it, but cannot push or open issues or pull requests.
11941194
archive.issue.nocomment = This repository is archived. You cannot comment on issues.
11951195
archive.pull.nocomment = This repository is archived. You cannot comment on pull requests.
1196+
archive.pull.noreview = This repository is archived. You cannot review pull requests.
11961197

11971198
form.reach_limit_of_creation_1 = The owner has already reached the limit of %d repository.
11981199
form.reach_limit_of_creation_n = The owner has already reached the limit of %d repositories.

templates/repo/diff/new_review.tmpl

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
<div id="review-box">
2-
<button class="ui tiny primary button tw-pr-1 tw-flex js-btn-review {{if not $.IsShowingAllCommits}}disabled{{end}}" {{if not $.IsShowingAllCommits}}data-tooltip-content="{{ctx.Locale.Tr "repo.pulls.review_only_possible_for_full_diff"}}"{{end}}>
3-
{{ctx.Locale.Tr "repo.diff.review"}}
4-
<span class="ui small label review-comments-counter" data-pending-comment-number="{{.PendingCodeCommentNumber}}">{{.PendingCodeCommentNumber}}</span>
5-
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
6-
</button>
2+
<div
3+
{{if not $.IsShowingAllCommits}}
4+
data-tooltip-content="{{ctx.Locale.Tr "repo.pulls.review_only_possible_for_full_diff"}}"
5+
{{else if .Repository.IsArchived}}
6+
data-tooltip-content="{{ctx.Locale.Tr "repo.archive.pull.noreview"}}"
7+
{{end}}>
8+
<button class="ui tiny primary button tw-pr-1 tw-flex js-btn-review {{if or (not $.IsShowingAllCommits) .Repository.IsArchived}}disabled{{end}}">
9+
{{ctx.Locale.Tr "repo.diff.review"}}
10+
<span class="ui small label review-comments-counter" data-pending-comment-number="{{.PendingCodeCommentNumber}}">{{.PendingCodeCommentNumber}}</span>
11+
{{svg "octicon-triangle-down" 14 "dropdown icon"}}
12+
</button>
13+
</div>
714
{{if $.IsShowingAllCommits}}
815
<div class="review-box-panel tippy-target">
916
<div class="ui segment">

tests/integration/pull_review_test.go

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
// Copyright 2019 The Gitea Authors. All rights reserved.
2+
// Copyright 2024 The Forgejo Authors. All rights reserved.
23
// SPDX-License-Identifier: MIT
34

45
package integration
@@ -362,6 +363,8 @@ func TestPullView_CodeOwner(t *testing.T) {
362363
defer f()
363364

364365
t.Run("First Pull Request", func(t *testing.T) {
366+
defer tests.PrintCurrentTest(t)()
367+
365368
// create a new branch to prepare for pull request
366369
_, err := files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
367370
NewBranch: "codeowner-basebranch",
@@ -409,6 +412,8 @@ func TestPullView_CodeOwner(t *testing.T) {
409412
require.NoError(t, err)
410413

411414
t.Run("Second Pull Request", func(t *testing.T) {
415+
defer tests.PrintCurrentTest(t)()
416+
412417
// create a new branch to prepare for pull request
413418
_, err = files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{
414419
NewBranch: "codeowner-basebranch2",
@@ -431,6 +436,8 @@ func TestPullView_CodeOwner(t *testing.T) {
431436
})
432437

433438
t.Run("Forked Repo Pull Request", func(t *testing.T) {
439+
defer tests.PrintCurrentTest(t)()
440+
434441
user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5})
435442
forkedRepo, err := repo_service.ForkRepositoryAndUpdates(db.DefaultContext, user2, user5, repo_service.ForkRepoOptions{
436443
BaseRepo: repo,
@@ -483,6 +490,8 @@ func TestPullView_GivenApproveOrRejectReviewOnClosedPR(t *testing.T) {
483490
defer baseGitRepo.Close()
484491

485492
t.Run("Submit approve/reject review on merged PR", func(t *testing.T) {
493+
defer tests.PrintCurrentTest(t)()
494+
486495
// Create a merged PR (made by user1) in the upstream repo1.
487496
testEditFile(t, user1Session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n")
488497
resp := testPullCreate(t, user1Session, "user1", "repo1", false, "master", "master", "This is a pull title")
@@ -513,6 +522,8 @@ func TestPullView_GivenApproveOrRejectReviewOnClosedPR(t *testing.T) {
513522
})
514523

515524
t.Run("Submit approve/reject review on closed PR", func(t *testing.T) {
525+
defer tests.PrintCurrentTest(t)()
526+
516527
// Created a closed PR (made by user1) in the upstream repo1.
517528
testEditFileToNewBranch(t, user1Session, "user1", "repo1", "master", "a-test-branch", "README.md", "Hello, World (Edited...again)\n")
518529
resp := testPullCreate(t, user1Session, "user1", "repo1", false, "master", "a-test-branch", "This is a pull title")
@@ -544,6 +555,41 @@ func TestPullView_GivenApproveOrRejectReviewOnClosedPR(t *testing.T) {
544555
})
545556
}
546557

558+
func TestPullReviewInArchivedRepo(t *testing.T) {
559+
onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) {
560+
session := loginUser(t, "user2")
561+
562+
// Open a PR
563+
testEditFileToNewBranch(t, session, "user2", "repo1", "master", "for-pr", "README.md", "Hi!\n")
564+
resp := testPullCreate(t, session, "user2", "repo1", true, "master", "for-pr", "PR title")
565+
elem := strings.Split(test.RedirectURL(resp), "/")
566+
567+
t.Run("Review box normally", func(t *testing.T) {
568+
defer tests.PrintCurrentTest(t)()
569+
570+
// The "Finish review button" must be available
571+
resp = session.MakeRequest(t, NewRequest(t, "GET", path.Join(elem[1], elem[2], "pulls", elem[4], "files")), http.StatusOK)
572+
button := NewHTMLParser(t, resp.Body).Find("#review-box button")
573+
assert.False(t, button.HasClass("disabled"))
574+
})
575+
576+
t.Run("Review box in archived repo", func(t *testing.T) {
577+
defer tests.PrintCurrentTest(t)()
578+
579+
// Archive the repo
580+
resp = session.MakeRequest(t, NewRequestWithValues(t, "POST", path.Join(elem[1], elem[2], "settings"), map[string]string{
581+
"_csrf": GetCSRF(t, session, path.Join(elem[1], elem[2], "settings")),
582+
"action": "archive",
583+
}), http.StatusSeeOther)
584+
585+
// The "Finish review button" must be disabled
586+
resp = session.MakeRequest(t, NewRequest(t, "GET", path.Join(elem[1], elem[2], "pulls", elem[4], "files")), http.StatusOK)
587+
button := NewHTMLParser(t, resp.Body).Find("#review-box button")
588+
assert.True(t, button.HasClass("disabled"))
589+
})
590+
})
591+
}
592+
547593
func testNofiticationCount(t *testing.T, session *TestSession, csrf string, expectedSubmitStatus int) *httptest.ResponseRecorder {
548594
options := map[string]string{
549595
"_csrf": csrf,

0 commit comments

Comments
 (0)