+
    oFj-                         R t ^ RIt^ RIt^ RIt^ RIt^ RIt^ RIHtH	t	 ^ RI
Ht ^ RIHtHt ^ RIt^ RIt ! R R4      t]! RR7       ! R	 R
4      4       t ! R R]P(                  P*                  4      tR# )z)Crash database implementation for Github.N)CallableMapping)	dataclass)AnySelfc                      a  ] tR t^t o Rt]P
                  ! 4       tRV 3R lR lltV 3R lR ltV 3R lR lt	V 3R	 lR
 lt
V 3R lR ltV 3R lR ltV 3R lR ltV 3R ltRtV tR# )Githubz:Wrapper around Github API, used to log in and post issues.Nc                8   < V ^8  d   QhRS[ RS[R,          RR/# )   	client_idmessage_callbackNreturn)strr   )format__classdict__s   "</usr/lib/python3/dist-packages/apport/crashdb_impl/github.py__annotate__Github.__annotate__   s)     1 110841	1    c                V    Wn         R V n        R V n        RV n        RV n        W n        R # Ng        )_Github__client_id_Github__authentication_data_Github__access_token_Github__cooldown_Github__expiryr   )selfr   r   s   &&&r   __init__Github.__init__   s.     %<@"" 0r   c                ,   < V ^8  d   QhRS[ RS[ RS[/# r
   urldatar   )r   r   )r   r   s   "r   r   r   (   s"     . . .C .C .r   c                   RR/pV P                   '       d   RV P                    2VR&   \        P                  P                  WP	                  R4      VRR7      p \        P                  P                  VRR	7      ;_uu_ 4       p\        P                  ! VP                  4       4      uuR
R
R
4       \        P                  ! 4       V n
        #   + '       g   i     MT; i  \        P                  P                   d0   pT P                  '       d   T P                  RRT R24       ThR
p?ii ; i \        P                  ! 4       T n
        R
#   \        P                  ! 4       T n
        i ; i)zCPosts the given data to the given URL.
Uses auth token if availableAcceptzapplication/vnd.github.v3+jsonztoken Authorizationzutf-8POST)r"   headersmethodg      @)timeoutNzFailed connectionzFailed connection to z6.
Please check your internet connection and try again.)r   urllibrequestRequestencodeurlopenjsonloadsreadtime_Github__last_requesterrorURLErrorr   )r   r!   r"   r'   r+   responseerrs   &&&    r   _postGithub._post(   s$    =>)/0C0C/D'EGO$..((kk'*GF ) 
	.'''==zz(--/2 >= #'))+D >=||$$ 	$$$%%'+C5 1K L
 I	 > #'))+D$))+DsH   )C  $C(
C  C	C  E C   D.?*D))D..E E*c                ,   < V ^8  d   QhRS[ RS[RS[/# r    r   dictr   )r   r   s   "r   r   r   ?   s"     = =c = =# =r   c                `    V P                  V\        P                  P                  V4      4      # )z$Authenticate against the GitHub API.)r8   r*   parse	urlencode)r   r!   r"   s   &&&r   api_authenticationGithub.api_authentication?   s"    zz#v||55d;<<r   c                2   < V ^8  d   QhRS[ RS[ RS[RS[/# )r
   ownerrepor"   r   r;   )r   r   s   "r   r   r   C   s)     1 1C 1s 1$ 13 1r   c                `    RV RV R2pV P                  V\        P                  ! V4      4      # )z'Open a new issue on the GitHub project.zhttps://api.github.com/repos//z/issues)r8   r/   dumps)r   rC   rD   r"   r!   s   &&&& r   api_open_issueGithub.api_open_issueC   s0    -eWAdV7Czz#tzz$/00r   c                    < V ^8  d   QhRS[ /# r
   r   )r   )r   r   s   "r   r   r   H   s      4 r   c                   RV P                   RR/pRpV P                  W!4      pRpVR,          pVR,          pV P                  '       d#   V P                  RVP                  W%R	7      4       RV P                   R
VR
,           RR/V n        VR,          V n        \        VR,          4      \        P                  ! 4       ,           V n        V # )z2Enters login process. At exit, login process ends.r   scopepublic_repoz$https://github.com/login/device/codezPosting an issue requires a Github account. If you have one, please follow these steps to log in.

Open the following URL. When requested, write this code to enable apport to open an issue.
URL:  {url}
Code: {code}verification_uri	user_codezLogin required)r!   codedevice_code
grant_typez,urn:ietf:params:oauth:grant-type:device_codeinterval
expires_in)	r   r@   r   r   r   r   intr2   r   )r   r"   r!   r6   promptrQ   s   &     r   	__enter__Github.__enter__H   s    T--wF4**35 	 )*$   !!"2FMMcM4UV ))h}56H&
"
 #:.H\23diikAr   c                $   < V ^8  d   QhRS[ RR/# )r
   _r   N)r   )r   r   s   "r   r   r   h   s      3 4 r   c                0    R V n         RV n        RV n        R # r   )r   r   r   )r   r[   s   &*r   __exit__Github.__exit__h   s    %)"r   c                    < V ^8  d   QhRS[ /# rK   )bool)r   r   s   "r   r   r   m   s     !H !H !Hr   c                   V P                   '       g   \        R4      h\        P                  ! 4       pV P                  WP                  ,
          ,
          pW,           V P
                  8  d0   V P                  '       d   V P                  RR4       \        R4      hV^ 8  d   \        P                  ! V4       RpV P                  W0P                   4      pRV9   dF   VR,          R8X  d   R# VR,          R	8X  d   \        VR
,          4      V n        R# \        RV 24      hRV9   d   VR,          V n
        R# \        RV 24      h)z^Asks Github if the user has logged in already.
It respects the wait-time requested by Github.
z9Authentication not started. Use a with statement to do sozFailed loginz0Github authentication expired. Please try again.zGithub authentication expiredz+https://github.com/login/oauth/access_tokenr4   authorization_pendingF	slow_downrT   zUnknown error from Github: access_tokenTzUnknown response from Github: )r   RuntimeErrorr2   r   r3   r   r   sleepr@   rV   r   )r   current_timewaittimer!   r6   s   &    r   authentication_completeGithub.authentication_completem   s'    )))K  yy{??l5H5H&HI"T]]2$$$%%"$V >??a<JJx ;**30J0JKh $;; K/"%hz&:";!<XJGHHX%"*>":D;H:FGGr   c                &   < V ^8  d   Qh/ S[ ;R&   # )r
   r3   )float)r   r   s   "r   r   r      s      ' r   )__access_token__authentication_data__client_id
__cooldown__expiry__last_requestr   N)__name__
__module____qualname____firstlineno____doc__r2   r3   r   r8   r@   rH   rX   r]   ri   __annotate_func____static_attributes____classdictcell__r   s   @r   r   r      sd     D IIKN1 1. ..= =1 1
 @ 
!H !Hi  r   r   T)frozenc                   ,   a  ] tR t^t o V 3R ltRtV tR# )IssueHandlec                &   < V ^8  d   Qh/ S[ ;R&   # )r
   r!   )r   )r   r   s   "r   r   IssueHandle.__annotate__   s     	H r    N)rt   ru   rv   rw   ry   rz   r{   r|   s   @r   r   r      s      r   r   c                     a  ] tR t^t o RtV 3R lR ltV 3R lR ltR+V 3R lR lltR,V 3R	 lR
 lltV 3R lR lt	R t
V 3R lR ltR tR tV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltR tV 3R lR ltV 3R lR  ltV 3R! lR" ltV 3R# lR$ ltR+V 3R% lR& lltV 3R' lR( ltR-R) ltR*tV tR# ).CrashDatabasezbGithub crash database.
This is a Apport CrashDB implementation for interacting with Github issues
c                N   < V ^8  d   QhRS[ R,          RS[S[ S[3,          RR/# )r
   	auth_fileNoptionsr   r;   )r   r   s   "r   r   CrashDatabase.__annotate__   s.     * *#* *tCH~ *$ *r   c                    \         P                  P                  P                  WV4       VR,          V n        VR,          V n        VR,          V n        \        VR,          4      V n        RV n	        RV n
        R# )z<Initialize some variables. Login is delayed until necessary.repository_ownerrepository_namegithub_app_idlabelsN)apportcrashdbr   r   r   r   app_idsetr   	issue_urlgithub)r   r   r   s   &&&r   r   CrashDatabase.__init__   sc    $$--dwG '(: ;&'89o.'(+,%)r   c                r   < V ^8  d   QhRS[ S[S[3,          RS[S[S[S[S[,          ,          3,          /# )r
   reportr   )r   r   r   r<   list)r   r   s   "r   r   r      s7     

 

WS#X%6 

4S4PS9_@T;U 

r   c                    RpVP                  4        F  w  r4VRV RV R2,          pK  	  RRRVR\        V P                  4      /# )	z>Formats report info as markdown and creates Github issue JSON. z**z**
z

titlezIssue submitted via apportbodyr   )itemsr   r   )r   r   body_markdownkeyvalues   &&   r   _format_reportCrashDatabase._format_report   sW     ,,.JCr#d5'66M ) 1Md4;;'
 	
r   Nc                4   < V ^8  d   QhRS[ R,          RS[/# )r
   user_message_callbackNr   )r   r   )r   r   s   "r   r   r      s      8d? f r   c                    \        V P                  V4      ;_uu_ 4       pVP                  4       '       g   K  VuuR R R 4       #   + '       g   i     R # ; irs   )r   r   ri   )r   r   r   s   && r   _github_loginCrashDatabase._github_login   s:    DKK!67764466 8777s   AAA	c                d   < V ^8  d   QhRS[ S[S[3,          RS[R,          RS[R,          RS[/# )r
   r   progress_callbackNr   r   )r   r   r   r   r   )r   r   s   "r   r   r      sD     5 5S!5 $d?5  ($	5
 
5r   c                    V P                  V4      '       g   Q hV P                  V4      V n        V P                  f   \        R4      hV P	                  V4      pV P
                  f   V P                  e3   V P                  P                  V P                  V P
                  V4      pMERV9   d4   RV9   d-   V P                  P                  VR,          VR,          V4      pM\        R4      h\        VR,          R7      # )zQUpload given problem report return a handle for it.
In Github, we open an issue.
zFailed to login to GithubSnapGitOwnerSnapGitNamez9Couldn't determine which repository to file the report inhtml_urlr!   )	acceptsr   r   re   r   r   r   rH   r   )r   r   r   r   r"   r6   s   &&&&  r   uploadCrashDatabase.upload   s     ||F####(()>?;;:;;""6*$$,1F1F1N{{11%%t';';TH v%-6*A{{11~&}(=tH K  x
344r   c                T   < V ^8  d   QhRS[ P                  P                  RS[RS[/# )r
   r   handler   )r   r   Reportr   r   )r   r   s   "r   r   r      s-      fmm&:&: K TW r   c                    VP                   # )z`Return a URL that should be opened after report has been uploaded
and upload() returned handle.
r   )r   r   r   s   &&&r   get_comment_urlCrashDatabase.get_comment_url   s     zzr   c                    \        R 4      hz?This method is not relevant for Github database implementation.NotImplementedError)r   crash_idr   s   &&&r   _mark_dup_checkedCrashDatabase._mark_dup_checked       !M
 	
r   c                &   < V ^8  d   QhRS[ RS[/# r
   r   r   rV   r`   )r   r   s   "r   r   r      s     
 
3 
4 
r   c                    \        R 4      hr   r   r   r   s   &&r   
can_updateCrashDatabase.can_update   r   r   c                    \        R 4      hr   r   )r   r   r   	master_ids   &&&&r   close_duplicateCrashDatabase.close_duplicate   r   r   c                    \        R 4      hr   r   r   s   &&r   downloadCrashDatabase.download   r   r   c                4   < V ^8  d   QhRS[ RS[ R,          /# r
   r   r   NrV   )r   r   s   "r   r   r      s     
 
S 
S4Z 
r   c                    \        R 4      hr   r   r   s   &&r   duplicate_ofCrashDatabase.duplicate_of   r   r   c                6   < V ^8  d   QhRS[ RS[S[,          /# r   )rV   r   r   )r   r   s   "r   r   r      s     
 
c 
d3i 
r   c                    \        R 4      hr   r   r   s   &&r   get_affected_packages#CrashDatabase.get_affected_packages   r   r   c                &   < V ^8  d   QhRS[ RS[/# r   rV   r   )r   r   s   "r   r   r      s     
 
3 
3 
r   c                    \        R 4      hr   r   r   s   &&r   get_distro_release CrashDatabase.get_distro_release   r   r   c                0   < V ^8  d   QhRS[ S[,          /# rK   r   rV   )r   r   s   "r   r   r      s     
 
3s8 
r   c                    \        R 4      hr   r   r   s   &r   get_dup_uncheckedCrashDatabase.get_dup_unchecked   r   r   c                4   < V ^8  d   QhRS[ RS[R,          /# r   r   )r   r   s   "r   r   r     s     
 
# 
#* 
r   c                    \        R 4      hr   r   r   s   &&r   get_fixed_versionCrashDatabase.get_fixed_version  r   r   c                    \        R 4      hr   r   )r   r   r   s   &&&r   
get_id_urlCrashDatabase.get_id_url
  r   r   c                0   < V ^8  d   QhRS[ S[,          /# rK   r   )r   r   s   "r   r   r     s     
 
SX 
r   c                    \        R 4      hr   r   r   s   &r   get_unfixedCrashDatabase.get_unfixed  r   r   c                0   < V ^8  d   QhRS[ S[,          /# rK   r   )r   r   s   "r   r   r     s     
 
C 
r   c                    \        R 4      hr   r   r   s   &r   get_unretracedCrashDatabase.get_unretraced  r   r   c                &   < V ^8  d   QhRS[ RS[/# r   r   )r   r   s   "r   r   r     s     
 
C 
D 
r   c                    \        R 4      hr   r   r   s   &&r   is_reporterCrashDatabase.is_reporter  r   r   c                *   < V ^8  d   QhRS[ RS[ RR/# )r
   r   masterr   Nr   )r   r   s   "r   r   r     s"     
 
 
S 
T 
r   c                    \        R 4      hr   r   )r   r   r   s   &&&r   mark_regressionCrashDatabase.mark_regression  r   r   c                8   < V ^8  d   QhRS[ RS[R,          RR/# )r
   r   invalid_msgNr   r   )r   r   s   "r   r   r   #  s)     
 

*-*
	
r   c                    \        R 4      hr   r   )r   r   r   s   &&&r   mark_retrace_failed!CrashDatabase.mark_retrace_failed#  s     "M
 	
r   c                $   < V ^8  d   QhRS[ RR/# r   r   )r   r   s   "r   r   r   *  s     
 
c 
d 
r   c                    \        R 4      hr   r   r   s   &&r   mark_retracedCrashDatabase.mark_retraced*  r   r   c                    \        R 4      hr   r   )r   r   r   commentchange_descriptionattachment_comment
key_filters   &&&&&&&r   updateCrashDatabase.update0  s     "M
 	
r   )r   r   r   r   r   r   rs   )NN)FNN)rt   ru   rv   rw   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  rz   r{   r|   s   @r   r   r      s     * *

 

 5 5@ 


 






 


 


 


 


 




 


 


 


 


 

 

 
r   r   )rx   r/   r2   urllib.errorr*   urllib.parseurllib.requestcollections.abcr   r   dataclassesr   typingr   r   apport.crashdbr   apport.reportr   r   r   r   r   r   r   <module>r     sm    /      - !   uH uHp $  e
FNN00 e
r   