Skip to content

Commit

Permalink
Issue #687. Abstract out comment creation into a get_comment_data met…
Browse files Browse the repository at this point in the history
…hod.
  • Loading branch information
Mike Taylor committed Sep 11, 2015
1 parent febd629 commit 4d04cae
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
13 changes: 5 additions & 8 deletions webcompat/api/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
from webcompat import cache
from webcompat import github
from webcompat import limiter
from webcompat.helpers import get_comment_data
from webcompat.helpers import get_headers
from webcompat.helpers import get_request_headers
from webcompat.helpers import get_user_info
Expand Down Expand Up @@ -219,10 +220,9 @@ def proxy_comments(number):
'''
if request.method == 'POST':
try:
comment_data = json.loads(request.data)
body = json.dumps({"body": comment_data['rawBody']})
path = 'repos/{0}/{1}/comments'.format(ISSUES_PATH, number)
comment = github.raw_request('POST', path, data=body)
comment = github.raw_request('POST', path,
data=get_comment_data(request.data))
return (json.dumps(comment.json()), comment.status_code,
{'content-type': JSON_MIME})
except GitHubError as e:
Expand All @@ -233,11 +233,8 @@ def proxy_comments(number):

if g.user:
comments = github.raw_request(
'GET',
'repos/{0}/{1}/comments'.format(
ISSUES_PATH, number),
headers=request_headers
)
'GET', 'repos/{0}/{1}/comments'.format(ISSUES_PATH, number),
headers=request_headers)
else:
comments = proxy_request('get', '/{0}/comments'.format(number),
headers=request_headers)
Expand Down
10 changes: 10 additions & 0 deletions webcompat/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

import datetime
import json
import hashlib
import math
import os
Expand Down Expand Up @@ -298,3 +299,12 @@ def format_link_header(link_header_data):
links = ['<{0}>; rel="{1}"'.format(data['link'], data['rel'])
for data in link_header_data]
return ', '.join(links)


def get_comment_data(request_data):
'''Returns a comment ready to send to GitHub.
We do this by JSON-encoding the rawBody property
of a request's data object.'''
comment_data = json.loads(request_data)
return json.dumps({"body": comment_data['rawBody']})

0 comments on commit 4d04cae

Please sign in to comment.