From 815b29ca9d0f517a6d282836b77332ac807f482f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Thorbj=C3=B8rn=20Lund=20Martsum?= <tmartsum@gmail.com>
Date: Wed, 10 Oct 2012 16:48:40 +0200
Subject: [PATCH] Make qdoc-bot respect work in progress
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

qdoc-bot should only provide a -1 if something can be staged.
When it is work in progress (WIP or ***) there is no risk of
it getting into Qt, so it should only provide a score of 0
and just tell what the (possible) problems are.

Otherwise it can be misread as a human -1 review to an idea.

Change-Id: Ica2b664eecf375cd0262007a423aafe379c607fd
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com>
---
 git-hooks/qdoc-bot.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/git-hooks/qdoc-bot.py b/git-hooks/qdoc-bot.py
index 9fada03..7693138 100755
--- a/git-hooks/qdoc-bot.py
+++ b/git-hooks/qdoc-bot.py
@@ -27,6 +27,7 @@ import os
 import subprocess
 import sys
 import logging
+import re
 
 config = None # configuration object, it is initialized in main and passed to every worker process created by multiprocessing.Pool
 
@@ -117,7 +118,7 @@ def remove_moved_doc_errors(fixes, errors):
         message += line + "\n "
     return message
 
-def review_output(event, output_no_patch, output_with_patch):
+def review_output(event, output_no_patch, output_with_patch, score_on_negative_review):
     try:
         import difflib
         project = event["change"]["project"]
@@ -134,10 +135,10 @@ def review_output(event, output_no_patch, output_with_patch):
         score = 0
         if new_error_count == 1:
             message += "This change introduces one new documentation error."
-            score = -1
+            score = score_on_negative_review
         elif new_error_count > 1:
             message += "This change introduces " + str(new_error_count) + " new documentation errors."
-            score = -1
+            score = score_on_negative_review
         elif new_error_count == -1:
             message += "This change removes a documentation error. Thank you!"
             score = 0
@@ -275,6 +276,11 @@ def process_event(event_string):
             cmd_git_reset = ["git", "checkout", event["patchSet"]["revision"], "-b", "tmp"]
             subprocess.check_call(cmd_git_reset)
 
+            score_on_negative_review = -1
+            header = subprocess.check_output(["git", "log", '--pretty=oneline', '-n 1'])
+            if  (re.search(r'\bWIP\b', header) or header.find('***') >= 0):
+                score_on_negative_review = 0 # Respect work in progress
+
             try:
                 output_with_patch = run_qdoc(module_name)
             except subprocess.CalledProcessError, e:
@@ -292,7 +298,7 @@ def process_event(event_string):
             output_no_patch = run_qdoc(module_name)
 
             logging.info("DONE RUNNING QDOC")
-            return review_output(event, output_no_patch, output_with_patch)
+            return review_output(event, output_no_patch, output_with_patch, score_on_negative_review)
 
         finally:
             # TODO reuse tmp dir
-- 
GitLab