Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(171)

Side by Side Diff: recipes/recipe_modules/recipe_autoroller/api.py

Issue 2249413005: recipe_autoroller: pass cwd=workdir directly, not using a context (Closed) Base URL: https://chromium.googlesource.com/infra/infra.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | recipes/recipes/recipe_autoroller.expected/basic.json » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 4
5 import base64 5 import base64
6 import hashlib 6 import hashlib
7 import json 7 import json
8 import re 8 import re
9 9
10 from recipe_engine import recipe_api 10 from recipe_engine import recipe_api
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 # Introduce ourselves to git - also needed for git cl upload to work. 172 # Introduce ourselves to git - also needed for git cl upload to work.
173 self.m.git( 173 self.m.git(
174 'config', 'user.email', 'recipe-roller@chromium.org', cwd=workdir) 174 'config', 'user.email', 'recipe-roller@chromium.org', cwd=workdir)
175 self.m.git('config', 'user.name', 'recipe-roller', cwd=workdir) 175 self.m.git('config', 'user.name', 'recipe-roller', cwd=workdir)
176 176
177 # git cl upload cannot work with detached HEAD, it requires a branch. 177 # git cl upload cannot work with detached HEAD, it requires a branch.
178 self.m.git('checkout', '-t', '-b', 'roll', 'origin/master', cwd=workdir) 178 self.m.git('checkout', '-t', '-b', 'roll', 'origin/master', cwd=workdir)
179 179
180 # Check status of last known CL for this repo. Ensure there's always 180 # Check status of last known CL for this repo. Ensure there's always
181 # at most one roll CL in flight. 181 # at most one roll CL in flight.
182 with self.m.step.context({'cwd': workdir}): 182 repo_data, cl_status = self._get_pending_cl_status(
183 repo_data, cl_status = self._get_pending_cl_status( 183 project_data['repo_url'], workdir)
184 project_data['repo_url'])
185 if repo_data: 184 if repo_data:
186 # Allow trivial rolls in CQ to finish. 185 # Allow trivial rolls in CQ to finish.
187 if repo_data['trivial'] and cl_status == 'commit': 186 if repo_data['trivial'] and cl_status == 'commit':
188 return ROLL_SUCCESS 187 return ROLL_SUCCESS
189 188
190 # Allow non-trivial rolls to wait for review comments. 189 # Allow non-trivial rolls to wait for review comments.
191 if not repo_data['trivial'] and cl_status != 'closed': 190 if not repo_data['trivial'] and cl_status != 'closed':
192 return ROLL_SUCCESS 191 return ROLL_SUCCESS
193 192
194 # We're about to upload a new CL, so close the old one. 193 # We're about to upload a new CL, so close the old one.
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 repo_data = { 326 repo_data = {
328 'issue': change_data['issue'], 327 'issue': change_data['issue'],
329 'issue_url': change_data['issue_url'], 328 'issue_url': change_data['issue_url'],
330 'trivial': roll_result['trivial'], 329 'trivial': roll_result['trivial'],
331 } 330 }
332 self.m.gsutil.upload( 331 self.m.gsutil.upload(
333 self.m.json.input(repo_data), 332 self.m.json.input(repo_data),
334 'recipe-roller-cl-uploads', 333 'recipe-roller-cl-uploads',
335 'repo_metadata/%s' % base64.urlsafe_b64encode(repo_url)) 334 'repo_metadata/%s' % base64.urlsafe_b64encode(repo_url))
336 335
337 def _get_pending_cl_status(self, repo_url): 336 def _get_pending_cl_status(self, repo_url, workdir):
338 """Returns (current_repo_data, git_cl_status_string) of the last known 337 """Returns (current_repo_data, git_cl_status_string) of the last known
339 roll CL for given repo. 338 roll CL for given repo.
340 339
341 If no such CL has been recorded, returns (None, None). 340 If no such CL has been recorded, returns (None, None).
342 """ 341 """
343 cat_result = self.m.gsutil.cat( 342 cat_result = self.m.gsutil.cat(
344 'gs://recipe-roller-cl-uploads/repo_metadata/%s' % ( 343 'gs://recipe-roller-cl-uploads/repo_metadata/%s' % (
345 base64.urlsafe_b64encode(repo_url)), 344 base64.urlsafe_b64encode(repo_url)),
346 stdout=self.m.raw_io.output(), 345 stdout=self.m.raw_io.output(),
347 stderr=self.m.raw_io.output(), 346 stderr=self.m.raw_io.output(),
(...skipping 16 matching lines...) Expand all
364 repo_data['issue_url']) 363 repo_data['issue_url'])
365 if repo_data['trivial']: 364 if repo_data['trivial']:
366 cat_result.presentation.step_text += ' (trivial)' 365 cat_result.presentation.step_text += ' (trivial)'
367 366
368 status_result = self.m.git( 367 status_result = self.m.git(
369 'cl', 'status', 368 'cl', 'status',
370 '--issue', repo_data['issue'], 369 '--issue', repo_data['issue'],
371 '--rietveld', 370 '--rietveld',
372 '--field', 'status', 371 '--field', 'status',
373 name='git cl status', stdout=self.m.raw_io.output(), 372 name='git cl status', stdout=self.m.raw_io.output(),
373 cwd=workdir,
374 step_test_data=lambda: self.m.raw_io.test_api.stream_output( 374 step_test_data=lambda: self.m.raw_io.test_api.stream_output(
375 'foo') 375 'foo')
376 ).stdout.strip() 376 ).stdout.strip()
377 377
378 return repo_data, status_result 378 return repo_data, status_result
OLDNEW
« no previous file with comments | « no previous file | recipes/recipes/recipe_autoroller.expected/basic.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698