def process_review_event(self, request: ReviewEvent) -> EventResponse: base_ptr = ReferencePointer.from_pb(request.commit_revision.base) head_ptr = ReferencePointer.from_pb(request.commit_revision.head) response = EventResponse() response.analyzer_version = self.version comments = [] for analyzer in self._analyzers: try: mycfg = dict(request.configuration[analyzer.__name__]) except (KeyError, ValueError): mycfg = {} model, cache_miss = self._model_repository.get( self._model_id(analyzer), analyzer.model_type, base_ptr.url) if cache_miss: self._log.info("cache miss: %s", analyzer.__name__) if model is None: self._log.info("training: %s", analyzer.__name__) model = analyzer.train(base_ptr, mycfg, self._data_service.get()) self._model_repository.set(self._model_id(analyzer), base_ptr.url, model) self._log.debug("running %s", analyzer.__name__) results = analyzer(model, head_ptr.url, mycfg).analyze( base_ptr, head_ptr, self._data_service.get()) self._log.info("%s: %d comments", analyzer.__name__, len(results)) comments.extend(results) response.comments.extend(comments) return response
def process_push_event(self, request: PushEvent) -> EventResponse: # noqa: D401 """ Callback for push events invoked by EventListener. """ ptr = ReferencePointer.from_pb(request.commit_revision.head) data_service = self._data_service for analyzer in self._analyzers: if analyzer.model_type == DummyAnalyzerModel: continue try: mycfg = self._protobuf_struct_to_dict( request.configuration[analyzer.name]) except (KeyError, ValueError): mycfg = {} model = self._get_model(analyzer, ptr.url) if model is not None: must_train = analyzer.check_training_required( model, ptr, mycfg, data_service) if not must_train: self._log.info("skipped training %s", analyzer.name) continue self._log.debug("training %s", analyzer.name) record_event("%s.train" % analyzer.name, 1) model = analyzer.train(ptr, mycfg, data_service) self._model_repository.set(self._model_id(analyzer), ptr.url, model) response = EventResponse() response.analyzer_version = self.version return response
def process_push_event(self, request: PushEvent) -> EventResponse: ptr = ReferencePointer.from_pb(request.commit_revision.head) for analyzer in self._analyzers: self._log.debug("training %s", analyzer.__name__) try: mycfg = dict(request.configuration[analyzer.__name__]) except (KeyError, ValueError): mycfg = {} model = analyzer.train(ptr, mycfg, self._data_service.get()) self._model_repository.set(self._model_id(analyzer), ptr.url, model) response = EventResponse() response.analyzer_version = self.version return response
def process_review_event( self, request: ReviewEvent) -> EventResponse: # noqa: D401 """ Callback for review events invoked by EventListener. """ base_ptr = ReferencePointer.from_pb(request.commit_revision.base) head_ptr = ReferencePointer.from_pb(request.commit_revision.head) response = EventResponse() response.analyzer_version = self.version comments = [] for analyzer in self._analyzers: try: mycfg = self._protobuf_struct_to_dict( request.configuration[analyzer.name]) self._log.info("%s config: %s", analyzer.name, mycfg) except (KeyError, ValueError): mycfg = {} self._log.debug("no config was provided for %s", analyzer.name) if analyzer.model_type != DummyAnalyzerModel: model = self._get_model(analyzer, base_ptr.url) if model is None: self._log.info("training: %s", analyzer.name) record_event("%s.train" % analyzer.name, 1) model = analyzer.train(base_ptr, mycfg, self._data_service) self._model_repository.set(self._model_id(analyzer), base_ptr.url, model) else: model = DummyAnalyzerModel() self._log.debug("running %s", analyzer.name) record_event("%s.analyze" % analyzer.name, 1) results = analyzer(model, head_ptr.url, mycfg).analyze(base_ptr, head_ptr, self._data_service) self._log.info("%s: %d comments", analyzer.name, len(results)) record_event("%s.comments" % analyzer.name, len(results)) comments.extend(results) response.comments.extend(comments) return response
def wrapped_catch_them_all(self, request, context: grpc.ServicerContext): try: return func(self, request, context) except Exception as e: start_time = getattr(context, "start_time", None) if start_time is not None: delta = time.perf_counter() - start_time self._log.exception("FAIL %.3f", delta) else: self._log.exception("FAIL ?") context.set_code(grpc.StatusCode.INTERNAL) context.set_details("%s: %s" % (type(e), e)) context.error = True submit_event("error", 1) return EventResponse()
def process_push_event(self, request: PushEvent) -> EventResponse: self.setUpEvent.set() self.tearDownEvent.wait() return EventResponse()
def process_review_event(self, request: ReviewEvent) -> EventResponse: self.setUpEvent.set() self.tearDownEvent.wait() return EventResponse()
def process_push_event(self, request: PushEvent) -> EventResponse: self.request = request return EventResponse()
def process_review_event(self, request: ReviewEvent) -> EventResponse: self.request = request return EventResponse()