Skip to content

Commit

Permalink
Added since_as_filter
Browse files Browse the repository at this point in the history
  • Loading branch information
cmtg committed Feb 19, 2023
1 parent 0805bbf commit fe503b6
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
4 changes: 3 additions & 1 deletion pydriller/repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class Repository:

def __init__(self, path_to_repo: Union[str, List[str]],
single: Optional[str] = None,
since: Optional[datetime] = None, to: Optional[datetime] = None,
since: Optional[datetime] = None, since_as_filter: Optional[datetime] = None, to: Optional[datetime] = None,
from_commit: Optional[str] = None, to_commit: Optional[str] = None,
from_tag: Optional[str] = None, to_tag: Optional[str] = None,
include_refs: bool = False,
Expand Down Expand Up @@ -76,6 +76,7 @@ def __init__(self, path_to_repo: Union[str, List[str]],
absolute paths) to the repository(ies) to analyze
:param str single: hash of a single commit to analyze
:param datetime since: starting date
:param datetime since_as_filter: starting date (scans all commits, does not stop at first commit with date < since_as_filter)
:param datetime to: ending date
:param str from_commit: starting commit (only if `since` is None)
:param str to_commit: ending commit (only if `to` is None)
Expand Down Expand Up @@ -119,6 +120,7 @@ def __init__(self, path_to_repo: Union[str, List[str]],
"from_tag": from_tag,
"to_tag": to_tag,
"since": since,
"since_as_filter": since_as_filter,
"to": to,
"single": single,
"include_refs": include_refs,
Expand Down
14 changes: 11 additions & 3 deletions pydriller/utils/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,16 @@ def _sanity_check_repos(path_to_repo: Union[str, List[str]]) -> None:

def _check_only_one_from_commit(self) -> None:
if not self.only_one_filter([self.get('since'),
self.get('since_as_filter'),
self.get('from_commit'),
self.get('from_tag')]):
raise Exception('You can only specify one filter between since, from_tag and from_commit')
raise Exception('You can only specify one filter between since, since_as_filter, from_tag and from_commit')

def _check_only_one_to_commit(self) -> None:
if not self.only_one_filter([self.get('to'),
self.get('to_commit'),
self.get('to_tag')]):
raise Exception('You can only specify one between since, from_tag and from_commit')
raise Exception('You can only specify one between to, to_tag and to_commit')

def sanity_check_filters(self) -> None:
"""
Expand All @@ -98,6 +99,7 @@ def sanity_check_filters(self) -> None:

if self.get('single') is not None:
if any([self.get('since'),
self.get('since_as_filter'),
self.get('to'),
self.get('from_commit'),
self.get('to_commit'),
Expand Down Expand Up @@ -142,7 +144,7 @@ def _is_commit_before(commit_before: Commit, commit_after: Commit) -> bool:

def get_starting_commit(self) -> Optional[List[str]]:
"""
Get the starting commit from the 'since', 'from_commit' or 'from_tag'
Get the starting commit from the 'from_commit' or 'from_tag'
filter.
"""
from_tag = self.get('from_tag')
Expand Down Expand Up @@ -199,6 +201,7 @@ def build_args(self) -> Tuple[Union[str, List[str]], Dict[str, Any]]:
"""
single: str = self.get('single')
since = self.get('since')
since_as_filter = self.get('since_as_filter')
until = self.get('to')
from_commit = self.get_starting_commit()
to_commit = self.get_ending_commit()
Expand Down Expand Up @@ -252,6 +255,9 @@ def build_args(self) -> Tuple[Union[str, List[str]], Dict[str, Any]]:
if since is not None:
kwargs['since'] = since

if since_as_filter is not None:
kwargs['since_as_filter'] = since_as_filter

if until is not None:
kwargs['until'] = until

Expand Down Expand Up @@ -290,6 +296,8 @@ def _has_modification_with_file_type(self, commit: Commit) -> bool:
def _check_timezones(self):
if self.get('since') is not None:
self.set_value('since', self._replace_timezone(self.get('since')))
if self.get('since_as_filter') is not None:
self.set_value('since_as_filter', self._replace_timezone(self.get('since_as_filter')))
if self.get('to') is not None:
self.set_value('to', self._replace_timezone(self.get('to')))

Expand Down
Binary file modified test-repos.zip
Binary file not shown.
12 changes: 12 additions & 0 deletions tests/integration/test_commit_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,18 @@ def test_filepath_with_since():
since=since).traverse_commits())) == 11


def test_since_as_filter():
since_as_filter = datetime(2018, 6, 6, 0, 0, 0, tzinfo=timezone.utc)

assert len(list(Repository(
path_to_repo='test-repos/since_as_filter',
since=since_as_filter).traverse_commits())) == 3

assert len(list(Repository(
path_to_repo='test-repos/since_as_filter',
since_as_filter=since_as_filter).traverse_commits())) == 16


def test_filepath_with_rename():
dt = datetime(2018, 6, 6)
commits = list(Repository(
Expand Down

0 comments on commit fe503b6

Please sign in to comment.