def __init__(self, config): self.token = self.get_token(config) self.username = self.get_username(config) self.g = github.Github(self.token) self._repos = config['repos'] self.monitoring_db = monitoring.GetDatabase('spinbot') self.logging = logging.getLogger('github_client_wrapper')
def ApplyPolicies(g): config = GetConfig() enabled = config.get('enabled', True) if enabled is not None and not enabled: return monitoring_db = monitoring.GetDatabase('spinbot') logging.info('Processing issues, repos') for i in itertools.chain(*[g.issues(), g.pull_requests(), g.repos()]): for p in policy.Policies(): if p.applies(i): err = None try: p.apply(g, i) except Exception as _err: logging.warn('Failure applying {} to {} due to {}: {}'.format( p, i, _err, traceback.format_exc() )) err = _err monitoring_db.write('policy_handled', { 'value': 1 }, tags={ 'policy': p.id, 'error': err }) if err is not None and isinstance(err, github.GithubException.GithubException): if err.status == 403: # we triggered abuse protection, time to shutdown logging.warn('Abuse protection triggered. Shutting down early.') return
def ApplyPolicies(g): config = GetConfig() enabled = config.get('enabled', True) if enabled is not None and not enabled: return monitoring_db = monitoring.GetDatabase('spinbot') logging.info('Processing issues, repos') for i in itertools.chain(*[g.issues(), g.repos()]): for p in policy.Policies(): if p.applies(i): err = None try: p.apply(g, i) except Exception as _err: logging.warn('Failure applying {} to {}: {}'.format( p, i, traceback.format_exc())) err = _err monitoring_db.write('issues_handled', {'value': 1}, tags={ 'policy': p.id, 'error': err })
def ProcessEvents(g, s): config = GetConfig() enabled = config.get('enabled', True) if enabled is not None and not enabled: return start_at = config.get('start_at') monitoring_db = monitoring.GetDatabase('spinbot') if start_at is None: start_at = s.load('start_at') if start_at is None: start_at = datetime.now() else: start_at = datetime.strptime(start_at, dateformat) newest_event = start_at logging.info('Processing events, starting at {}'.format(start_at)) for e in g.events_since(start_at): if e.created_at > newest_event: newest_event = e.created_at s.store('start_at', newest_event.strftime(dateformat)) for h in event.Handlers(): if h.handles(e): logging.info('Handling {} with {}'.format(e, h)) err = None try: h.handle(g, e) except Exception as _err: logging.warn( 'Failure handling {} with {} due to {}: {}'.format( e, h, _err, traceback.format_exc())) err = _err monitoring_db.write('event_handle', {'value': 1}, tags={ 'handler': h.id, 'error': err })
def __init__(self): self.id = self._id() self.logging = logging.getLogger(self.id) self.monitoring_db = monitoring.GetDatabase('spinbot') self.config = GetHandlerConfig(self.id) RegisterHandler(self)