def send_report(self, title, body, application_log=None): _logger().debug('sending bug report on github\ntitle=%s\nbody=%s', title, body) # Credentials credentials = self.get_user_credentials() username = credentials['username'] password = credentials['password'] remember = credentials['remember'] token = credentials['token'] remember_token = credentials['remember_token'] if username is None and password is None and token is None: return False _logger().debug('got user credentials') # upload log file as a gist if application_log: url = self.upload_log_file(application_log) body += '\nApplication log: %s' % url try: if token: gh = github.GitHub(access_token=token) else: gh = github.GitHub(username=username, password=password) repo = gh.repos(self.gh_owner)(self.gh_repo) ret = repo.issues.post(title=title, body=body) except github.ApiError as e: _logger().warning('Failed to send bug report on Github. ' 'response=%r', e.response) # invalid credentials if e.response.code == 401: if self._show_msgbox: QMessageBox.warning( self.parent_widget, _('Invalid credentials'), _('Failed to create Github issue, ' 'invalid credentials...')) else: # other issue if self._show_msgbox: QMessageBox.warning( self.parent_widget, _('Failed to create issue'), _('Failed to create Github issue. Error %d') % e.response.code) return False else: issue_nbr = ret['number'] if self._show_msgbox: ret = QMessageBox.question( self.parent_widget, _('Issue created on Github'), _('Issue successfully created. Would you like to open the ' 'issue in your web browser?')) if ret in [QMessageBox.Yes, QMessageBox.Ok]: webbrowser.open( 'https://github.com/%s/%s/issues/%d' % ( self.gh_owner, self.gh_repo, issue_nbr)) return True
def upload_log_file(self, log_content): gh = github.GitHub() try: qApp.setOverrideCursor(Qt.WaitCursor) ret = gh.gists.post( description="SpyderIDE log", public=True, files={'SpyderIDE.log': {"content": log_content}}) qApp.restoreOverrideCursor() except github.ApiError: _logger().warning('Failed to upload log report as a gist') return '"Failed to upload log file as a gist"' else: return ret['html_url']