// ĠCopyright Ġ 2 0 0 0 - 2 0 2 1 Ġ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 . extensions Ċ Ċ import Ġcom . intellij . concurrency . Sensitive Progress Wrapper Ċ import Ġcom . intellij . openapi . application . run In Ed t Ċ import Ġcom . intellij . openapi . components . service Ċ import Ġcom . intellij . openapi . diagnostic . logger Ċ import Ġcom . intellij . openapi . progress . Process Canceled Exception Ċ import Ġcom . intellij . openapi . progress . Progress Indicator Ċ import Ġcom . intellij . openapi . project . Project Ċ import Ġcom . intellij . util . Pattern Util Ċ import Ġgit 4 idea . config . Git Shared Settings Ċ import Ġgit 4 idea . fetch . Git Fetch Handler Ċ import Ġgit 4 idea . repo . Git Remote Ċ import Ġgit 4 idea . repo . Git Repository Ċ import Ġorg . jetbrains . plugins . github . api . GH G QL Requests Ċ import Ġorg . jetbrains . plugins . github . api . Github ApiRequest Executor Manager Ċ import Ġorg . jetbrains . plugins . github . api . util . Simple GH G QL Pages Loader Ċ import Ġorg . jetbrains . plugins . github . authentication . Github Authentication Manager Ċ import Ġorg . jetbrains . plugins . github . i 1 8 n . Github Bundle Ċ import Ġorg . jetbrains . plugins . github . util . GH Project Repositories Manager Ċ import Ġorg . jetbrains . plugins . github . util . Github Project Settings Ċ Ċ private Ġval ĠLOG Ġ= Ġlogger < GH Protected Branch Rules Loader >() Ċ Ċ internal Ġclass ĠGH Protected Branch Rules Loader Ġ: ĠGit Fetch Handler Ġ{ ĊĊĠ Ġoverride Ġfun Ġdo After Successful Fetch ( project : ĠProject , Ġf etches : ĠMap < Git Repository , ĠList < Git Remote >>, Ġindicator : ĠProgress Indicator ) Ġ{ ĊĠĠĠ Ġtry Ġ{ ĊĠĠĠĠĠ Ġload Protection Rules ( indicator , Ġf etches , Ġproject ) ĊĠĠĠ Ġ} ĊĠĠĠ Ġcatch Ġ( e : ĠException ) Ġ{ ĊĠĠĠĠĠ Ġif Ġ( e Ġis ĠProcess Canceled Exception ) Ġ{ ĊĠĠĠĠĠĠĠ Ġthrow Ġe ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ ĠLOG . info (" Error Ġoccurred Ġwhile Ġtrying Ġto Ġload Ġbranch Ġprotection Ġrules ", Ġe ) ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġprivate Ġfun Ġload Protection Rules ( indicator : ĠProgress Indicator , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġf etches : ĠMap < Git Repository , ĠList < Git Remote >>, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġproject : ĠProject ) Ġ{ ĊĠĠĠ Ġval Ġgithub Authentication Manager Ġ= ĠGithub Authentication Manager . getInstance () ĊĠĠĠ Ġif Ġ(! Git Shared Settings . getInstance ( project ). is Synchronize Branch Protection Rules Ġ|| Ġ! github Authentication Manager . has Accounts ()) Ġ{ ĊĠĠĠĠĠ Ġrun In Ed t Ġ{ ĊĠĠĠĠĠĠĠ Ġproject . service < Github Project Settings >(). branch Protection Patterns Ġ= Ġarray ListOf () ĊĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġreturn ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġindicator . text Ġ= ĠGithub Bundle . message (" progress . text . loading . protected . branches ") ĊĊĠĠĠ Ġval Ġbranch Protection Patterns Ġ= Ġmutable Set Of < String >() ĊĠĠĠ Ġfor Ġ(( repository , Ġrem otes ) Ġin Ġf etches ) Ġ{ ĊĠĠĠĠĠ Ġindicator . check Canceled () ĊĊĠĠĠĠĠ Ġfor Ġ( remote Ġin Ġrem otes ) Ġ{ ĊĠĠĠĠĠĠĠ Ġindicator . check Canceled () ĊĊĠĠĠĠĠĠĠ Ġval Ġaccount Ġ= ĊĠĠĠĠĠĠĠĠĠ Ġgithub Authentication Manager . get Accounts (). find Ġ{ Ġit . server . matches ( remote . first Url . or Empty ()) Ġ} Ġ?: Ġcontinue ĊĊĠĠĠĠĠĠĠ Ġval Ġrequest Executor Ġ= ĠGithub ApiRequest Executor Manager . getInstance (). get Executor ( account ) ĊĊĠĠĠĠĠĠĠ Ġval Ġgithub Repository Mapping Ġ= ĊĠĠĠĠĠĠĠĠĠ Ġproject . service < GH Project Repositories Manager >(). find Known Repositories ( repository ). find Ġ{ Ġit . git Remote Url Coordinates . remote Ġ== Ġremote Ġ} ĊĠĠĠĠĠĠĠĠĠ Ġ?: Ġcontinue ĊĊĠĠĠĠĠĠĠ Ġval Ġrepository Coordinates Ġ= Ġgithub Repository Mapping . gh Repository Coordinates ĊĊĠĠĠĠĠĠĠ ĠSimple GH G QL Pages Loader ( request Executor , Ġ{ ĠG HG QL Requests . Repo . get Protection Rules ( repository Coordinates ) Ġ}) ĊĠĠĠĠĠĠĠĠĠ Ġ. load All ( Sensitive Progress Wrapper (( indicator ))) ĊĠĠĠĠĠĠĠĠĠ Ġ. forEach Ġ{ Ġrule Ġ-> Ġbranch Protection Patterns . add ( Pattern Util . convertTo Regex ( rule . pattern )) Ġ} ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠ Ġ} ĊĊĠĠĠ Ġrun In Ed t Ġ{ ĊĠĠĠĠĠ Ġproject . service < Github Project Settings >(). branch Protection Patterns Ġ= Ġbranch Protection Patterns . to Mutable List () ĊĠĠĠ Ġ} ĊĠ Ġ} Ċ Ċ } Ċ