Advertisement
Guest User

Create an issue in Redmine using the API through Python

a guest
Jul 17th, 2012
797
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.93 KB | None | 0 0
  1. from pyactiveresource.activeresource import ActiveResource
  2.  
  3.  
  4. # site settings. Activate API access under Administration - Authentication - Enable REST web service
  5. # Get your API key on the "My account" page, in the right frame (API access key)
  6. api_key = 'YourApiKeyHere'
  7. api_site = "http://%[email protected]" % api_key
  8.  
  9.  
  10. # connect to access the projects in redmine
  11. class Project(ActiveResource):
  12.     _site = api_site
  13.  
  14. # connect to access the issues in redmine
  15. class Issue(ActiveResource):
  16.     _site = api_site
  17.  
  18.  
  19. #### general info that could be useful
  20. # attributes of an issue
  21. #{'status': None, 'due_date': None, 'description': u'Sorry if this goes out as a mail to everyone. Please ignore it :)\n\nMvh\nMartin Dahl\xf6', 'project': None, 'author': None, 'id': '42', 'priority': None, 'created_on': '2012-07-17T10:09:11+02:00', 'tracker': None, 'estimated_hours': None, 'updated_on': '2012-07-17T10:09:11+02:00', 'start_date': '2012-07-17', 'done_ratio': '0', 'subject': 'Test to see the api syntax'}
  22.  
  23.  
  24. #### general info that could be useful
  25. # dir of an issue
  26. #['__class__', '__cmp__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattr__', '__getattribute__', '__hash__', '__init__', '__metaclass__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_build_list', '_build_object', '_class_delete', '_class_get', '_class_post', '_class_put', '_collection_path', '_connection', '_custom_method_collection_url', '_custom_method_element_url', '_custom_method_new_element_url', '_element_path', '_find_class_for', '_find_every', '_find_one', '_find_single', '_format', '_headers', '_id_from_response', '_initialized', '_instance_delete', '_instance_get', '_instance_post', '_instance_put', '_password', '_plural', '_prefix', '_prefix_options', '_prefix_parameters', '_query_string', '_singular', '_site', '_split_options', '_timeout', '_update', '_user', 'attributes', 'create', 'delete', 'destroy', 'errors', 'exists', 'find', 'find_first', 'find_one', 'get', 'is_valid', 'klass', 'post', 'put', 'save', 'to_dict', 'to_xml']
  27.  
  28.  
  29.  
  30. #### general info that could be useful
  31. ### list all issues' attributes
  32. # A weird thing is that many of the important attributes of the issues are reported as None..
  33.  
  34. # get a list of all the issues
  35. #issues = Issue.find()
  36.  
  37. # go through the list of issues
  38. #for i, v in enumerate(issues):
  39.  
  40.     # print number in the loop and issue id, just to keep track
  41. #    print 'issue [',i,']',' =', v
  42.  
  43.     # print each attribute of the issue
  44. #    for item in issues[i].attributes:
  45. #       print item, " =  ", issues[i].attributes[item]
  46.  
  47.     # separator
  48. #    print '======================'
  49.  
  50.  
  51.  
  52.  
  53. #### general info that could be useful
  54. ### list all project's attributes
  55.  
  56. # get a list of all the projects
  57. #projects = Project.find()
  58.  
  59. # go through the list of projects
  60. #for i, v in enumerate(projects):
  61.  
  62.     # print number in the loop and project id, just to keep track
  63. #    print 'project [',i,']',' =', v
  64.  
  65.     # print each attribute of the project
  66. #    for item in projects[i].attributes:
  67. #       print item, " =  ", projects[i].attributes[item]
  68.  
  69.     # separator
  70. #    print '======================'
  71.  
  72.  
  73. # properties for the new issue
  74. subject = "Example"
  75. description = "This is a question body.\n\nYepp, sure is.."
  76. pid = 14 # get this by running the code above (list all project's attributes)
  77. tid = 3 # get this by looking in the overview of the project in question, in the ordinary web interface. Hover the mouse over the links to the different issue trackers you have on that project.  Ex. http://whatever.url/projects/name.of.your.project/issues?set_filter=1&tracker_id=3 where tracker_id is what you are after.
  78.  
  79.  
  80. # create the issue and save it
  81. newIssue = Issue({'subject': subject, 'project_id': pid, 'tracker_id': tid, 'description': description})
  82. newIssue.save()
  83.  
  84. # done, it should have showed up in your redmine installation now.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement