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 Jun 29, 2019
1 parent af3ec5f commit 51e9f5e
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
21 changes: 21 additions & 0 deletions bears/vcs/actions/EditCommitMessageAction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import subprocess
from coalib.results.result_actions.ResultAction import ResultAction


class EditCommitMessageAction(ResultAction):

SUCCESS_MESSAGE = 'Commit message edited successfully.'

@staticmethod
def is_applicable(result,
original_file_dict,
file_diff_dict,
applied_actions=()):
return True

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 51e9f5e

Please sign in to comment.