Repository: coala/coala-bears

Issue:
GitCommitBear: Check for "wip" at staart of commit message



Discussion:
Thanks for reporting this issue!

Your aid is required, fellow coalaian. Help us triage and solving this issue!

CC @sils1297, @AbdealiJK

@AbdealiJK this could be a fun 5 minute feature for this release?

I really need to get going and I still have Checkstyle, Rubicop, etc etc etc


Resolving patch:
diff --git a/bears/vcs/git/GitCommitBear.py b/bears/vcs/git/GitCommitBear.py
--- a/bears/vcs/git/GitCommitBear.py
+++ b/bears/vcs/git/GitCommitBear.py
@@ -7,6 +7,7 @@
 from coalib.misc.ContextManagers import change_directory
 from coalib.misc.Shell import run_shell_command
 from coalib.results.Result import Result
+from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
 
 
 class GitCommitBear(GlobalBear):
@@ -25,7 +26,8 @@ def run(self,
             allow_empty_commit_message: bool=False,
             shortlog_regex: str="",
             shortlog_trailing_period: bool=None,
-            shortlog_imperative_check: bool=True):
+            shortlog_imperative_check: bool=True,
+            shortlog_wip_check: bool=False):
         """
         Check the current git commit message at HEAD.
 
@@ -54,6 +56,9 @@ def run(self,
         :param shortlog_imperative_check:
             Whether an imperative check shall be applied to shortlog and
             providing ``False`` would prohibit the check.
+        :param shortlog_wip_check:
+            Whether a wip in the shortlog should yield a major result
+            or not.
         """
         with change_directory(self.get_config_dir() or os.getcwd()):
             stdout, stderr = run_shell_command("git log -1 --pretty=%B")
@@ -73,6 +78,7 @@ def run(self,
                                        shortlog_regex,
                                        shortlog_trailing_period,
                                        shortlog_imperative_check,
+                                       shortlog_wip_check,
                                        stdout[0])
         yield from self.check_body(body_line_length, force_body, stdout[1:])
 
@@ -81,6 +87,7 @@ def check_shortlog(self,
                        regex,
                        shortlog_trailing_period,
                        shortlog_imperative_check,
+                       shortlog_wip_check,
                        shortlog):
         """
         Checks the given shortlog.
@@ -92,6 +99,8 @@ def check_shortlog(self,
         :param shortlog_trailing_period: Whether a dot shall be enforced at end
                                          end or not (or ``None`` for "don't
                                          care").
+        :param shortlog_wip_check:       Whether a wip in the shortlog should
+                                         yield a major result or not.
         :param shortlog:                 The shortlog message string.
         """
         diff = len(shortlog) - shortlog_length
@@ -126,6 +135,12 @@ def check_shortlog(self,
                 yield Result(self,
                              "Shortlog of HEAD commit isn't imperative mood, "
                              "bad words are '{}'".format(bad_word))
+        if shortlog_wip_check:
+            if "wip" in shortlog.lower()[:4]:
+                yield Result(self,
+                             "This commit seems to be marked as work in "
+                             "progress and should not be used in production. "
+                             "Tread carefully.", severity=RESULT_SEVERITY.MAJOR)
 
     def check_imperative(self, paragraph):
         """


Test patch:
diff --git a/tests/vcs/git/GitCommitBearTest.py b/tests/vcs/git/GitCommitBearTest.py
--- a/tests/vcs/git/GitCommitBearTest.py
+++ b/tests/vcs/git/GitCommitBearTest.py
@@ -139,6 +139,15 @@ def test_shortlog_checks_shortlog_trailing_period(self):
         self.assertEqual(self.run_uut(shortlog_trailing_period=False), [])
         self.assertEqual(self.run_uut(shortlog_trailing_period=None), [])
 
+    def test_shortlog_wip_check(self):
+        self.git_commit("[wip] Shortlog")
+        self.assertEqual(self.run_uut(shortlog_wip_check=False), [])
+        self.assertEqual(self.run_uut(shortlog_wip_check=True),
+                         ["This commit seems to be marked as work in "
+                             "progress and should not be used in production. "
+                             "Tread carefully."])
+        self.assertEqual(self.run_uut(shortlog_wip_check=None), [])
+
     def test_shortlog_checks_imperative(self):
         self.git_commit("tag: Add shortlog in imperative")
         self.assertNotIn("Shortlog of HEAD commit isn't imperative mood, "