@@ -17,6 +17,7 @@ import (
1717 "code.gitea.io/gitea/models/db"
1818 issues_model "code.gitea.io/gitea/models/issues"
1919 repo_model "code.gitea.io/gitea/models/repo"
20+ "code.gitea.io/gitea/models/unit"
2021 "code.gitea.io/gitea/models/unittest"
2122 user_model "code.gitea.io/gitea/models/user"
2223 "code.gitea.io/gitea/modules/indexer/issues"
@@ -471,19 +472,38 @@ func TestIssueRedirect(t *testing.T) {
471472 session := loginUser (t , "user2" )
472473
473474 // Test external tracker where style not set (shall default numeric)
474- req := NewRequest (t , "GET" , path . Join ( " org26" , " repo_external_tracker" , " issues" , "1" ) )
475+ req := NewRequest (t , "GET" , "/ org26/ repo_external_tracker/ issues/1" )
475476 resp := session .MakeRequest (t , req , http .StatusSeeOther )
476477 assert .Equal (t , "https://tracker.com/org26/repo_external_tracker/issues/1" , test .RedirectURL (resp ))
477478
478479 // Test external tracker with numeric style
479- req = NewRequest (t , "GET" , path . Join ( " org26" , " repo_external_tracker_numeric" , " issues" , "1" ) )
480+ req = NewRequest (t , "GET" , "/ org26/ repo_external_tracker_numeric/ issues/1" )
480481 resp = session .MakeRequest (t , req , http .StatusSeeOther )
481482 assert .Equal (t , "https://tracker.com/org26/repo_external_tracker_numeric/issues/1" , test .RedirectURL (resp ))
482483
483484 // Test external tracker with alphanumeric style (for a pull request)
484- req = NewRequest (t , "GET" , path . Join ( " org26" , " repo_external_tracker_alpha" , " issues" , "1" ) )
485+ req = NewRequest (t , "GET" , "/ org26/ repo_external_tracker_alpha/ issues/1" )
485486 resp = session .MakeRequest (t , req , http .StatusSeeOther )
486- assert .Equal (t , "/" + path .Join ("org26" , "repo_external_tracker_alpha" , "pulls" , "1" ), test .RedirectURL (resp ))
487+ assert .Equal (t , "/org26/repo_external_tracker_alpha/pulls/1" , test .RedirectURL (resp ))
488+
489+ // test to check that the PR redirection works if the issue unit is disabled
490+ // repo1 is a normal repository with issue unit enabled, visit issue 2(which is a pull request)
491+ // will redirect to pulls
492+ req = NewRequest (t , "GET" , "/user2/repo1/issues/2" )
493+ resp = session .MakeRequest (t , req , http .StatusSeeOther )
494+ assert .Equal (t , "/user2/repo1/pulls/2" , test .RedirectURL (resp ))
495+
496+ repoUnit := unittest .AssertExistsAndLoadBean (t , & repo_model.RepoUnit {RepoID : 1 , Type : unit .TypeIssues })
497+
498+ // disable issue unit, it will be reset
499+ _ , err := db .DeleteByID [repo_model.RepoUnit ](t .Context (), repoUnit .ID )
500+ assert .NoError (t , err )
501+
502+ // even if the issue unit is disabled, visiting an issue which is a pull request
503+ // will still redirect to pull request
504+ req = NewRequest (t , "GET" , "/user2/repo1/issues/2" )
505+ resp = session .MakeRequest (t , req , http .StatusSeeOther )
506+ assert .Equal (t , "/user2/repo1/pulls/2" , test .RedirectURL (resp ))
487507}
488508
489509func TestSearchIssues (t * testing.T ) {
0 commit comments