@@ -26,6 +26,7 @@ import (
26
26
"code.gitea.io/gitea/models/webhook"
27
27
"code.gitea.io/gitea/modules/git"
28
28
"code.gitea.io/gitea/modules/gitrepo"
29
+ "code.gitea.io/gitea/modules/queue"
29
30
api "code.gitea.io/gitea/modules/structs"
30
31
"code.gitea.io/gitea/modules/test"
31
32
"code.gitea.io/gitea/modules/translation"
@@ -587,3 +588,63 @@ func TestPullDontRetargetChildOnWrongRepo(t *testing.T) {
587
588
assert .EqualValues (t , "Closed" , prStatus )
588
589
})
589
590
}
591
+
592
+ func TestPullMergeIndexerNotifier (t * testing.T ) {
593
+ onGiteaRun (t , func (t * testing.T , giteaURL * url.URL ) {
594
+ // create a pull request
595
+ session := loginUser (t , "user1" )
596
+ testRepoFork (t , session , "user2" , "repo1" , "user1" , "repo1" )
597
+ testEditFile (t , session , "user1" , "repo1" , "master" , "README.md" , "Hello, World (Edited)\n " )
598
+ createPullResp := testPullCreate (t , session , "user1" , "repo1" , false , "master" , "master" , "Indexer notifier test pull" )
599
+
600
+ assert .NoError (t , queue .GetManager ().FlushAll (context .Background (), 0 ))
601
+ time .Sleep (time .Second )
602
+
603
+ repo1 := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {
604
+ OwnerName : "user2" ,
605
+ Name : "repo1" ,
606
+ })
607
+ issue := unittest .AssertExistsAndLoadBean (t , & issues_model.Issue {
608
+ RepoID : repo1 .ID ,
609
+ Title : "Indexer notifier test pull" ,
610
+ IsPull : true ,
611
+ IsClosed : false ,
612
+ })
613
+
614
+ // build the request for searching issues
615
+ link , _ := url .Parse ("/api/v1/repos/issues/search" )
616
+ query := url.Values {}
617
+ query .Add ("state" , "closed" )
618
+ query .Add ("type" , "pulls" )
619
+ query .Add ("q" , "notifier" )
620
+ link .RawQuery = query .Encode ()
621
+
622
+ // search issues
623
+ searchIssuesResp := session .MakeRequest (t , NewRequest (t , "GET" , link .String ()), http .StatusOK )
624
+ var apiIssuesBefore []* api.Issue
625
+ DecodeJSON (t , searchIssuesResp , & apiIssuesBefore )
626
+ assert .Len (t , apiIssuesBefore , 0 )
627
+
628
+ // merge the pull request
629
+ elem := strings .Split (test .RedirectURL (createPullResp ), "/" )
630
+ assert .EqualValues (t , "pulls" , elem [3 ])
631
+ testPullMerge (t , session , elem [1 ], elem [2 ], elem [4 ], repo_model .MergeStyleMerge , false )
632
+
633
+ // check if the issue is closed
634
+ issue = unittest .AssertExistsAndLoadBean (t , & issues_model.Issue {
635
+ ID : issue .ID ,
636
+ })
637
+ assert .True (t , issue .IsClosed )
638
+
639
+ assert .NoError (t , queue .GetManager ().FlushAll (context .Background (), 0 ))
640
+ time .Sleep (time .Second )
641
+
642
+ // search issues again
643
+ searchIssuesResp = session .MakeRequest (t , NewRequest (t , "GET" , link .String ()), http .StatusOK )
644
+ var apiIssuesAfter []* api.Issue
645
+ DecodeJSON (t , searchIssuesResp , & apiIssuesAfter )
646
+ if assert .Len (t , apiIssuesAfter , 1 ) {
647
+ assert .Equal (t , issue .ID , apiIssuesAfter [0 ].ID )
648
+ }
649
+ })
650
+ }
0 commit comments