// Ġinvoke ĠGithub ĠREST ĠAPI Ġin Ġkotlin Ċ // Ġidentify Ġall Ġrepos Ġthe Ġauthenticated Ġuser Ġhas Ġcollabor ated Ġon Ġand Ġlist Ġall Ġothers Ġwho Ġhave Ġworked Ġon Ġthe Ġsame Ġrepos . Ċ // Ġcer ner _ 2 tot he 5 th _ 2 0 2 1 Ċ // ĠRun Ġwith Ġargs Ġ< your - user - name > Ġ< your - password > Ġ< github - v 3 - api - endpoint > Ċ import Ġokhttp 3 . Ok HttpClient Ċ import Ġretrofit 2 .* Ċ import Ġretrofit 2 . http .* Ċ import Ġretrofit 2 . converter . mos hi . M oshi Converter Factory Ċ import Ġjava . util . function . Function Ċ import Ġjava . util . stream . Collectors Ċ Ċ // Ġservice Ġinterface Ċ interface ĠGitHub Service Ġ{ ĊĠĠĠ Ġ@ GET (" user / repos ? per _ page = 1 0 0 & sort = pus hed & order = desc ") ĊĠĠĠ Ġfun ĠgetUser Repos (): ĠCall < List < Repo >> ĊĊĠĠĠ Ġ@ GET (" repos /{ owner }/{ repo }/ contributors ? per _ page = 1 0 0 ") ĊĠĠĠ Ġfun Ġget Repo Contribut ors (@ Path (" owner ") Ġowner : ĠString , Ġ@ Path (" repo ") Ġrepo : ĠString ): ĠCall < List < User >> Ġ} Ċ Ċ // Ġdata Ġclasses Ċ data Ġclass ĠUser ( val Ġlogin : ĠString , Ġval Ġcontributions : ĠInt ) Ċ data Ġclass ĠRepo ( val Ġfull _ name : ĠString ) Ċ Ċ fun Ġmain ( args : ĠArray < String >) Ġ{ ĊĠĠĠ Ġval Ġauth Token Ġ= Ġ" Basic Ġ" Ġ+ Ġjava . util . Base 6 4 . get Encoder (). encode ("${ args [ 0 ]} :${ args [ 1 ]} ". toByteArray ()). toString ( Charsets . UTF _ 8 ) ĊĠĠĠ Ġval ĠhttpClient Ġ= ĠOk HttpClient . Builder (). add Interceptor Ġ{ Ġchain Ġ-> ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġrequest Ġ= Ġchain . request (). newBuilder (). header (" Accept ", Ġ" application / vnd . github . v 3 + json "). header (" Authorization ", Ġauth Token ). build () ĊĠĠĠĠĠĠĠĠĠĠĠ Ġchain . proceed ( request ) Ġ}. build () ĊĊĠĠĠ Ġval Ġservice Ġ= ĠRet rofit . Builder (). baseUrl ( args [ 2 ]). add Converter Factory ( M oshi Converter Factory . create ()). client ( httpClient ). build (). create ( GitHub Service :: class . java ) ĊĠĠĠ Ġval Ġrequest Ġ= Ġservice . getUser Repos (). execute () ĊĠĠĠ Ġval Ġunique Collabor ators Ġ= ĠArrayList < String >() ĊĊĠĠĠ Ġ// Ġpick Ġfirst Ġ 1 0 0 Ġrepos Ġwhich Ġare Ġrecently Ġpushed Ġ- Ġpag inate Ġthis Ġto Ġget Ġall Ġrepos Ġwhere Ġyou Ġmight Ġhave Ġworked Ġon ĊĠĠĠ Ġprintln (" Found Ġ${ request . body () !!. size } Ġrepositories Ġwhere Ġyou Ġhave Ġcollabor ated ") ĊĠĠĠ Ġfor Ġ( repo Ġin Ġrequest . body () !! ){ ĊĠĠĠĠĠĠĠ Ġprintln ( repo . full _ name ) ĊĠĠĠĠĠĠĠ Ġval Ġsplits Ġ= Ġrepo . full _ name . split ( Ġ"/", Ġignore Case Ġ= Ġfalse , Ġlimit Ġ= Ġ 0 ) ĊĠĠĠĠĠĠĠ Ġservice . get Repo Contribut ors ( splits [ 0 ], Ġsplits [ 1 ]). execute (). body () !!. forEach Ġ{ Ġcollabor ator Ġ-> Ġunique Collabor ators . add ( coll aborator . login ) Ġ} ĊĠĠĠ Ġ} ĊĠĠĠ Ġ// Ġidentify Ġcollabor ators Ġon Ġabove Ġrepos Ġ- Ġsorted Ġby Ġmost Ġrepos Ġwhere Ġyou Ġhave Ġworked Ġtogether Ġon . ĊĠĠĠ Ġprintln (" Collabor ators Ġon Ġrepos Ġwhich Ġyou Ġhave Ġcontributed Ġ- Ġsorted Ġby Ġmost Ġinteractions .. ") ĊĠĠĠ Ġprintln ( unique Collabor ators . stream (). collect ( Collectors . grouping By ( Function . identity (), ĠCollect ors . count ing ())). toList (). sorted By Descending Ġ{ Ġ(_, Ġvalue ) Ġ-> Ġvalue Ġ}. take ( 1 0 )) Ċ } Ċ