Skip to content

Commit ac16508

Browse files
committedJun 1, 2018
Send changeset URLs along with sentry and log data
Also add a test to exercise our new code.
1 parent fc6c989 commit ac16508

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed
 

‎committelemetry/pulse.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import socket
1111
from contextlib import closing
1212
from functools import partial
13+
from typing import List
1314

1415
from kombu import Connection, Exchange, Queue
1516

@@ -25,7 +26,7 @@ def noop(*args, **kwargs):
2526
return None
2627

2728

28-
def changesets_for_pushid(pushid, push_json_url):
29+
def changesets_for_pushid(pushid: int, push_json_url: str) -> List[str]:
2930
"""Return a list of changeset IDs in a repository push.
3031
3132
Reads data published by the Mozilla hgweb pushlog extension.
@@ -104,8 +105,15 @@ def process_push_message(body, message, no_send=False):
104105
for changeset in changesets_for_pushid(
105106
pushdata['pushid'], pushdata['push_json_url']
106107
):
107-
log.info(f'processing changeset {changeset}')
108-
sentry.extra_context({'changeset': changeset})
108+
changeset_url = f'{repo_url}/rev/{changeset}'
109+
log.info(f'processing changeset {changeset}: {changeset_url}')
110+
sentry.extra_context(
111+
{
112+
'changeset': changeset,
113+
'changeset URL': changeset_url
114+
}
115+
)
116+
109117
ping = payload_for_changeset(changeset, repo_url)
110118

111119
if no_send:

‎tests/test_process_hgpush.py

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# This Source Code Form is subject to the terms of the Mozilla Public
2+
# License, v. 2.0. If a copy of the MPL was not distributed with this
3+
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
4+
"""
5+
Test the hgpush message processing code.
6+
"""
7+
8+
from unittest.mock import MagicMock, patch
9+
10+
import pytest
11+
12+
pytestmark = pytest.mark.usefixtures('null_config')
13+
14+
15+
# This structure is described here:
16+
# https://mozilla-version-control-tools.readthedocs.io/en/latest/hgmo/notifications.html#common-properties-of-notifications
17+
# Example messages can be collected from this URL:
18+
# https://tools.taskcluster.net/pulse-inspector?bindings[0][exchange]=exchange%2Fhgpushes%2Fv2&bindings[0][routingKeyPattern]=%23
19+
test_message = {
20+
'payload': {
21+
'type': 'changegroup.1',
22+
'data': {
23+
'pushlog_pushes': [
24+
{
25+
'time': 15278721560,
26+
'pushid': 64752,
27+
'push_json_url': 'https://hg.mozilla.org/integration/autoland/json-pushes?version=2&startID=64751&endID=64752',
28+
'push_full_json_url': 'https://hg.mozilla.org/integration/autoland/json-pushes?version=2&full=1&startID=64751&endID=64752',
29+
'user': 'someuser@mozilla.org',
30+
}
31+
],
32+
'heads': [
33+
'ebe99842f5f8d543e5453ce78b1eae3641830b13',
34+
],
35+
'repo_url': 'https://hg.mozilla.org/integration/autoland',
36+
},
37+
},
38+
} # yapf: disable
39+
40+
def test_process_push_message():
41+
from committelemetry.pulse import process_push_message
42+
43+
with patch('committelemetry.pulse.send_ping') as send_ping, \
44+
patch('committelemetry.pulse.payload_for_changeset'), \
45+
patch('committelemetry.pulse.changesets_for_pushid') as changesets_for_pushid:
46+
changesets_for_pushid.return_value = ['ab1cd2']
47+
48+
process_push_message(test_message, MagicMock())
49+
50+
send_ping.assert_called_once()
51+
52+

0 commit comments

Comments
 (0)
Failed to load comments.