// ĠCopyright Ġ 2 0 0 0 - 2 0 2 0 ĠJetBrains Ġs . r . o . ĠUse Ġof Ġthis Ġsource Ġcode Ġis Ġgoverned Ġby Ġthe ĠApache Ġ 2 . 0 Ġlicense Ġthat Ġcan Ġbe Ġfound Ġin Ġthe ĠLICENSE Ġfile . Ċ package Ġorg . jetbrains . plugins . github . pull request . data Ċ Ċ import Ġcom . intellij . openapi . Disposable Ċ import Ġcom . intellij . openapi . components . Service Ċ import Ġcom . intellij . openapi . components . service Ċ import Ġcom . intellij . openapi . file Editor . File Editor Manager Ċ import Ġcom . intellij . openapi . progress . Progress Indicator Ċ import Ġcom . intellij . openapi . progress . Progress Manager Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġcom . intellij . openapi . util . Dis poser Ċ import Ġcom . intellij . ui . Collection ListModel Ċ import Ġgit 4 idea . commands . Git Ċ import Ġorg . jetbrains . annotations . Called In A wt Ċ import Ġorg . jetbrains . annotations . Called In Background Ċ import Ġorg . jetbrains . plugins . github . api . GH G QL Requests Ċ import Ġorg . jetbrains . plugins . github . api . GH Repository Coordinates Ċ import Ġorg . jetbrains . plugins . github . api . Github ApiRequest Executor Ċ import Ġorg . jetbrains . plugins . github . api . data . GH Repository Owner Name Ċ import Ġorg . jetbrains . plugins . github . api . data . GH User Ċ import Ġorg . jetbrains . plugins . github . api . data . pull request . G HP ull Request Ċ import Ġorg . jetbrains . plugins . github . api . data . pull request . G HP ull Request Short Ċ import Ġorg . jetbrains . plugins . github . api . util . Simple GH G QL Pages Loader Ċ import Ġorg . jetbrains . plugins . github . authentication . accounts . Github Account Ċ import Ġorg . jetbrains . plugins . github . authentication . accounts . Github Account Information Provider Ċ import Ġorg . jetbrains . plugins . github . i 1 8 n . Github Bundle Ċ import Ġorg . jetbrains . plugins . github . pull request . GH PR Virtual File Ċ import Ġorg . jetbrains . plugins . github . pull request . data . service .* Ċ import Ġorg . jetbrains . plugins . github . pull request . search . Github PullRequest Search Query Holder Impl Ċ import Ġorg . jetbrains . plugins . github . pull request . ui . timeline . GH PR Timeline Mer ging Model Ċ import Ġorg . jetbrains . plugins . github . util .* Ċ import Ġjava . io . IOException Ċ import Ġjava . util . concurrent . Comp letableFuture Ċ Ċ @ Service Ċ internal Ġclass ĠGH PR DataContext Repository ( private Ġval Ġproject : ĠProject ) Ġ{ ĊĊĠ Ġprivate Ġval Ġrepositories Ġ= Ġmutable Map Of < Git Remote Url Coordinates , ĠLazy C ancellable Background Process Value < GH PR DataContext >>() ĊĊĠ Ġ@ Called In A wt ĊĠ Ġfun Ġacquire Context ( git Remote Coordinates : ĠGit Remote Url Coordinates , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaccount : ĠGithub Account , Ġrequest Executor : ĠGithub ApiRequest Executor ): ĠCompletableFuture < GH PR DataContext > Ġ{ ĊĊĠĠĠ Ġreturn Ġrepositories . get Or Put ( git Remote Coordinates ) Ġ{ ĊĠĠĠĠĠ Ġval Ġcontext Disposable Ġ= ĠDis poser . new Disposable () ĊĠĠĠĠĠ ĠLazy C ancellable Background Process Value . create Ġ{ Ġindicator Ġ-> ĊĠĠĠĠĠĠĠ ĠProgress Manager . getInstance (). submit I OT ask ( indicator ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġload Context ( indicator , Ġaccount , Ġrequest Executor , Ġgit Remote Coordinates ) ĊĠĠĠĠĠĠĠ Ġ}. success On Ed t Ġ{ Ġctx Ġ-> ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ( Dis poser . is Disposed ( context Disposable )) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDis poser . dispose ( ctx ) ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDis poser . register ( context Disposable , Ġctx ) ĊĠĠĠĠĠĠĠĠĠĠĠ ĠDis poser . register ( ctx , ĠDis posable Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġeditor Manager Ġ= ĠFile Editor Manager . getInstance ( project ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġeditor Manager . open Files . filter Ġ{ Ġit Ġis ĠGH PR Virtual File Ġ&& Ġit . data Context Ġ=== Ġctx Ġ}. forEach ( editor Manager :: close File ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġctx ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ}. also Ġ{ ĊĠĠĠĠĠĠĠ Ġit . add Drop EventListener Ġ{ ĊĠĠĠĠĠĠĠĠĠ ĠDis poser . dispose ( context Disposable ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ}. value ĊĠ Ġ} ĊĊĠ Ġ@ Called In A wt ĊĠ Ġfun Ġclear Context ( git Remote Coordinates : ĠGit Remote Url Coordinates ) Ġ{ ĊĠĠĠ Ġrepositories . remove ( git Remote Coordinates )?. drop () ĊĠ Ġ} ĊĊĠ Ġ@ Called In Background ĊĠ Ġ@ Throws ( IOException :: class ) ĊĠ Ġprivate Ġfun Ġload Context ( indicator : ĠProgress Indicator , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaccount : ĠGithub Account , Ġrequest Executor : ĠGithub ApiRequest Executor , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġgit Remote Coordinates : ĠGit Remote Url Coordinates ): ĠGH PR DataContext Ġ{ ĊĠĠĠ Ġval Ġfull Path Ġ= ĠGithub Url Util . getUser And Repository From Remote Url ( git Remote Coordinates . url ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ?: Ġthrow ĠIllegalArgumentException ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ" Invalid ĠGitHub ĠRepository ĠURL Ġ- Ġ${ git Remote Coordinates . url } Ġis Ġnot Ġa ĠGitHub Ġrepository ") ĊĊĠĠĠ Ġindicator . text Ġ= ĠGithub Bundle . message (" pull . request . loading . account . info ") ĊĠĠĠ Ġval Ġaccount Details Ġ= ĠGithub Account Information Provider . getInstance (). get Information ( request Executor , Ġindicator , Ġaccount ) ĊĠĠĠ Ġindicator . check Canceled () ĊĊĠĠĠ Ġindicator . text Ġ= ĠGithub Bundle . message (" pull . request . loading . repo . info ") ĊĠĠĠ Ġval Ġrepo With Permissions Ġ= ĊĠĠĠĠĠ Ġrequest Executor . execute ( indicator , ĠG HG QL Requests . Repo . find Permission ( GH Repository Coordinates ( account . server , Ġfull Path ))) ĊĠĠĠĠĠ Ġ?: Ġthrow ĠIllegalArgumentException (" Repository Ġ$ fullPath Ġdoes Ġnot Ġexist Ġat Ġ${ account . server } Ġor Ġyou Ġdon 't Ġhave Ġaccess .") ĊĊĠĠĠ Ġval ĠcurrentUser Ġ= ĠGH User ( account Details . nodeId , Ġaccount Details . login , Ġaccount Details . html Url , Ġaccount Details . avatar Url !! , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaccount Details . name ) ĊĊĠĠĠ Ġindicator . text Ġ= ĠGithub Bundle . message (" pull . request . loading . user . teams . info ") ĊĠĠĠ Ġval Ġrepo Owner Ġ= Ġrepo With Permissions . owner ĊĠĠĠ Ġval ĠcurrentUser Teams Ġ= Ġif Ġ( repo Owner Ġis ĠGH Repository Owner Name . Organization ) ĊĠĠĠĠĠ ĠSimple GH G QL Pages Loader ( request Executor , Ġ{ ĊĠĠĠĠĠĠĠ ĠG HG QL Requests . Organization . Team . findBy User Log ins ( account . server , Ġrepo Owner . login , ĠlistOf ( currentUser . login ), Ġit ) ĊĠĠĠĠĠ Ġ}). load All ( indicator ) ĊĠĠĠ Ġelse Ġempty List () ĊĠĠĠ Ġindicator . check Canceled () ĊĊĠĠĠ Ġval Ġrepository Coordinates Ġ= ĠGH Repository Coordinates ( account . server , Ġrepo With Permissions . path ) ĊĊĠĠĠ Ġval Ġsecurity Service Ġ= ĠGH PR Security ServiceImpl ( Github Shared Project Settings . getInstance ( project ), ĠcurrentUser , ĠcurrentUser Teams , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġrepo With Permissions ) ĊĠĠĠ Ġval Ġdetails Service Ġ= ĠGH PR Details ServiceImpl ( Progress Manager . getInstance (), Ġrequest Executor , Ġrepository Coordinates ) ĊĠĠĠ Ġval Ġstate Service Ġ= ĠGH PR State ServiceImpl ( Progress Manager . getInstance (), Ġsecurity Service , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġrequest Executor , Ġaccount . server , Ġrepo With Permissions . path ) ĊĠĠĠ Ġval Ġcomment Service Ġ= ĠGH PR Comment ServiceImpl ( Progress Manager . getInstance (), Ġrequest Executor , Ġrepository Coordinates ) ĊĠĠĠ Ġval Ġchanges Service Ġ= ĠGH PR Changes ServiceImpl ( Progress Manager . getInstance (), ĠGit . getInstance (), Ġproject , Ġrequest Executor , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġgit Remote Coordinates , Ġrepository Coordinates ) ĊĠĠĠ Ġval Ġreview Service Ġ= ĠGH PR Review ServiceImpl ( Progress Manager . getInstance (), Ġsecurity Service , Ġrequest Executor , Ġrepository Coordinates ) ĊĊĠĠĠ Ġval Ġlist Model Ġ= ĠCollection ListModel < G HP ull Request Short >() ĊĠĠĠ Ġval Ġsearch Holder Ġ= ĠGithub PullRequest Search Query Holder Impl () ĊĠĠĠ Ġval Ġlist Loader Ġ= ĠGH PR List Loader Impl ( Progress Manager . getInstance (), Ġrequest Executor , Ġaccount . server , Ġrepo With Permissions . path , Ġlist Model , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġsearch Holder ) ĊĊĠĠĠ Ġval Ġdata Loader Ġ= ĠGH PR DataLoader Impl ( details Service , Ġstate Service , Ġreview Service , Ġcomment Service , Ġchanges Service ) Ġ{ Ġid Ġ-> ĊĠĠĠĠĠ Ġval Ġtimeline Model Ġ= ĠGH PR Timeline Mer ging Model () ĊĠĠĠĠĠ ĠGH PR Timeline Loader ( Progress Manager . getInstance (), Ġrequest Executor , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġaccount . server , Ġrepo With Permissions . path , Ġid . number , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġtimeline Model ) ĊĠĠĠ Ġ}. also Ġ{ ĊĠĠĠĠĠ Ġit . add Details Loaded Listener Ġ{ Ġdetails : ĠG HP ull Request Ġ-> ĊĠĠĠĠĠĠĠ Ġlist Loader . update Data ( details ) ĊĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġval Ġrepo DataService Ġ= ĠGH PR Repository Data ServiceImpl ( Progress Manager . getInstance (), Ġrequest Executor , Ġaccount . server , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġrepo With Permissions . path , Ġrepo Owner ) ĊĊĠĠĠ Ġindicator . check Canceled () ĊĠĠĠ Ġreturn ĠGH PR DataContext ( git Remote Coordinates , Ġrepository Coordinates , Ġaccount , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġrequest Executor , Ġlist Model , Ġsearch Holder , Ġlist Loader , Ġdata Loader , Ġsecurity Service , Ġrepo DataService ) ĊĠ Ġ} ĊĊĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠ Ġfun ĠgetInstance ( project : ĠProject ) Ġ= Ġproject . service < GH PR DataContext Repository >() ĊĠ Ġ} Ċ }