pythonã§Redmineã®ãã±ãããèªåã§ã¤ããï¼
æè¿Redmineã®ãã±ãããçæããpythonã®ã¹ã¯ãªãããã¤ãã£ã¦ããã®ã§ãããæ®å¿µãªããå
¬å¼ã®ãµã¤ããªã©ã®ãµã³ãã«ããã¾ãå
å®ãã¦ãã¾ããã§ããã
ã¨ãããã¨ã§ããã£ãããªã®ã§ãµã³ãã«ã¨ãã¦ç§ã®ä½ã£ãã¹ã¯ãªãããè¼ãã¦ããã¾ããå
¬å¼ã®REST APIã使ã£ã¦ãXMLãPOSTãã¦ãã¾ãã
ãã±ãããpythonã®ã¹ã¯ãªããã§ã¤ãããããã«ãªãã¨ãä¾ãã°ãªãã¸ããªã¸ã®ã³ãããæã«ããã¯ãã¦ä»éãããã±ãããçæãããªã©ããã±ãããã¤ãã³ãã«å¯¾ãã¦èªåã§çæãããã¨ãã§ããããã«ãªããã¨ã¦ã便å©ã§ãã
# -*- coding:utf-8 -*- from xml.etree.ElementTree import Element, SubElement, Comment import xml.etree.ElementTree as ET import xml.dom.minidom as minidom import urllib2 if __name__ == '__main__': issue = Element('issue') project_id = SubElement(issue, 'project_id') project_id.text = '5' subject = SubElement(issue, 'subject') subject.text = 'TEST TICKET' tracker_id = SubElement(issue, 'tracker_id') tracker_id.text = '2' priority = SubElement(issue, 'priority') priority.text = '4' priority = SubElement(issue, 'assigned_to_id') priority.text = '3' custom_fields = SubElement(issue, 'custom_fields', {'type':'array'}) custom_field_1 = SubElement(custom_fields, 'custom_field', {'id':'1'}) custom_field_value_1 = SubElement(custom_field_1, 'value') custom_field_value_1.text = 'A' watcher_user_ids = SubElement(issue, 'watcher_user_ids', {'type':'array'}) watcher_user_id_1 = SubElement(watcher_user_ids, 'watcher_user_id') watcher_user_id_1.text = '4' watcher_user_id_2 = SubElement(watcher_user_ids, 'watcher_user_id') watcher_user_id_2.text = '3' string = ET.tostring(issue, 'utf-8') pretty_string = minidom.parseString(string).toprettyxml(indent=' ', encoding="utf-8") # API key api_key = '***' # Redmine URL url = 'http://localhost/redmine/issues.xml' # POST request = urllib2.Request(url, data=pretty_string) request.add_header('Content-Type', 'text/xml') request.add_header('X-Redmine-API-Key', api_key) request.get_method = lambda: 'POST' response = urllib2.urlopen(request) ret = response.read() #print(ret)
(API Reference)
www.redmine.org
ã§ã¯ã§ã¯ã