Skip to content

Commit

Permalink
Refact revision
Browse files Browse the repository at this point in the history
  • Loading branch information
chrismaille committed Jun 16, 2018
1 parent 5439872 commit 907eee9
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion cabrita/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Cabrita initialization."""
__version__ = "2.0.4"
__version__ = "2.0.5"
4 changes: 2 additions & 2 deletions cabrita/components/box.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,11 +246,11 @@ def _get_headers(self) -> List[str]:
"""
table_header = ['Service', 'Status']
if self.show_revision:
table_header += ['Revision']
table_header += ['Commit']
if self.port_view == PortView.column:
table_header += ['Port']
if self.show_git:
table_header += ['Git']
table_header += ['Branch']
if self.categories:
table_header += self.categories
return table_header
Expand Down
7 changes: 4 additions & 3 deletions cabrita/components/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,10 @@ def inspect(self, service: str) -> None:
text_style = result_list[0][1]
text_theme = result_list[0][2]
else:
service_status = "{} x{}".format(
Counter([result[0] for result in result_list]).most_common()[0][0],
len(result_list)
stats = Counter([result[0] for result in result_list]).most_common()[0][0]
service_status = "{}{}".format(
stats,
" x{}".format(len(result_list)) if 'exited' not in stats.lower() else ""
)
text_style = Counter([result[1] for result in result_list]).most_common()[0][0]
text_theme = Counter([result[2] for result in result_list]).most_common()[0][0]
Expand Down
8 changes: 6 additions & 2 deletions cabrita/components/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,12 @@ def get_git_revision_from_path(self, path, show_branch: bool = False) -> str:
git_commit_data = "⑂ {}@{}".format(git_branch, str(git_hash).replace('\n', ''))
else:
git_commit_data = "⑂ {}".format(str(git_hash).replace('\n', ''))
git_status = u"✎ {} {}".format(
str(git_tag).replace('\n', '')[:10], git_commit_data) if git_tag else git_commit_data

if git_tag:
git_status = u"✎ {}".format(str(git_tag).replace('\n', '')[:15])
else:
git_status = git_commit_data

return git_status

def get_git_revision(self, service):
Expand Down
4 changes: 2 additions & 2 deletions cabrita/tests/test_box.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_add_service(self):

def test__get_headers(self):
test_headers = self.box._get_headers()
self.assertListEqual(test_headers, ['Service', 'Status', 'Revision', 'Port', 'Git', 'Worker'])
self.assertListEqual(test_headers, ['Service', 'Status', 'Commit', 'Port', 'Branch', 'Worker'])

def test__append_ports_in_field(self):
self.box.run()
Expand All @@ -148,7 +148,7 @@ def test__append_ports_in_field(self):

def test_run(self):
test_result = \
"Service Status Revision Port Git Worker\n" \
"Service Status Commit Port Branch Worker\n" \
"------------- -------- ------------ ------ ----------- --------\n" \
"django-worker Running  " \
"Using Image ↘ 8085 Using Image Running"
Expand Down
4 changes: 2 additions & 2 deletions cabrita/tests/test_gitInspect.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ def setUpClass(cls):
def test_get_git_revision_from_path(self, *mocks):
self.git.run = mocks[0]
test_string = self.git.get_git_revision_from_path(path='/', show_branch=True)
self.assertEqual(test_string, u'✎ 2.0.1 ⑂ develop@457ac8c')
self.assertEqual(test_string, u'✎ 2.0.1')

@mock.patch('cabrita.abc.utils.run_command', side_effect=return_git_result)
def test_get_git_revision(self, *mocks):
self.git.run = mocks[0]
test_revision = self.git.get_git_revision('django')
self.assertEqual(test_revision, u'✎ 2.0.1 ⑂ 457ac8c')
self.assertEqual(test_revision, u'✎ 2.0.1')

@mock.patch('os.path.isdir', return_value=True)
@mock.patch('cabrita.abc.utils.run_command', side_effect=return_git_result)
Expand Down

0 comments on commit 907eee9

Please sign in to comment.