Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Analyze commits only from the defined directory #109

Open
suola opened this issue Feb 7, 2020 · 4 comments
Open

Analyze commits only from the defined directory #109

suola opened this issue Feb 7, 2020 · 4 comments

Comments

@suola
Copy link

suola commented Feb 7, 2020

Assume I have a project

foo
foo/bar
foo/baz

I want to analyze only foo/baz and I run

> wily build foo/baz

Now this goes through all the commits in the git history. Would it be possible for it to go through only the commits in the foo/baz directory?

I was able to make it work for myself with the following patch, but I don't know whether this would be the right way to do such a change.

test/unit/test_cyclomatic.py ...                                                                                                                                              [ 95%]
diff --git a/src/wily/archivers/git.py b/src/wily/archivers/git.py
index ef39d8c..a1b7854 100644
--- a/src/wily/archivers/git.py
+++ b/src/wily/archivers/git.py
@@ -75,7 +75,7 @@ class GitArchiver(BaseArchiver):

         revisions = []
         for commit in self.repo.iter_commits(
-            self.current_branch, max_count=max_revisions
+            self.current_branch, path, max_count=max_revisions
         ):
             rev = Revision(
                 key=commit.name_rev.split(" ")[0],
diff --git a/src/wily/commands/build.py b/src/wily/commands/build.py
index b087f09..82bff98 100644
--- a/src/wily/commands/build.py
+++ b/src/wily/commands/build.py
@@ -68,12 +68,12 @@ def build(config, archiver, operators):
     try:
         logger.debug(f"Using {archiver.name} archiver module")
         archiver = archiver.cls(config)
-        revisions = archiver.revisions(config.path, config.max_revisions)
+        revisions = archiver.revisions(config.targets, config.max_revisions)
     except InvalidGitRepositoryError:
         # TODO: This logic shouldn't really be here (SoC)
         logger.info(f"Defaulting back to the filesystem archiver, not a valid git repo")
         archiver = FilesystemArchiver(config)
-        revisions = archiver.revisions(config.path, config.max_revisions)
+        revisions = archiver.revisions(config.targets, config.max_revisions)
     except Exception as e:
         if hasattr(e, "message"):
             logger.error(f"Failed to setup archiver: '{e.message}'")
@nagylzs
Copy link

nagylzs commented Mar 1, 2020

+1 for this. I have a project that contains frontend code (html/javascript) and backend code (python). Frontend code and node_modules also contains python files. I only want to analyze my backend code, but there is no option to do that. wily will always analyze the whole git repo, no matter what. It would be very good to have an option or setting for narrowing down to given subdirectories.

@DahlitzFlorian
Copy link
Collaborator

@suola I applied your patch locally leading to 14 failing tests. Currently, I do not have the time to investigate it further and check whether the patch makes sense, is doable and how to test it afterwards. However, I see the need for analysing only a single directory and would be happy to see this feature.

If you like and have the time, submit a PR and @ mention me so I can have a look at it.

@DahlitzFlorian
Copy link
Collaborator

Idea: Print only the commits where at least one metric does not print Not found '<path>'.

@devdanzin
Copy link
Collaborator

Idea: Print only the commits where at least one metric does not print Not found '<path>'.

This is trivial to do, and happens in #187 (from a CLI option) but it also omits lines where no changes happened. Should I make it always omit commits where all metrics print Not found '<path>' and separately allow omitting commits where no change happened?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants