loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

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 <gusted@noreply.codeberg.org>
Co-authored-by: 0ko <0ko@noreply.codeberg.org>
Co-committed-by: 0ko <0ko@noreply.codeberg.org>

authored by

0ko
0ko
and committed by
Gusted
b1590068 4ef00fe6

+59 -5
+1
options/locale/locale_en-US.ini
··· 1193 1193 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. 1194 1194 archive.issue.nocomment = This repository is archived. You cannot comment on issues. 1195 1195 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. 1196 1197 1197 1198 form.reach_limit_of_creation_1 = The owner has already reached the limit of %d repository. 1198 1199 form.reach_limit_of_creation_n = The owner has already reached the limit of %d repositories.
+12 -5
templates/repo/diff/new_review.tmpl
··· 1 1 <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> 7 14 {{if $.IsShowingAllCommits}} 8 15 <div class="review-box-panel tippy-target"> 9 16 <div class="ui segment">
+46
tests/integration/pull_review_test.go
··· 1 1 // Copyright 2019 The Gitea Authors. All rights reserved. 2 + // Copyright 2024 The Forgejo Authors. All rights reserved. 2 3 // SPDX-License-Identifier: MIT 3 4 4 5 package integration ··· 362 363 defer f() 363 364 364 365 t.Run("First Pull Request", func(t *testing.T) { 366 + defer tests.PrintCurrentTest(t)() 367 + 365 368 // create a new branch to prepare for pull request 366 369 _, err := files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{ 367 370 NewBranch: "codeowner-basebranch", ··· 409 412 require.NoError(t, err) 410 413 411 414 t.Run("Second Pull Request", func(t *testing.T) { 415 + defer tests.PrintCurrentTest(t)() 416 + 412 417 // create a new branch to prepare for pull request 413 418 _, err = files_service.ChangeRepoFiles(db.DefaultContext, repo, user2, &files_service.ChangeRepoFilesOptions{ 414 419 NewBranch: "codeowner-basebranch2", ··· 431 436 }) 432 437 433 438 t.Run("Forked Repo Pull Request", func(t *testing.T) { 439 + defer tests.PrintCurrentTest(t)() 440 + 434 441 user5 := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 5}) 435 442 forkedRepo, err := repo_service.ForkRepositoryAndUpdates(db.DefaultContext, user2, user5, repo_service.ForkRepoOptions{ 436 443 BaseRepo: repo, ··· 483 490 defer baseGitRepo.Close() 484 491 485 492 t.Run("Submit approve/reject review on merged PR", func(t *testing.T) { 493 + defer tests.PrintCurrentTest(t)() 494 + 486 495 // Create a merged PR (made by user1) in the upstream repo1. 487 496 testEditFile(t, user1Session, "user1", "repo1", "master", "README.md", "Hello, World (Edited)\n") 488 497 resp := testPullCreate(t, user1Session, "user1", "repo1", false, "master", "master", "This is a pull title") ··· 513 522 }) 514 523 515 524 t.Run("Submit approve/reject review on closed PR", func(t *testing.T) { 525 + defer tests.PrintCurrentTest(t)() 526 + 516 527 // Created a closed PR (made by user1) in the upstream repo1. 517 528 testEditFileToNewBranch(t, user1Session, "user1", "repo1", "master", "a-test-branch", "README.md", "Hello, World (Edited...again)\n") 518 529 resp := testPullCreate(t, user1Session, "user1", "repo1", false, "master", "a-test-branch", "This is a pull title") ··· 540 551 541 552 // Submit a reject review on the PR. 542 553 testSubmitReview(t, user2Session, htmlDoc.GetCSRF(), "user2", "repo1", elem[4], sha, "reject", http.StatusOK) 554 + }) 555 + }) 556 + } 557 + 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")) 543 589 }) 544 590 }) 545 591 }