@@ -25,6 +25,7 @@ import (
25
25
user_model "code.gitea.io/gitea/models/user"
26
26
"code.gitea.io/gitea/models/webhook"
27
27
"code.gitea.io/gitea/modules/git"
28
+ "code.gitea.io/gitea/modules/queue"
28
29
api "code.gitea.io/gitea/modules/structs"
29
30
"code.gitea.io/gitea/modules/test"
30
31
"code.gitea.io/gitea/modules/translation"
@@ -435,3 +436,63 @@ func TestConflictChecking(t *testing.T) {
435
436
assert .False (t , conflictingPR .Mergeable (db .DefaultContext ))
436
437
})
437
438
}
439
+
440
+ func TestPullMergeIndexerNotifier (t * testing.T ) {
441
+ onGiteaRun (t , func (t * testing.T , giteaURL * url.URL ) {
442
+ // create a pull request
443
+ session := loginUser (t , "user1" )
444
+ testRepoFork (t , session , "user2" , "repo1" , "user1" , "repo1" )
445
+ testEditFile (t , session , "user1" , "repo1" , "master" , "README.md" , "Hello, World (Edited)\n " )
446
+ createPullResp := testPullCreate (t , session , "user1" , "repo1" , "master" , "Indexer notifier test pull" )
447
+
448
+ assert .NoError (t , queue .GetManager ().FlushAll (context .Background (), 0 ))
449
+ time .Sleep (time .Second )
450
+
451
+ repo1 := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {
452
+ OwnerName : "user2" ,
453
+ Name : "repo1" ,
454
+ })
455
+ issue := unittest .AssertExistsAndLoadBean (t , & issues_model.Issue {
456
+ RepoID : repo1 .ID ,
457
+ Title : "Indexer notifier test pull" ,
458
+ IsPull : true ,
459
+ IsClosed : false ,
460
+ })
461
+
462
+ // build the request for searching issues
463
+ link , _ := url .Parse ("/api/v1/repos/issues/search" )
464
+ query := url.Values {}
465
+ query .Add ("state" , "closed" )
466
+ query .Add ("type" , "pulls" )
467
+ query .Add ("q" , "notifier" )
468
+ link .RawQuery = query .Encode ()
469
+
470
+ // search issues
471
+ searchIssuesResp := session .MakeRequest (t , NewRequest (t , "GET" , link .String ()), http .StatusOK )
472
+ var apiIssuesBefore []* api.Issue
473
+ DecodeJSON (t , searchIssuesResp , & apiIssuesBefore )
474
+ assert .Len (t , apiIssuesBefore , 0 )
475
+
476
+ // merge the pull request
477
+ elem := strings .Split (test .RedirectURL (createPullResp ), "/" )
478
+ assert .EqualValues (t , "pulls" , elem [3 ])
479
+ testPullMerge (t , session , elem [1 ], elem [2 ], elem [4 ], repo_model .MergeStyleMerge )
480
+
481
+ // check if the issue is closed
482
+ issue = unittest .AssertExistsAndLoadBean (t , & issues_model.Issue {
483
+ ID : issue .ID ,
484
+ })
485
+ assert .True (t , issue .IsClosed )
486
+
487
+ assert .NoError (t , queue .GetManager ().FlushAll (context .Background (), 0 ))
488
+ time .Sleep (time .Second )
489
+
490
+ // search issues again
491
+ searchIssuesResp = session .MakeRequest (t , NewRequest (t , "GET" , link .String ()), http .StatusOK )
492
+ var apiIssuesAfter []* api.Issue
493
+ DecodeJSON (t , searchIssuesResp , & apiIssuesAfter )
494
+ if assert .Len (t , apiIssuesAfter , 1 ) {
495
+ assert .Equal (t , issue .ID , apiIssuesAfter [0 ].ID )
496
+ }
497
+ })
498
+ }
0 commit comments