github: edit issue

This commit is contained in:
Vincent A 2013-11-02 11:36:16 +01:00
commit f95b76e356
2 changed files with 38 additions and 8 deletions

View file

@ -83,16 +83,25 @@ class GithubBrowser(BaseBrowser):
break
def post_issue(self, issue):
base_data = self._issue_post_body(issue)
url = 'https://api.github.com/repos/%s/issues' % issue.project.id
json = self.do_post(url, base_data)
issue_number = json['id']
return self._make_issue(issue.project.id, issue_number, json)
def edit_issue(self, issue, issue_number):
base_data = self._issue_post_body(issue)
url = 'https://api.github.com/repos/%s/issues/%s' % (issue.project.id, issue_number)
self.do_patch(url, base_data)
return issue
def _issue_post_body(self, issue):
data = {'title': issue.title, 'body': issue.body}
if issue.assignee:
data['assignee'] = issue.assignee.id
if issue.version:
data['milestone'] = issue.version.id
base_data = json_module.dumps(data)
url = 'https://api.github.com/repos/%s/issues' % issue.project.id
json = self.do_post(url, base_data)
issue_number = json['id']
return self._make_issue(issue.project.id, issue_number, json)
return json_module.dumps(data)
def post_comment(self, issue_id, comment):
project_id, issue_number = issue_id.rsplit('/', 1)
@ -170,6 +179,15 @@ class GithubBrowser(BaseBrowser):
req = self.request_class(url, data, headers=headers)
return self.get_document(self.openurl(req))
def do_patch(self, url, data):
class PatchRequest(self.request_class):
def get_method(self):
return 'PATCH'
headers = self.auth_headers()
headers.update({'Accept': 'application/vnd.github.preview'})
req = PatchRequest(url, data, headers=headers)
return self.get_document(self.openurl(req))
def auth_headers(self):
if self.username:
return {'Authorization': 'Basic %s' % b64encode('%s:%s' % (self.username, self.password))}