[damned-lies] Fix commit action when noone has full name



commit a259ef6144eb6eca49b99423354e2a10cc1d8074
Author: Claude Paroz <claude 2xlibre net>
Date:   Thu Sep 18 11:04:12 2014 +0200

    Fix commit action when noone has full name

 stats/models.py         |    7 ++++---
 vertimus/forms.py       |    1 -
 vertimus/models.py      |    4 +++-
 vertimus/tests/tests.py |   26 +++++++++++++++++++++++---
 4 files changed, 30 insertions(+), 8 deletions(-)
---
diff --git a/stats/models.py b/stats/models.py
index 00beaba..ac41f23 100644
--- a/stats/models.py
+++ b/stats/models.py
@@ -703,9 +703,10 @@ class Branch(models.Model):
                             "cd \"%(dest)s\" && git add %(lg_file)s" % var_dict, raise_on_error=True)
                     var_dict['msg'] = "Added %s translation" % language.name
                 # git commit -m "Updated %s translation."
-                utils.run_shell_command(
-                    "cd \"%(dest)s\" && git commit -m \"%(msg)s\" --author \"%(author)s\"" % var_dict,
-                    raise_on_error=True)
+                commit_cmd = "cd \"%(dest)s\" && git commit -m \"%(msg)s\""
+                if author:
+                    commit_cmd += " --author \"%(author)s\""
+                utils.run_shell_command(commit_cmd % var_dict, raise_on_error=True)
                 # git push
                 try:
                     utils.run_shell_command(
diff --git a/vertimus/forms.py b/vertimus/forms.py
index 918b293..25b85bd 100644
--- a/vertimus/forms.py
+++ b/vertimus/forms.py
@@ -82,7 +82,6 @@ class ActionForm(forms.Form):
         self.fields['action'].help_link = reverse('help', args=['vertimus_workflow'])
         if state and ActionCI in map(type, self.actions):
             self.fields['author'].queryset = state.involved_persons()
-            self.fields['author'].required = True
             self.fields['author'].initial = state.get_latest_po_file_action().person
         if not has_mailing_list:
             del self.fields['send_to_ml']
diff --git a/vertimus/models.py b/vertimus/models.py
index ae2884b..0816431 100644
--- a/vertimus/models.py
+++ b/vertimus/models.py
@@ -627,7 +627,9 @@ class ActionCI(Action):
         self.state_db = state
         action_with_po = self.get_previous_action_with_po()
         try:
-            state.branch.commit_po(action_with_po.file.path, state.domain, state.language, 
form_data['author'].as_author())
+            author = form_data['author'].as_author() if form_data['author'] else None
+            state.branch.commit_po(
+                action_with_po.file.path, state.domain, state.language, author)
         except:
             # Commit failed, state unchanged
             raise Exception(_("The commit failed. The error was: '%s'") % sys.exc_info()[1])
diff --git a/vertimus/tests/tests.py b/vertimus/tests/tests.py
index cf1edd0..16472a1 100644
--- a/vertimus/tests/tests.py
+++ b/vertimus/tests/tests.py
@@ -29,7 +29,7 @@ from django.utils.datastructures import MultiValueDict
 
 from teams.tests import TeamsAndRolesTests
 from stats.models import Module, Branch, Release, Category, Domain, Statistics
-from stats.tests import test_scratchdir
+from stats.tests import patch_shell_command, test_scratchdir
 from vertimus.models import *
 from vertimus.forms import ActionForm
 
@@ -66,11 +66,11 @@ class VertimusTest(TeamsAndRolesTests):
             if os.path.exists(path):
                 os.remove(path)
 
-    def upload_file(self, to_state, action_code='UP'):
+    def upload_file(self, to_state, action_code='UP', pers=None):
         """ Test utility to add an uploaded file to a state """
         test_file = ContentFile('test content')
         test_file.name = 'mytestfile.po'
-        action = Action.new_by_name(action_code, person=self.pr, comment="Done.", file=test_file)
+        action = Action.new_by_name(action_code, person=pers or self.pr, comment="Done.", file=test_file)
         action.apply_on(to_state, {'send_to_ml': action.send_mail_to_ml})
         self.files_to_clean.append(action.file.path)
         return action.file
@@ -356,6 +356,26 @@ class VertimusTest(TeamsAndRolesTests):
         self.assertIn('<option value="%d">John Translator</option>' % self.pt.pk,
                       rendered_form)
 
+    def test_action_ci_no_fullname(self):
+        """
+        Test that a commit works even when nobody has full name, but without --author flag.
+        """
+        pers = Person.objects.create(email='user example org', username='username_only')
+        Role.objects.create(team=self.t, person=pers, role='reviewer')
+        self.b.module.vcs_root = self.b.module.vcs_root.replace('git://', 'ssh://')
+        self.b.module.save()
+        state = StateProofreading(branch=self.b, domain=self.d, language=self.l, person=pers)
+        state.save()
+        self.upload_file(state, 'UP', pers=pers)
+        form = ActionForm(state, state.get_available_actions(self.pcoo), True, {'action': 'CI', 'author': 
''})
+        self.assertTrue(form.is_valid())
+        with patch_shell_command() as cmds:
+            action = Action.new_by_name('CI', person=self.pcoo, comment='')
+            action.apply_on(state, form.cleaned_data)
+            self.assertIn("git commit", cmds[-2])
+            self.assertNotIn("--author", cmds[-2])
+
+
     def test_action_ic(self):
         state = StateProofreading(branch=self.b, domain=self.d, language=self.l, person=self.pr)
         state.save()


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]