
    NZyiH                     v   S r SSKrSSKrSSKJr   SSKJr  SSKJr  SSK	J
r
  \R                  " \R                  S\R                  " S	5      \R                  " \R                   5      /S
9  \R"                  " \5      rS\S\S\S\
4S jrS r\S:X  a  \" 5         gg! \ a    SSKJr  SSKJr  SSK	J
r
   Nf = f)zD
Script to update the top 20 active repositories that need updates.
    N)Path)ConfigManager)BitbucketClient)
GitManager   z4%(asctime)s - %(name)s - %(levelname)s - %(message)szupdate_top_repos.log)levelformathandlersrepos_to_update	repos_dir	bitbucketgit_managerc                    [         R                  S[        U 5       S35        SnSnU  GH  n[         R                  SU S35        X-  nUR                  5       (       d  [         R	                  SU 35        US-  nMU   UR                  U5      nU(       d  [         R                  S5        SS	KJn	   U	" U5      n
U
R                  S
S9nUR                  5          U
R                  R                  nU
R                  R                  5         [         R                  SU SU S35        US-  nGM  UR                  USS9nU(       d   [         R	                  SU 35        US-  nGM=  UR!                  UUS9u  nnU(       a@  U(       a  [         R                  SU 35        O[         R                  SU 35        US-  nGM  [         R	                  SU 35        US-  nGM     XE4$ ! [         a*  n[         R                  SU SU 35        US-  n SnANSnAff = f! [         a+  n[         R	                  SU SU 35        US-  n SnAGN SnAff = f! [         a,  n[         R	                  SU SU 35        US-  n SnAGM\  SnAff = f)z
Update specific repositories.

Args:
    repos_to_update: List of repository slugs to update
    repos_dir: Path to repositories directory
    bitbucket: BitbucketClient instance
    git_manager: GitManager instance
z	Updating z repositories...r   z

Updating z...z/  [ERROR] Repository directory does not exist: r   zQ  [WARN] Could not fetch repo info from Bitbucket, trying with existing remote...)Repoorigin)namez  [OK] Successfully updated z
 (branch: )z  [WARN] Could not pull z: Nz  [ERROR] Failed to update ssh)protocolz&  [ERROR] Could not get clone URL for )	repo_slug	clone_urlz  [OK] Successfully cloned z$  [ERROR] Unexpected error updating )loggerinfolenexistserrorget_repository_infowarninggitr   remotefetchactive_branchr   pull	Exceptionget_clone_urlclone_or_update)r   r   r   r   updated_countfailed_countr   	repo_path	repo_infor   repor   current_brancher   resultis_first_clones                    0C:\wamp64\www\sonar_scan\src\update_top_repos.pyupdate_repositoriesr1      s    KK)C011ABCML$	k)C01)	!!LLJ9+VWAL/	!55i@I!rt$&	?D![[h[7FLLN*)-););)@)@&B9+ZXfWggh$ij%* !//	E/JIEi[QR! &1%@%@## &A &"FN
 !KK"=i[ IJKK">yk JK":9+FG!k %v &&E % *)A)Bqc'RS$)* ! &LL#>ykA3!OP A%L&6  	LL?	{"QCPQAL	sz   ?3I3'HAG%/4I&AI I%
H/ HHIHH
I& IIII
J
 JJ
c                     [         R                  S5        [         R                  S5        [         R                  S5        / SQn  [        5       nUR                  S5      (       d+  [         R	                  S5        [
        R                  " S5        [        UR                  S5      5      n[        UR                  S5      5      nUR                  S	5      (       d+  [         R	                  S
5        [
        R                  " S5        U(       d2  U(       d+  [         R	                  S5        [
        R                  " S5        [        UR                  S5      UR                  S	5      U(       d  UR                  S5      OSUR                  S5      S9n[        UR                  S5      S9n[        UR                  S5      5      n[        XXE5      u  px[         R                  S5        [         R                  S5        [         R                  S5        [         R                  S[        U 5       35        [         R                  SU 35        [         R                  SU 35        [         R                  S5        US:  a  [
        R                  " S5        g[         R                  S5        [
        R                  " S5        g! [         a7  n	[         R	                  SU	 3SS9  [
        R                  " S5         Sn	A	gSn	A	ff = f)z7Main function to update repositories that need updates.z<============================================================z#Updating Top 20 Active Repositories)doh_simssawisneoafrica_qaedioverdrivezipw-php	superbowlzbitbucket.workspacez"Bitbucket workspace not configuredr   zbitbucket.api_tokenzbitbucket.app_passwordzbitbucket.usernamez'Bitbucket username/email not configuredz'Bitbucket authentication not configuredN)	workspaceusernameapp_password	api_tokenzscanning.repos_dir)r   z=
============================================================zUpdate SummaryzTotal repositories to update: z  [OK] Successfully updated: z  [ERROR] Failed: r   z1
[SUCCESS] All repositories updated successfully!zUnexpected error: T)exc_info)r   r   r   getr   sysexitboolr   r   r   r1   r   r$   )
r   confighas_api_tokenhas_app_passwordr   r   r   r'   r(   r-   s
             r0   mainrD   l   s0   
KK
KK56
KKO8 zz/00LL=>HHQKVZZ(=>?

+C DEzz.//LLBCHHQK%5LLBCHHQK $jj!67ZZ 45ER$<=X\jj!67	
	 !jj!56
 $89:	 ':	'
#
 	O$$%H4S5I4JKL3M?CD(78H!HHQKKKLMHHQK )!-=s   IJ= +J= =
K>-K99K>__main__)__doc__r>   loggingpathlibr   config_managerr   bitbucket_clientr   r   r   ImportErrorbasicConfigINFOFileHandlerStreamHandlerstdout	getLogger__name__r   listr1   rD        r0   <module>rV      s      (,0&   
,,A23cjj) 
		8	$J' J'$ J'? J'is J'ZHV zF U  (-1'(s   B B87B8