OLD | NEW |
| (Empty) |
1 # Copyright 2013 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 urlparse | |
6 | |
7 from recipe_engine import recipe_api | |
8 | |
9 | |
10 class RietveldApi(recipe_api.RecipeApi): | |
11 def calculate_issue_root(self, extra_patch_project_roots=None): | |
12 """Returns path where a patch should be applied to based on "patch_project". | |
13 | |
14 Maps Rietveld's "patch_project" to a path of directories relative to | |
15 api.gclient.c.solutions[0].name which describe where to place the patch. | |
16 | |
17 Args: | |
18 extra_patch_project_roots: Dict mapping project names to relative roots. | |
19 | |
20 Returns: | |
21 Relative path or empty string if patch_project is not set or path for a | |
22 given is unknown. | |
23 """ | |
24 # Property 'patch_project' is set by Rietveld, 'project' is set by git-try | |
25 # when TRYSERVER_PROJECT is present in codereview.settings. | |
26 patch_project = (self.m.properties.get('patch_project') or | |
27 self.m.properties.get('project')) | |
28 | |
29 # Please avoid adding projects into this hard-coded list unless your project | |
30 # CLs are being run by multiple recipes. Instead pass patch_project_roots to | |
31 # ensure_checkout. | |
32 patch_project_roots = { | |
33 'angle/angle': ['third_party', 'angle'], | |
34 'blink': ['third_party', 'WebKit'], | |
35 'v8': ['v8'], | |
36 'luci-py': ['luci'], | |
37 'recipes-py': ['recipes-py'], | |
38 } | |
39 | |
40 # Make sure to update common projects (above) with extra projects (and not | |
41 # vice versa, so that recipes can override default values if needed. | |
42 if extra_patch_project_roots: | |
43 patch_project_roots.update(extra_patch_project_roots) | |
44 | |
45 path_parts = patch_project_roots.get(patch_project) | |
46 return self.m.path.join(*path_parts) if path_parts else '' | |
47 | |
48 def apply_issue(self, *root_pieces, **kwargs): | |
49 """Call apply_issue from depot_tools. | |
50 | |
51 Args: | |
52 root_pieces (strings): location where to run apply_issue, relative to the | |
53 checkout root. | |
54 authentication (string or None): authentication scheme to use. Can be None | |
55 or 'oauth2'. See also apply_issue.py --help (-E and --no-auth options.) | |
56 """ | |
57 # TODO(pgervais): replace *root_pieces by a single Path object. | |
58 authentication = kwargs.get('authentication', None) | |
59 rietveld_url = self.m.properties['rietveld'] | |
60 issue_number = self.m.properties['issue'] | |
61 | |
62 if authentication == 'oauth2': | |
63 step_result = self.m.python( | |
64 'apply_issue', | |
65 self.m.path['depot_tools'].join('apply_issue.py'), [ | |
66 '-r', self.m.path['checkout'].join(*root_pieces), | |
67 '-i', issue_number, | |
68 '-p', self.m.properties['patchset'], | |
69 '-s', rietveld_url, | |
70 '-E', self.m.path['build'].join('site_config', | |
71 '.rietveld_client_email'), | |
72 '-k', self.m.path['build'].join('site_config', | |
73 '.rietveld_secret_key') | |
74 ], | |
75 ) | |
76 | |
77 else: | |
78 step_result = self.m.python( | |
79 'apply_issue', | |
80 self.m.path['depot_tools'].join('apply_issue.py'), [ | |
81 '-r', self.m.path['checkout'].join(*root_pieces), | |
82 '-i', issue_number, | |
83 '-p', self.m.properties['patchset'], | |
84 '-s', rietveld_url, | |
85 '--no-auth'], | |
86 ) | |
87 step_result.presentation.links['Applied issue %s' % issue_number] = ( | |
88 urlparse.urljoin(rietveld_url, str(issue_number))) | |
89 | |
OLD | NEW |