Exemplo n.º 1
0
def CountRecentCommits(repo_url,
                       ref='refs/heads/master',
                       time_period=datetime.timedelta(hours=1)):
    """Gets the number of commits that landed recently.

  By default, this function will count the commits landed in the master ref
  during last hour, but can be used to count the commits landed in any ref in
  the most recent period of any arbitrary size.

  Args:
    repo_url (str): Url to the repo.
    ref (str): ref to count commits on.
    time_period (datetime.delta): window of time in which to count commits.

  Returns:
    An integer representing the number of commits that landed in the last
    hour.
  """
    count = 0
    cutoff = time_util.GetUTCNow() - time_period
    git_repo = NonCachedGitilesRepository(FinditHttpClient(), repo_url, ref)
    next_rev = ref
    while next_rev:
        # 100 is a reasonable size for a page.
        # This assumes that GetNChangeLogs returns changelogs in newer to older
        # order.
        logs, next_rev = git_repo.GetNChangeLogs(next_rev, 100)
        for log in logs:
            if log.committer.time >= cutoff:
                count += 1
            else:
                return count
    return count
Exemplo n.º 2
0
  def GetMockPredatorApp(self, get_repository=None, config=None,
                         client_id=CrashClient.FRACAS):
    get_repository = (get_repository or
                      GitilesRepository.Factory(self.GetMockHttpClient()))
    config = config or CrashConfig.Get()

    class MockPredatorApp(PredatorApp):  # pylint: disable=W0223
      """Overwrite abstract method of PredatorApp for testing."""
      def __init__(self):
        super(MockPredatorApp, self).__init__(get_repository, config)

      @classmethod
      def _ClientID(cls):
        return client_id

      def ProcessResultForPublishing(self, result, key): # pylint: disable=W0613
        return result

      def GetCrashData(self, crash_data):

        class MockCrashData(CrashData):
          @property
          def regression_range(self):
            return crash_data.get('regression_range')

          @property
          def stacktrace(self):
            return None

          @property
          def dependencies(self):
            return {}

          @property
          def dependency_rolls(self):
            return {}

          @property
          def identifiers(self):
            return crash_data.get('crash_identifiers')

        return MockCrashData(crash_data)

      def GetAnalysis(self, crash_identifiers):
        return MockCrashAnalysis.Get(crash_identifiers)

      def CreateAnalysis(self, crash_identifiers):
        return MockCrashAnalysis.Create(crash_identifiers)

      def _Predator(self):
        return Predator(MockChangelistClassifier(get_repository, None, None),
                        self._component_classifier,
                        self._project_classifier)

    mock_predator = MockPredatorApp()
    mock_predator.SetLog(self.GetMockLog())
    return mock_predator
 def setUp(self):
     super(TouchCrashedFileMetaFeatureTest, self).setUp()
     get_repository = GitilesRepository.Factory(self.GetMockHttpClient())
     min_distance_feature = MinDistanceFeature(get_repository)
     top_frame_index_feature = TopFrameIndexFeature()
     touch_crashed_file_feature = TouchCrashedFileFeature()
     self._feature = TouchCrashedFileMetaFeature([
         min_distance_feature, top_frame_index_feature,
         touch_crashed_file_feature
     ])
    def testFindCulprit(self):
        self.mock(FinditForChromeCrash, 'FindCulprit', lambda self, *_: None)

        # TODO(wrengr): would be less fragile to call
        # FinditForFracas.CreateAnalysis instead; though if I'm right about
        # the original purpose of this test, then this is one of the few
        # places where calling FracasCrashAnalysis directly would actually
        # make sense.
        analysis = FracasCrashAnalysis.Create({'signature': 'sig'})
        findit_client = _FinditForChromeCrash(
            GitilesRepository.Factory(HttpClientAppengine()),
            CrashConfig.Get())
        self.assertIsNone(findit_client.FindCulprit(analysis))
Exemplo n.º 5
0
    def testFindCulprit(self, mock_find_culprit):
        mock_find_culprit.return_value = None

        # TODO(wrengr): would be less fragile to call
        # PredatorForFracas.CreateAnalysis instead; though if I'm right about
        # the original purpose of this test, then this is one of the few
        # places where calling FracasCrashAnalysis directly would actually
        # make sense.
        analysis = FracasCrashAnalysis.Create({'signature': 'sig'})
        predator_client = _PredatorForChromeCrash(
            GitilesRepository.Factory(HttpClientAppengine()),
            CrashConfig.Get())
        self.assertIsNone(predator_client.FindCulprit(analysis))
    def setUp(self):
        super(ChangelistClassifierTest, self).setUp()
        meta_weight = MetaWeight({
            'TouchCrashedFileMeta':
            MetaWeight({
                'MinDistance': Weight(1.),
                'TopFrameIndex': Weight(1.),
                'TouchCrashedFile': Weight(1.),
            })
        })
        get_repository = GitilesRepository.Factory(self.GetMockHttpClient())
        meta_feature = WrapperMetaFeature(
            [TouchCrashedFileMetaFeature(get_repository)])

        self.changelist_classifier = ChangelistClassifier(
            get_repository, meta_feature, meta_weight)
Exemplo n.º 7
0
    def GetMockFindit(self,
                      get_repository=None,
                      config=None,
                      client_id='mock_client'):
        get_repository = (get_repository or GitilesRepository.Factory(
            self.GetMockHttpClient()))
        config = config or CrashConfig.Get()

        class MockFindit(Findit):  # pylint: disable=W0223
            """Overwrite abstract method of Findit for testing."""
            def __init__(self):
                super(MockFindit, self).__init__(get_repository, config)

            @classmethod
            def _ClientID(cls):
                return client_id

            def ProcessResultForPublishing(self, result, key):  # pylint: disable=W0613
                return result

            def GetCrashData(self, crash_data):
                class MockCrashData(CrashData):
                    @property
                    def regression_range(self):
                        return crash_data.get('regression_range')

                    @property
                    def stacktrace(self):
                        return None

                    @property
                    def dependencies(self):
                        return {}

                    @property
                    def dependency_rolls(self):
                        return {}

                return MockCrashData(crash_data)

            def GetAnalysis(self, crash_identifiers):
                return CrashAnalysis.Get(crash_identifiers)

            def CreateAnalysis(self, crash_identifiers):
                return CrashAnalysis.Create(crash_identifiers)

        return MockFindit()
Exemplo n.º 8
0
 def GetMockRepoFactory(self, response_for_url=None):
     """Returns mocked repository factory."""
     return GitilesRepository.Factory(
         self.GetMockHttpClient(response_for_url or {}))
Exemplo n.º 9
0
 def setUp(self):
     super(MinDistanceTest, self).setUp()
     self._get_repository = GitilesRepository.Factory(
         self.GetMockHttpClient())
Exemplo n.º 10
0
 def setUp(self):
     super(TouchCrashedFileMetaFeatureTest, self).setUp()
     get_repository = GitilesRepository.Factory(self.GetMockHttpClient())
     self._feature = TouchCrashedFileMetaFeature(get_repository)