Commits

illume committed bfc8998

Updated formatting of messages and attachment urls.

  • Participants
  • Parent commits 6f9eed5

Comments (0)

Files changed (1)

File create_issues.py

 	    status: The status of the issue (new, open, resolved, on hold, invalid, duplicate, or wontfix).
 	    kind: The kind of issue (bug, enhancement, or proposal).
 
+    $ curl -d "title=Issue%20Title&content=Issue%20Content" \
+        https://api.bitbucket.org/1.0/repositories/sarahmaddox/sarahmaddox/issues/
+
 How to delete an issue:
 	curl -X DELETE https://api.bitbucket.org/1.0/repositories/pygame/pygame/issues/3
 
 
 
 """
-import os,sys,urllib, pprint, glob, base64
+import os,sys,urllib, pprint, glob, base64, getpass
 import xml.etree.cElementTree as ElementTree
 
 
 ATTACHMENT_BASE_URL = "http://www.pygame.org/old_bug_attachments/"
+ISSUES_API_URL = "https://api.bitbucket.org/1.0/repositories/pygame/pygame/issues/"
 
 
 issue_keys = "title content component milestone version responsible status kind".split()
 		raise ValueError(":%s: kind is not one of %s" % (issue.get('kind'), valid_kind))
 
 def create_issue(issue):
-
-	validate_issue(issue)
-	# create http post data from issue
-	issue_data = urllib.urlencode(issue)
-	return issue_data
+    validate_issue(issue)
+    # create http post data from issue
+    if 0:
+        for k,v in issue.items():
+            print "k", k
+            print v
+            urllib.urlencode(dict(k=v))
+        pprint.pprint(issue)
+    issue_data = urllib.urlencode(issue)
+    return issue_data
 
 
 def test_create_issue():
 
 
 def extractInfo(bugs):
+    """ This gets information from the bugzilla bugs.
+
+        Things like all the versions used, all the components etc.
+
+        This is so you can set them up in bitbucket before you do the import.
+    """
     info = dict(bug_status = set([]), 
                 version = set([]), 
                 component= set([]), 
         content = u""
         for long_desc in bug['long_desc']:
             #pprint.pprint( long_desc )
-            c = u"%s\n%s\n\n%s\n\n\n" % (long_desc['bug_when'], 
-                                       long_desc['who']['name'], 
-                                       long_desc['thetext'])
+            c = u"\n\n"
+            c += u"== %s, %s\n\n{{{\n%s\n}}}\n\n----\n" % (long_desc['who']['name'], 
+                                                           long_desc['bug_when'],
+                                                           long_desc['thetext'])
             # we create links to attachments, since the bitbucket API can not add attachments.
-            if bug['attachment']:
+
+            if 'attachid' in long_desc:
                 c += "Attachments:\n"
                 for attachment in bug['attachment']:
-                    c += "%s\n" % ("/".join([ATTACHMENT_BASE_URL.rstrip("/"), 
-                                    attachment['attachid'], 
-                                    urllib.quote(attachment['filename'])]))
+                    if long_desc['attachid'] == attachment['attachid']:
+                        c += "[[%s| %s]]\n" % ("/".join([ATTACHMENT_BASE_URL.rstrip("/"), 
+                                        attachment['attachid'], 
+                                        urllib.quote(attachment['filename'])]), 
+                                        urllib.quote(attachment['filename']))
             content += c
+        content = content.encode('utf8')
         return content
 
     def component(self, bug):
             f.close()
 
 
+def make_create_issue_curls(issues):
+    username = "illume"
+    password = getpass.getpass("Bitbucket password:\n")
+    curl_commands = []
+    for i, issue in enumerate(issues):
+        issue_id = i -1
+
+        issue_data = create_issue(issue)
+        curl_cmd = 'curl -d "%s" %s --user %s:%s' % (issue_data, ISSUES_API_URL, username, password)
+        curl_commands.append(curl_cmd)
+    return curl_commands
+
 
 bugs = create_bugzilla_dicts()
 
 create_attachments(bugs)
 
 issues = [ ConvertBug().convert(bug) for bug_id, bug in sorted(bugs.items())]
-pprint.pprint(issues[69-1])
-print(issues[69-1]['content'])
+#pprint.pprint(issues[69-1])
+#print(issues[69-1]['content'])
 
+cmds = make_create_issue_curls(issues)
+for c in cmds:
+    print c
 
+
+