def _get_repos_and_revisions() -> Tuple[List[Repo], RevisionMap]: """Get the repo object and a map of revisions to compare against.""" modules = git.get_module_paths() repos = [Repo(path) for path in modules] revision_map = generate_revision_map( repos, { "mongo": os.environ.get(MONGO_REVISION_ENV_VAR), "enterprise": os.environ.get(ENTERPRISE_REVISION_ENV_VAR) }) return repos, revision_map
def create_revision_map(self, repos: List[Repo]) -> RevisionMap: """ Create a map of the repos and the given revisions to diff against. :param repos: List of repos being tracked. :return: Map of repositories and revisions to diff against. """ if self.origin_rev: return generate_revision_map(repos, {"mongo": self.origin_rev}) return {}
def test_missing_repos_are_not_returned(self): mock_repo_list = [create_mock_repo(os.getcwd())] revision_data = { "mongo": "revision1234", "enterprise": "revision56768" } revision_map = under_test.generate_revision_map( mock_repo_list, revision_data) self.assertEqual(revision_map[mock_repo_list[0].git_dir], revision_data["mongo"]) self.assertEqual(len(revision_map), 1)
def test_mongo_revisions_is_mapped_correctly(self): mock_repo_list = [ create_mock_repo(os.getcwd()), create_mock_repo("/path/to/enterprise") ] revision_data = {"mongo": "revision1234", "enterprise": "revision5678"} revision_map = under_test.generate_revision_map( mock_repo_list, revision_data) self.assertEqual(revision_map[mock_repo_list[0].git_dir], revision_data["mongo"]) self.assertEqual(revision_map[mock_repo_list[1].git_dir], revision_data["enterprise"])
def generate_revision_map_from_manifest(repos: List[Repo], task_id: str, evg_api: EvergreenApi) -> RevisionMap: """ Generate a revision map for the given repositories using the revisions from the manifest. :param repos: Repositories to generate map for. :param task_id: Id of evergreen task running. :param evg_api: Evergreen API object. :return: Map of repositories to revisions """ manifest = evg_api.manifest_for_task(task_id) revisions_data = { module_name: module.revision for module_name, module in manifest.modules.items() } revisions_data["mongo"] = manifest.revision return generate_revision_map(repos, revisions_data)
def _create_revision_map(repos: List[Repo], origin_rev: Optional[str], evg_api: EvergreenApi, task_id: Optional[str]) -> RevisionMap: """ Create a map of the repos and the given revisions to diff against. :param repos: Repositories to include in the map. :param origin_rev: User specified revision to compare against. :param evg_api: Evergreen API client. :param task_id: Evergreen task ID. :return: Map of repositories to revisions. """ if origin_rev: return generate_revision_map(repos, {"mongo": origin_rev}) if evg_api and task_id: return generate_revision_map_from_manifest(repos, task_id, evg_api) return {}