Skip to content

Commit

Permalink
Merge branch 'release-3.0.x' into release-4.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
davidt committed Oct 26, 2020
2 parents 6fafb89 + 5f34cfe commit b960ee6
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions reviewboard/notifications/webhooks.py
Expand Up @@ -3,6 +3,7 @@
import hashlib
import hmac
import logging
from base64 import b64encode
from collections import OrderedDict
from datetime import datetime

Expand All @@ -14,13 +15,10 @@
from django.utils import six
from django.utils.encoding import force_bytes, force_text
from django.utils.safestring import SafeText
from django.utils.six.moves.urllib.error import HTTPError
from django.utils.six.moves.urllib.parse import (urlencode, urlsplit,
urlunsplit)
from django.utils.six.moves.urllib.request import (
HTTPBasicAuthHandler,
HTTPPasswordMgrWithDefaultRealm,
Request,
build_opener)
from django.utils.six.moves.urllib.request import Request, urlopen
from django.utils.text import get_text_list
from django.utils.translation import ugettext as _
from django.template import Context, Template
Expand Down Expand Up @@ -396,24 +394,22 @@ def dispatch_webhook_event(request, webhook_targets, event, payload):
url_parts = urlsplit(url)

if url_parts.username or url_parts.password:
netloc = url_parts.netloc.split('@', 1)[1]
credentials, netloc = url_parts.netloc.split('@', 1)
url = urlunsplit(
(url_parts.scheme, netloc, url_parts.path,
url_parts.params, url_parts.query))
url_parts.query, url_parts.fragment))
headers[b'Authorization'] = \
b'Basic %s' % b64encode(credentials.encode('utf-8'))

password_mgr = HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(
None, url, url_parts.username, url_parts.password)
handler = HTTPBasicAuthHandler(password_mgr)
opener = build_opener(handler)
else:
opener = build_opener()

opener.open(Request(url, body, headers))
urlopen(Request(url.encode('utf-8'), body, headers))
except Exception as e:
logging.exception('Could not dispatch WebHook to %s: %s',
webhook_target.url, e)

if isinstance(e, HTTPError):
logging.info('Error response from %s: %s %s\n%s',
webhook_target.url, e.code, e.reason, e.read())


def _serialize_review(review, request):
return {
Expand Down

0 comments on commit b960ee6

Please sign in to comment.