OLD | NEW |
| (Empty) |
1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
2 # Use of this source code is governed by a BSD-style license that can be | |
3 # found in the LICENSE file. | |
4 | |
5 import json | |
6 import urllib2 | |
7 | |
8 BASE_URL = 'https://chromium.googlesource.com/chromium/src/+' | |
9 PADDING = ')]}\'\n' # Gitiles padding. | |
10 | |
11 def revision_info(revision): | |
12 """Gets information about a chromium revision. | |
13 | |
14 Args: | |
15 revision (str): The git commit hash of the revision to check. | |
16 | |
17 Returns: | |
18 A dictionary containing the author, email, 'subject' (the first line of the | |
19 commit message) the 'body' (the whole message) and the date in string format | |
20 like "Sat Oct 24 00:33:21 2015". | |
21 """ | |
22 | |
23 url = '%s/%s?format=json' % (BASE_URL, revision) | |
24 response = urllib2.urlopen(url).read() | |
25 response = json.loads(response[len(PADDING):]) | |
26 message = response['message'].splitlines() | |
27 subject = message[0] | |
28 body = '\n'.join(message[1:]) | |
29 result = { | |
30 'author': response['author']['name'], | |
31 'email': response['author']['email'], | |
32 'subject': subject, | |
33 'body': body, | |
34 'date': response['committer']['time'], | |
35 } | |
36 return result | |
37 | |
38 | |
39 def revision_range(first_revision, last_revision): | |
40 """Gets the revisions in chromium between first and last including the latter. | |
41 | |
42 Args: | |
43 first_revision (str): The git commit of the first revision in the range. | |
44 last_revision (str): The git commit of the last revision in the range. | |
45 | |
46 Returns: | |
47 A list of dictionaries, one for each revision after the first revision up to | |
48 and including the last revision. For each revision, its dictionary will | |
49 contain information about the author and the comitter and the commit itself | |
50 analogously to the 'git log' command. See test_data/MOCK_RANGE_RESPONSE_FILE | |
51 for an example. | |
52 """ | |
53 url = '%slog/%s..%s?format=json' % (BASE_URL, first_revision, last_revision) | |
54 response = urllib2.urlopen(url).read() | |
55 response = json.loads(response[len(PADDING):]) | |
56 return response['log'] | |
OLD | NEW |