@@ -17,6 +17,7 @@ import (
17
17
"code.gitea.io/gitea/models/db"
18
18
issues_model "code.gitea.io/gitea/models/issues"
19
19
repo_model "code.gitea.io/gitea/models/repo"
20
+ "code.gitea.io/gitea/models/unit"
20
21
"code.gitea.io/gitea/models/unittest"
21
22
user_model "code.gitea.io/gitea/models/user"
22
23
"code.gitea.io/gitea/modules/indexer/issues"
@@ -471,19 +472,38 @@ func TestIssueRedirect(t *testing.T) {
471
472
session := loginUser (t , "user2" )
472
473
473
474
// 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" )
475
476
resp := session .MakeRequest (t , req , http .StatusSeeOther )
476
477
assert .Equal (t , "https://tracker.com/org26/repo_external_tracker/issues/1" , test .RedirectURL (resp ))
477
478
478
479
// 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" )
480
481
resp = session .MakeRequest (t , req , http .StatusSeeOther )
481
482
assert .Equal (t , "https://tracker.com/org26/repo_external_tracker_numeric/issues/1" , test .RedirectURL (resp ))
482
483
483
484
// 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" )
485
486
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 ))
487
507
}
488
508
489
509
func TestSearchIssues (t * testing.T ) {
0 commit comments