Skip to content

Commit

Permalink
EditCommitMessageAction: New action
Browse files Browse the repository at this point in the history
A new action for GitCommitBear when applied
opens up a editor for user to edit commit
message of the HEAD commit.
  • Loading branch information
akshatkarani committed Jul 21, 2019
1 parent cfc8ca3 commit 26fad10
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bears/vcs/actions/EditCommitMessageAction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import subprocess
from coalib.results.result_actions.ResultAction import ResultAction


class EditCommitMessageAction(ResultAction):

SUCCESS_MESSAGE = 'Commit message edited successfully.'

def apply(self, result, original_file_dict, file_diff_dict):
"""
Edit (C)ommit Message [Note: This may rewrite your commit history]
"""
subprocess.check_call(['git', 'commit', '-o', '--amend'])
return file_diff_dict
24 changes: 24 additions & 0 deletions tests/vcs/actions/EditCommitMessageActionTest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import unittest
from unittest.mock import patch
from coala_utils.ContextManagers import retrieve_stdout
from coalib.results.Result import Result
from bears.vcs.actions.EditCommitMessageAction import EditCommitMessageAction


class EditCommitMessageActionTest(unittest.TestCase):

def setUp(self):
self.uut = EditCommitMessageAction()
self.result = Result('origin', 'message')

def test_is_applicable(self):
self.assertTrue(self.uut.is_applicable(self.result, {}, {}))

def test_apply(self):
with retrieve_stdout() as stdout:
patcher = ('bears.vcs.actions.EditCommitMessageAction.'
'subprocess.check_call')
with patch(patcher):
ret = self.uut.apply(self.result, {}, {'file': 'diff'})
self.assertEqual(ret, {'file': 'diff'})
self.assertEqual(stdout.getvalue(), '')

0 comments on commit 26fad10

Please sign in to comment.