diff options
author | David Bradford <david.bradford@mongodb.com> | 2020-03-19 17:08:11 -0400 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2020-03-20 17:56:48 +0000 |
commit | ef6cd28bc3f39d2c7e7bb175fcbc7e83584f11c0 (patch) | |
tree | 95cfb0dba0f89c09687eaf40dd2e31df1a5137b9 /buildscripts | |
parent | 40ecb806e22bb82df5e5ed74c11f7da46bf1136c (diff) | |
download | mongo-ef6cd28bc3f39d2c7e7bb175fcbc7e83584f11c0.tar.gz |
SERVER-47004: Properly run eslint on modules
Diffstat (limited to 'buildscripts')
-rwxr-xr-x | buildscripts/eslint.py | 27 | ||||
-rw-r--r-- | buildscripts/patch_builds/change_data.py | 16 |
2 files changed, 35 insertions, 8 deletions
diff --git a/buildscripts/eslint.py b/buildscripts/eslint.py index 2a3eba272ff..220385a1e91 100755 --- a/buildscripts/eslint.py +++ b/buildscripts/eslint.py @@ -19,7 +19,7 @@ import sys import tarfile import tempfile import threading -from typing import Optional +from typing import Optional, Dict, Tuple, List import urllib.error import urllib.parse import urllib.request @@ -228,6 +228,26 @@ def lint_patch(eslint, infile): return True +def get_revision_for_repo(path: str) -> str: + """ + Get the git revision for the given git repository. + + :param path: Path to git repository. + :return: Git revision to compare against for given repo. + """ + if "enterprise" in path: + return os.environ.get("ENTERPRISE_REV") + return os.environ.get("REVISION") + + +def get_repos_and_revisions() -> Tuple[List[Repo], Dict[str, str]]: + """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 = {repo.git_dir: get_revision_for_repo(repo.git_dir) for repo in repos} + return repos, revision_map + + def lint_git_diff(eslint: Optional[str]) -> bool: """ Lint the files that have changes since the last git commit. @@ -235,8 +255,9 @@ def lint_git_diff(eslint: Optional[str]) -> bool: :param eslint: Path to eslint command. :return: True if lint was successful. """ - repos = [Repo(path) for path in git.get_module_paths()] - candidate_files = find_changed_files_in_repos(repos) + repos, revision_map = get_repos_and_revisions() + LOGGER.info("revisions", revision=revision_map) + candidate_files = find_changed_files_in_repos(repos, revision_map) LOGGER.info("Found candidate_files", candidate_files=candidate_files) files = [filename for filename in candidate_files if is_interesting_file(filename)] LOGGER.info("Found files to lint", files=files) diff --git a/buildscripts/patch_builds/change_data.py b/buildscripts/patch_builds/change_data.py index 4bfafd0db1e..636698962aa 100644 --- a/buildscripts/patch_builds/change_data.py +++ b/buildscripts/patch_builds/change_data.py @@ -1,7 +1,7 @@ """Tools for detecting changes in a commit.""" import os from itertools import chain -from typing import Any, Iterable, Set +from typing import Any, Dict, Iterable, Set, Optional import structlog from structlog.stdlib import LoggerFactory @@ -47,19 +47,23 @@ def _modified_files_for_diff(diff: DiffIndex, log: Any) -> Set: return modified_files.union(added_files).union(renamed_files).union(deleted_files) -def find_changed_files(repo: Repo) -> Set[str]: +def find_changed_files(repo: Repo, revision_map: Optional[Dict[str, str]] = None) -> Set[str]: """ Find files that were new or added to the repository between commits. :param repo: Git repository. + :param revision_map: Map of revisions to compare against for repos. :return: Set of changed files. """ + LOGGER.info("Getting diff for repo", repo=repo.git_dir) + if not revision_map: + revision_map = {} diff = repo.index.diff(None) work_tree_files = _modified_files_for_diff(diff, LOGGER.bind(diff="working tree diff")) commit = repo.index - diff = commit.diff(repo.head.commit) + diff = commit.diff(revision_map.get(repo.git_dir, repo.head.commit)) index_files = _modified_files_for_diff(diff, LOGGER.bind(diff="index diff")) untracked_files = set(repo.untracked_files) @@ -73,13 +77,15 @@ def find_changed_files(repo: Repo) -> Set[str]: ] -def find_changed_files_in_repos(repos: Iterable[Repo]) -> Set[str]: +def find_changed_files_in_repos(repos: Iterable[Repo], + revision_map: Optional[Dict[str, str]] = None) -> Set[str]: """ Find the changed files. Use git to find which files have changed in this patch. :param repos: List of repos containing changed files. + :param revision_map: Map of revisions to compare against for repos. :returns: Set of changed files. """ - return set(chain.from_iterable([find_changed_files(repo) for repo in repos])) + return set(chain.from_iterable([find_changed_files(repo, revision_map) for repo in repos])) |