Commits

Takumi IINO committed 97f7726

add user-friendly message, mojibake, retry, update documents, etc

Comments (0)

Files changed (2)

     changegroup.backlog = python:backlog.hook
     
     [web]
-    baseurl = http://hgserver/...
+    baseurl = http://hgserver/... # your repository server
     
     [backloog]
     # REQUIRED ITEMS:
     spacename = demo # backlog space name
-    user      = ...  # username for login
+    username  = ...  # username for login
     password  = ...
     key       = ...  # issue key
     
 反映後ポストコミットフックが起動しBacklogの該当の課題にコメントが追記されます。
 
 コミットフックを利用する以外に`hg backlog` サブコマンドでリビジョン単位で
-実行できます。
+実行できます。(主にdebug用途です)
+
+    hg backlog .
 
 コミットコメントに特別なキーワードを含めると、該当する課題の状態を更新します。
 

backlog/__init__.py

 unbundle()
 
 import re
+import traceback
 import backloglib
 from mercurial.i18n import _
 from mercurial import patch, cmdutil, templater, util, scmutil
 
 class BacklogComment(object):
 
-    def __init__(self, ui, issue, status, content):
+    def __init__(self, ui, ctx, issue, status, content):
         self.ui = ui
+        self.ctx = ctx
         self.issue = issue
         self.status = status
         self.content = content
                         baseurl=self.ui.config('web', 'baseurl'),
                         **props)
             content = self.ui.popbuffer()
-            self.comments.append(BacklogComment(self.ui, issue, status, content))
+            self.comments.append(BacklogComment(self.ui, ctx, issue, status, content))
 
     def notify(self):
         backlog = backloglib.Backlog(self.spacename, self.username, self.password)
         for comment in self.comments:
+            self.ui.status(_('backlog: notify issue %s of changeset %s\n') %
+                           (comment.key(), comment.ctx))
+            retry = False
             if (comment.need_switch_status()):
-                backlog.switch_status({
-                    "key": comment.key(),
-                    "statusId": comment.status,
-                    "assignerId": None,
-                    "resolutionId": None,
-                    "comment": comment.content,
-                })
-            else:
-                backlog.add_comment({
-                    "key": comment.key(),
-                    "content": comment.content,
-                })
+                try:
+                    backlog.switch_status({
+                        "key": comment.key(),
+                        "statusId": comment.status,
+                        "assignerId": None,
+                        "resolutionId": None,
+                        "comment": comment.content.decode('utf-8'),
+                    })
+                except:
+                    retry = True
+            if (not comment.need_switch_status() or retry):
+                try:
+                    backlog.add_comment({
+                        "key": comment.key(),
+                        "content": comment.content.decode('utf-8'),
+                    })
+                except:
+                    self.ui.warn(_('backlog: failure notify issue %s of changeset %s\n') %
+                                 (comment.key(), comment.ctx))
 
 @command('backlog',
     [],