From b1590068a7e85e4a5af8d09dbbca5e8db3d7ca58 Mon Sep 17 00:00:00 2001 From: 0ko <0ko@noreply.codeberg.org> Date: Fri, 31 Jan 2025 10:39:30 +0000 Subject: [PATCH] fix(ui): disable PR review button in archived repos (#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 Co-authored-by: 0ko <0ko@noreply.codeberg.org> Co-committed-by: 0ko <0ko@noreply.codeberg.org> --- options/locale/locale_en-US.ini | 1 + templates/repo/diff/new_review.tmpl | 17 +++++++--- tests/integration/pull_review_test.go | 46 +++++++++++++++++++++++++++ 3 files changed, 59 insertions(+), 5 deletions(-) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index c23397904a..166616ba91 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -1193,6 +1193,7 @@ archive.title = This repository is archived. You can view files and clone it, bu 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. archive.issue.nocomment = This repository is archived. You cannot comment on issues. archive.pull.nocomment = This repository is archived. You cannot comment on pull requests. +archive.pull.noreview = This repository is archived. You cannot review pull requests. form.reach_limit_of_creation_1 = The owner has already reached the limit of %d repository. form.reach_limit_of_creation_n = The owner has already reached the limit of %d repositories. diff --git a/templates/repo/diff/new_review.tmpl b/templates/repo/diff/new_review.tmpl index a2eae007a5..13d09babe1 100644 --- a/templates/repo/diff/new_review.tmpl +++ b/templates/repo/diff/new_review.tmpl @@ -1,9 +1,16 @@
- +
+ +
{{if $.IsShowingAllCommits}}
diff --git a/tests/integration/pull_review_test.go b/tests/integration/pull_review_test.go index e1db171f16..6dd58102eb 100644 --- a/tests/integration/pull_review_test.go +++ b/tests/integration/pull_review_test.go @@ -1,4 +1,5 @@ // Copyright 2019 The Gitea Authors. All rights reserved. +// Copyright 2024 The Forgejo Authors. All rights reserved. // SPDX-License-Identifier: MIT package integration @@ -362,6 +363,8 @@ func TestPullView_CodeOwner(t *testing.T) { defer f() t.Run("First Pull Request", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + // create a new branch to prepare for pull request _, err := files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{ NewBranch: "codeowner-basebranch", @@ -409,6 +412,8 @@ func TestPullView_CodeOwner(t *testing.T) { require.NoError(t, err) t.Run("Second Pull Request", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + // create a new branch to prepare for pull request _, err = files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{ NewBranch: "codeowner-basebranch2", @@ -431,6 +436,8 @@ func TestPullView_CodeOwner(t *testing.T) { }) t.Run("Forked Repo Pull Request", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) forkedRepo, err := repo_service.ForkRepositoryAndUpdates(db.DefaultContext, user2, user5, repo_service.ForkRepoOptions{ BaseRepo: repo, @@ -483,6 +490,8 @@ func TestPullView_GivenApproveOrRejectReviewOnClosedPR(t *testing.T) { defer baseGitRepo.Close() t.Run("Submit approve/reject review on merged PR", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + // Create a merged PR (made by user1) in the upstream repo1. testEditFile(t, user1Session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") resp := testPullCreate(t, user1Session, "user1", "repo1", false, "master", "master", "This is a pull title") @@ -513,6 +522,8 @@ func TestPullView_GivenApproveOrRejectReviewOnClosedPR(t *testing.T) { }) t.Run("Submit approve/reject review on closed PR", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + // Created a closed PR (made by user1) in the upstream repo1. testEditFileToNewBranch(t, user1Session, "user1", "repo1", "master", "a-test-branch", "README.md", "Hello, World (Edited...again)\n") 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) { }) } +func TestPullReviewInArchivedRepo(t *testing.T) { + onGiteaRun(t, func(t *testing.T, giteaURL *url.URL) { + session := loginUser(t, "user2") + + // Open a PR + testEditFileToNewBranch(t, session, "user2", "repo1", "master", "for-pr", "README.md", "Hi!\n") + resp := testPullCreate(t, session, "user2", "repo1", true, "master", "for-pr", "PR title") + elem := strings.Split(test.RedirectURL(resp), "/") + + t.Run("Review box normally", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + // The "Finish review button" must be available + resp = session.MakeRequest(t, NewRequest(t, "GET", path.Join(elem[1], elem[2], "pulls", elem[4], "files")), http.StatusOK) + button := NewHTMLParser(t, resp.Body).Find("#review-box button") + assert.False(t, button.HasClass("disabled")) + }) + + t.Run("Review box in archived repo", func(t *testing.T) { + defer tests.PrintCurrentTest(t)() + + // Archive the repo + resp = session.MakeRequest(t, NewRequestWithValues(t, "POST", path.Join(elem[1], elem[2], "settings"), map[string]string{ + "_csrf": GetCSRF(t, session, path.Join(elem[1], elem[2], "settings")), + "action": "archive", + }), http.StatusSeeOther) + + // The "Finish review button" must be disabled + resp = session.MakeRequest(t, NewRequest(t, "GET", path.Join(elem[1], elem[2], "pulls", elem[4], "files")), http.StatusOK) + button := NewHTMLParser(t, resp.Body).Find("#review-box button") + assert.True(t, button.HasClass("disabled")) + }) + }) +} + func testNofiticationCount(t *testing.T, session *TestSession, csrf string, expectedSubmitStatus int) *httptest.ResponseRecorder { options := map[string]string{ "_csrf": csrf,