!f@+dZddlZddlZddlmZddlmZddlmZddl Z ddl Z ddl Z GddZ ed Gd d Z Gd d e jjZy)z)Crash database implementation for Github.N)Callable) dataclass)AnyceZdZUdZejZeed<dZe de de fdZ de de de fdZde de de fd Zd e d e de de fd Zd Zde ddfdZdefdZy)Githubz:Wrapper around Github API, used to log in and post issues._Github__last_requestcX||_d|_d|_d|_d|_||_yN)_Github__client_id_Github__authentication_data_Github__access_token_Github__cooldown_Github__expirymessage_callback)self client_idrs    )/0C0C/D'EGO $ .]]3dCPF#'))+D !zz&++&&((   ! !#'uC0HI  I  #'))+D s#BB9B44B99B<<CcD|j||j|S)z$Authenticate against the GitHub API.)r1r )rr!rs rapi_authenticationzGithub.api_authenticationBszz#tt455rownerrepoc^d|d|d}|j|tj|S)z'Open a new issue on the GitHub project.zhttps://api.github.com/repos//z/issues)r1r,dumps)rr4r5rr!s rapi_open_issuezGithub.api_open_issueFs0-eWAdV7Czz#tzz$/00rc@|jdd}d}|j||}d}|d}|d}|jd|j|||j|d d d |_|d |_t |d tjz|_|S)z2Enters login process. At exit, login process ends. public_repo)rscopez$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_codezLogin required)r!code device_codez,urn:ietf:params:oauth:grant-type:device_code)rr@ grant_typeinterval expires_in) r r3rformatr rintr*r)rrr!responsepromptr?s r __enter__zGithub.__enter__Ks!-- F4**35  )* $ . #D 0QR))&}56H& " #:.H\23diikA  r_Nc.d|_d|_d|_y)Nr)r rr)rrIs r__exit__zGithub.__exit__js%)" rc|js tdtj}|j||jz z }||z|j kDr|j ddtd|dkDrtj|d}|j||j}d|vr3|ddk(ry |dd k(rt|d |_y td |d |vr |d |_ ytd|)znAsks 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.zGithub authentication expiredrz+https://github.com/login/oauth/access_tokenerrorauthorization_pendingF slow_downrBzUnknown error from Github: access_tokenTzUnknown response from Github: ) r RuntimeErrorr*rrrrsleepr3rEr )r current_timewaittimer!rFs rauthentication_completezGithub.authentication_completeos))K yy{ ??lT5H5H&HI ( "T]] 2  ! ! R >? ? a< JJx ;**30J0JK h  $;; K/"%hz&:";!":D ;H:FGGr)__name__ __module__ __qualname____doc__r*rfloat__annotations__r staticmethoddictstrr rr1r3r9rHrKboolrUrrrrsD%DIIKNE'1#''C'C'*6c66#61C1s1$131 >34 H HrrT)frozenceZdZUeed<y) IssueHandler!N)rVrWrXr^r[r`rrrcrcs Hrrcc eZdZdZdZdej defdZdZ ddej de dzd e dzde fd Z dej d e de fd Zd ZdZdZdZdZdZdZdZdZdZdZdZdZdZddZdZ d dZy)! CrashDatabasezjGithub crash database. This is a Apport CrashDB implementation for interacting with Github issues ctjjj||||d|_|d|_|d|_t|d|_d|_ d|_ y)zFormats report info as markdown and creates Github issue JSON.rz**z** z zIssue submitted via apport)titlebodyrj)rlistrj)rrs body_markdownrrs r_format_reportzCrashDatabase._format_reportsW  ,,. 7JC r#d5'6 6M 72!4;;'  rct|j|5}|js |js|cdddS#1swYyxYwr )rrmrU)ruser_message_callbackrps r _github_loginzCrashDatabase._github_loginsH DKK!6 7 6446446   s"AAANprogress_callbackr{c|j|sJ|j||_|j td|j |}|j |j 2|jj|j |j |}n7d|vr(d|vr$|jj|d|d|}n tdt|dS)zaUpload given problem report return a handle for it. In Github, we open an issue. zFailed to login to Github SnapGitOwner SnapGitNamez9Couldn't determine which repository to file the report inhtml_urlr!) acceptsr|rprQryrhrgr9rc)rrsr}r{rrFs ruploadzCrashDatabase.uploads||F###(()>? ;; :; ;""6*$$,1F1F1N{{11%%t';';THv %-6*A{{11~&}(=tHK x 344rhandlec|jS)zpReturn a URL that should be opened after report has been uploaded and upload() returned handle. r)rrsrs rget_comment_urlzCrashDatabase.get_comment_urlszzrctdNz?This method is not relevant for Github database implementation.NotImplementedError)rcrash_idrss r_mark_dup_checkedzCrashDatabase._mark_dup_checked! M  rctdrrrrs r can_updatezCrashDatabase.can_updaterrctdrr)rrsr master_ids rclose_duplicatezCrashDatabase.close_duplicaterrctdrrrs rdownloadzCrashDatabase.downloadrrctdrrrs r duplicate_ofzCrashDatabase.duplicate_ofrrctdrrrs rget_affected_packagesz#CrashDatabase.get_affected_packagesrrctdrrrs rget_distro_releasez CrashDatabase.get_distro_releaserrctdrrrs rget_dup_uncheckedzCrashDatabase.get_dup_uncheckedrrctdrrrs rget_fixed_versionzCrashDatabase.get_fixed_versionrrctdrr)rrsrs r get_id_urlzCrashDatabase.get_id_url rrctdrrrs r get_unfixedzCrashDatabase.get_unfixedrrctdrrrs rget_unretracedzCrashDatabase.get_unretracedrrctdrrrs r is_reporterzCrashDatabase.is_reporterrrctdrr)rrmasters rmark_regressionzCrashDatabase.mark_regressionrrctdrr)rr invalid_msgs rmark_retrace_failedz!CrashDatabase.mark_retrace_failed$rrctdrrrs r mark_retracedzCrashDatabase.mark_retraced)rrctdrr)rrrscommentchange_descriptionattachment_comment key_filters rupdatezCrashDatabase.update.s" M  r)NNr )FNN) rVrWrXrYrrkReportr]ryr|rrcrr^rrrrrrrrrrrrrrrrrrr`rrreres  V]]  t  .215 5 5$d?5 ($ 5  5@fmm[S                 !  rre)rYr,r*collections.abcr dataclassesrtypingrr'rkapport.crashdbrrcrlrer`rrrsg/ $! wHwHt $   b FNN00b r