Skip to content
This repository has been archived by the owner on Aug 22, 2022. It is now read-only.

Commit

Permalink
Update commit hash in instance name when setting branch to tip
Browse files Browse the repository at this point in the history
  • Loading branch information
antoviaque committed Aug 29, 2015
1 parent 058a82b commit 9d19cba
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 13 additions & 1 deletion instance/models/instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,22 @@ def set_to_branch_tip(self, branch_name=None, ref_type=None, commit=True):
if ref_type is not None:
self.ref_type = ref_type
self.log('info', 'Setting instance {} to tip of branch {}'.format(self, self.branch_name))
self.commit_id = github.get_commit_id_from_ref(
new_commit_id = github.get_commit_id_from_ref(
self.fork_name,
self.branch_name,
ref_type=self.ref_type)

if new_commit_id != self.commit_id:
old_commit_short_id = self.commit_short_id
self.commit_id = new_commit_id

# Update the hash in the instance title if it is present there
# TODO: Find a better way to handle this - include the hash dynamically?
# TODO: Figure out why the warnings aren't suppressed despite the fact that it's a mixin
if self.name and old_commit_short_id: #pylint: disable=access-member-before-definition
#pylint: disable=attribute-defined-outside-init
self.name = self.name.replace(old_commit_short_id, self.commit_short_id)

if commit:
self.save()

Expand Down
10 changes: 10 additions & 0 deletions instance/tests/models/test_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,16 @@ def test_set_to_branch_tip_extra_args(self, mock_get_commit_id_from_ref):
self.assertEqual(instance.branch_name, 'new-branch')
self.assertEqual(instance.ref_type, 'tag')

@patch('instance.models.instance.github.get_commit_id_from_ref')
def test_set_to_branch_tip_replace_commit_hash(self, mock_get_commit_id_from_ref):
"""
The hash should be updated in the instance name when updating
"""
mock_get_commit_id_from_ref.return_value = '1234567' + 'd' * 33
instance = OpenEdXInstanceFactory(commit_id='a' * 40, name='Test Instance (aaaaaaa)')
instance.set_to_branch_tip(branch_name='new-branch', ref_type='tag')
self.assertEqual(instance.name, 'Test Instance (1234567)')


class AnsibleInstanceTestCase(TestCase):
"""
Expand Down

0 comments on commit 9d19cba

Please sign in to comment.