Skip to content

Commit

Permalink
Add local repo positional argument (#15)
Browse files Browse the repository at this point in the history
  • Loading branch information
alfinkel authored Sep 2, 2020
1 parent 59a254e commit 8f37ac0
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# 1.1.0

[NEW] "local" `repo` positional argument option is now valid bypassing remote validation.

# 1.0.0

[NEW] Make the Auditree Harvest tool public.
2 changes: 1 addition & 1 deletion harvest/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
# limitations under the License.
"""The Auditree file collating and reporting tool."""

__version__ = '1.0.0'
__version__ = '1.1.0'
10 changes: 8 additions & 2 deletions harvest/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,15 @@ def _init_arguments(self):
'repo',
help=(
'the URL to the repository containing files to be processed '
'by harvest, as an example https://github.com/my-org/my-repo'
'by harvest, as an example: https://github.com/my-org/my-repo '
'or: local - if working exclusively with a local git repo'
)
)
self.add_argument(
'--repo-path',
help=(
'the operating system location of a local git repository - '
'if not provided, repo will be cloned to $TMPDIR/harvest'
'if not provided, repo path is assumed to be $TMPDIR/harvest'
),
metavar='~/path/git-repo',
default=None
Expand All @@ -65,6 +66,11 @@ def _init_arguments(self):
)

def _validate_arguments(self, args):
if args.repo == 'local':
if not args.repo_path:
return 'ERROR: --repo-path expected for "local" mode'
args.repo = 'https://local/local/local'
args.no_validate = False
parsed = urlparse(args.repo)
if not (parsed.scheme and parsed.hostname and parsed.path):
return (
Expand Down
23 changes: 23 additions & 0 deletions test/test_cli_collate.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,26 @@ def test_collate_future_end(self, mock_read, mock_write):
)
mock_read.assert_not_called()
mock_write.assert_not_called()

@patch('harvest.collator.Collator.write')
@patch('harvest.collator.Collator.read')
def test_collate_local(self, mock_read, mock_write):
"""Ensures collate sub-command works when 'local' repo provided."""
mock_read.return_value = ['commit-foo']
self.harvest.run(
[
'collate',
'local',
'my/path/baz.json',
'--repo-path',
'os/repo/path'
]
)
today = datetime.today()

mock_read.assert_called_once_with(
'my/path/baz.json',
datetime(today.year, today.month, today.day),
datetime(today.year, today.month, today.day)
)
mock_write.assert_called_once_with('my/path/baz.json', ['commit-foo'])

0 comments on commit 8f37ac0

Please sign in to comment.