@@ -14,8 +14,10 @@ import (
14
14
"testing"
15
15
"time"
16
16
17
+ "code.gitea.io/gitea/models/db"
17
18
issues_model "code.gitea.io/gitea/models/issues"
18
19
repo_model "code.gitea.io/gitea/models/repo"
20
+ "code.gitea.io/gitea/models/unit"
19
21
"code.gitea.io/gitea/models/unittest"
20
22
user_model "code.gitea.io/gitea/models/user"
21
23
"code.gitea.io/gitea/modules/indexer/issues"
@@ -474,19 +476,38 @@ func TestIssueRedirect(t *testing.T) {
474
476
session := loginUser (t , "user2" )
475
477
476
478
// Test external tracker where style not set (shall default numeric)
477
- req := NewRequest (t , "GET" , path . Join ( " org26" , " repo_external_tracker" , " issues" , "1" ) )
479
+ req := NewRequest (t , "GET" , "/ org26/ repo_external_tracker/ issues/1" )
478
480
resp := session .MakeRequest (t , req , http .StatusSeeOther )
479
481
assert .Equal (t , "https://tracker.com/org26/repo_external_tracker/issues/1" , test .RedirectURL (resp ))
480
482
481
483
// Test external tracker with numeric style
482
- req = NewRequest (t , "GET" , path . Join ( " org26" , " repo_external_tracker_numeric" , " issues" , "1" ) )
484
+ req = NewRequest (t , "GET" , "/ org26/ repo_external_tracker_numeric/ issues/1" )
483
485
resp = session .MakeRequest (t , req , http .StatusSeeOther )
484
486
assert .Equal (t , "https://tracker.com/org26/repo_external_tracker_numeric/issues/1" , test .RedirectURL (resp ))
485
487
486
488
// Test external tracker with alphanumeric style (for a pull request)
487
- req = NewRequest (t , "GET" , path . Join ( " org26" , " repo_external_tracker_alpha" , " issues" , "1" ) )
489
+ req = NewRequest (t , "GET" , "/ org26/ repo_external_tracker_alpha/ issues/1" )
488
490
resp = session .MakeRequest (t , req , http .StatusSeeOther )
489
- assert .Equal (t , "/" + path .Join ("org26" , "repo_external_tracker_alpha" , "pulls" , "1" ), test .RedirectURL (resp ))
491
+ assert .Equal (t , "/org26/repo_external_tracker_alpha/pulls/1" , test .RedirectURL (resp ))
492
+
493
+ // test to check that the PR redirection works if the issue unit is disabled
494
+ // repo1 is a normal repository with issue unit enabled, visit issue 2(which is a pull request)
495
+ // will redirect to pulls
496
+ req = NewRequest (t , "GET" , "/user2/repo1/issues/2" )
497
+ resp = session .MakeRequest (t , req , http .StatusSeeOther )
498
+ assert .Equal (t , "/user2/repo1/pulls/2" , test .RedirectURL (resp ))
499
+
500
+ repoUnit := unittest .AssertExistsAndLoadBean (t , & repo_model.RepoUnit {RepoID : 1 , Type : unit .TypeIssues })
501
+
502
+ // disable issue unit, it will be reset
503
+ _ , err := db .DeleteByID [repo_model.RepoUnit ](t .Context (), repoUnit .ID )
504
+ assert .NoError (t , err )
505
+
506
+ // even if the issue unit is disabled, visiting an issue which is a pull request
507
+ // will still redirect to pull request
508
+ req = NewRequest (t , "GET" , "/user2/repo1/issues/2" )
509
+ resp = session .MakeRequest (t , req , http .StatusSeeOther )
510
+ assert .Equal (t , "/user2/repo1/pulls/2" , test .RedirectURL (resp ))
490
511
}
491
512
492
513
func TestSearchIssues (t * testing.T ) {
0 commit comments