Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Changelog
in development
--------------

Changed
~~~~~~~

* Install pack with the latest tag version if it exists when branch is not specialized.
(improvement) #4743

Fixed
~~~~~

Expand Down
43 changes: 42 additions & 1 deletion contrib/packs/tests/test_action_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,22 @@ def mock_is_dir_func(path):
return original_is_dir_func(path)


def mock_get_gitref(repo, ref):
"""
Mock get_gitref function which return mocked object if ref passed is
PACK_INDEX['test']['version']
"""
if PACK_INDEX['test']['version'] in ref:
if ref[0] == 'v':
return mock.MagicMock(hexsha=PACK_INDEX['test']['version'])
else:
return None
elif ref:
return mock.MagicMock(hexsha="abcDef")
else:
return None


@mock.patch.object(pack_service, 'fetch_pack_index', mock.MagicMock(return_value=(PACK_INDEX, {})))
class DownloadGitRepoActionTestCase(BaseActionTestCase):
action_cls = DownloadGitRepoAction
Expand Down Expand Up @@ -520,7 +536,7 @@ def side_effect(ref):

# Fool _get_gitref into working when its ref == our ref
def fake_commit(arg_ref):
if arg_ref == ref:
if not ref or arg_ref == ref:
return gitref
else:
raise BadName()
Expand Down Expand Up @@ -572,3 +588,28 @@ def test_run_pack_download_local_directory(self):
destination_path = os.path.join(self.repo_base, 'test4')
self.assertTrue(os.path.exists(destination_path))
self.assertTrue(os.path.exists(os.path.join(destination_path, 'pack.yaml')))

@mock.patch('st2common.util.pack_management.get_gitref', mock_get_gitref)
def test_run_pack_download_with_tag(self):
action = self.get_action_instance()
result = action.run(packs=['test'], abs_repo_base=self.repo_base)
temp_dir = hashlib.md5(PACK_INDEX['test']['repo_url'].encode()).hexdigest()

self.assertEqual(result, {'test': 'Success.'})
self.clone_from.assert_called_once_with(PACK_INDEX['test']['repo_url'],
os.path.join(os.path.expanduser('~'), temp_dir))
self.assertTrue(os.path.isfile(os.path.join(self.repo_base, 'test/pack.yaml')))

# Check repo.git.checkout is called three times
self.assertEqual(self.repo_instance.git.checkout.call_count, 3)

# Check repo.git.checkout called with latest tag or branch
self.assertEqual(PACK_INDEX['test']['version'],
self.repo_instance.git.checkout.call_args_list[1][0][0])

# Check repo.git.checkout called with head
self.assertEqual(self.repo_instance.head.reference,
self.repo_instance.git.checkout.call_args_list[2][0][0])

self.repo_instance.git.branch.assert_called_with(
'-f', self.repo_instance.head.reference, PACK_INDEX['test']['version'])
2 changes: 1 addition & 1 deletion st2common/st2common/util/pack_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def get_repo_url(pack, proxy_config=None):
if not pack:
raise Exception('No record of the "%s" pack in the index.' % (name_or_url))

return (pack['repo_url'], version)
return (pack['repo_url'], version or pack['version'])
else:
return (eval_repo_url(name_or_url), version)

Expand Down