def test_derive_state_filepath(self): self.assertEqual("config.state", ReviewFileSet._state_filepath("config")) self.assertEqual("my.config.state", ReviewFileSet._state_filepath("my.config")) self.assertEqual("my.reviewconfig.state", ReviewFileSet._state_filepath("my.reviewconfig"))
def _user_choose_review_config(): config_path = _get_config_path() if isfile(config_path): print "Found previous review configuration %s." % config_path choice_use_existing = prompt_user( "Use it and send review update [y/n]?", ('y', 'n')) if choice_use_existing == 'y': return ReviewFileSet(config_path) print '''\ (1) Load other existing review configuration? (2) Create a NEW review request for all COMMITTED changes on the branch? (3) Create a NEW review request for all UNCOMMITTED changes on the branch?\ ''' choice_of_action = prompt_user("Answer:", ('1', '2', '3')) config_path = prompt_user("Enter path of review configuration file:") if choice_of_action == '1': if not isfile(config_path): error("%s does not exist" % config_path) return ReviewFileSet(config_path) elif choice_of_action in ['2', '3']: if isfile(config_path): choice_overwrite = prompt_user( "Overwrite %s [y/n]?" % config_path, ('y', 'n')) if choice_overwrite == 'n': return None os.unlink(config_path) uncommitted = (choice_of_action == '3') return _init_default_review_config_file(config_path, None, uncommitted) else: print '''\ Could not find a previous review configuration for this branch. (1) Create a NEW review request for all COMMITTED changes on the branch? (2) Create a NEW review request for all UNCOMMITTED changes on the branch? (3) Update an EXISTING review request with all COMMITTED changes on the \ branch? (4) Update an EXISTING review request with all UNCOMMITTED changes on the \ branch?\ ''' choice_of_action = prompt_user("Answer:", ('1', '2', '3', '4')) if choice_of_action in ['3', '4']: review_id = prompt_user("Give review ID:") if not review_id.isdigit(): error("invalid review ID given") else: review_id = None uncommitted = choice_of_action in ['2', '4'] return _init_default_review_config_file(config_path, review_id, uncommitted)
def test_error_if_state_exist_but_not_config(self): open(self._state_file, "w").close() self.assertFalse(os.path.isfile(self._config_file)) self.assertTrue(os.path.isfile(self._state_file)) with self.assertRaisesRegexp(ExecutionError, "state file found"): ReviewFileSet(self._config_file)
def _execute_update(): config_path = _get_config_path() if isfile(config_path) and options.config is None: print "Using existing review configuration file %s." % config_path elif not isfile(config_path): error("Could not find review configuration file %s." % config_path) _post_reviews_in_config(ReviewFileSet(config_path))
def _execute_new(): config_path = _get_config_path() if isfile(config_path): if options.config is None: usage_error('''\ Found an existing review configuration at %(config_path)s. Do you want to create a new review using this configuration? If so, run "review new -c %(config_path)s". Or did you want to update an existing review using this configuration? If so, run "review update" instead.\ ''' % {"config_path": config_path}) else: review_file_set = ReviewFileSet(config_path) if any([ review.review_id is not None for review in review_file_set.review_config ]): usage_error('''\ Expected no reviews with IDs listed in "%s" when running a "new" command. Did you mean to run an "update" command? If yes, run "review update -c %s ...".\ ''' % (options.config, config_path)) review_file_set.review_state.reset() else: review_file_set = \ _init_default_review_config_file(config_path, None, False) if options.uncommitted: review_file_set.review_state.set_uncommitted(options.uncommitted) _post_reviews_in_config(review_file_set)
def test_config_and_state_do_not_exist(self): self.assertFalse(os.path.isfile(self._config_file)) self.assertFalse(os.path.isfile(self._state_file)) s = ReviewFileSet(self._config_file) self.assertIsInstance(s.review_config, ReviewConfigurationFile) self.assertIsInstance(s.review_state, ReviewStateFile) self.assertFalse(os.path.isfile(self._config_file)) self.assertFalse(os.path.isfile(self._state_file))
def _init_default_review_config_file(config_path, review_id, uncommitted): review_file_set = ReviewFileSet(config_path) review_config = review_file_set.review_config review_state = review_file_set.review_state review_state.set_uncommitted(uncommitted) review_config.add_review(review_id, "-i *") if not options.dry_run: print "Creating review configuration file %s." % config_path review_config.save() return review_file_set
def _init_default_review_config_file(config_path, review_id, unpushed, parent): if (not unpushed and not options.pushed and options.diff is None and _do_unpushed_commits_exist()): usage_error(WORKING_COPY_HAS_UNPUSHED_COMMITS) review_file_set = ReviewFileSet(config_path) review_config = review_file_set.review_config review_state = review_file_set.review_state review_state.set_unpushed(unpushed) review_state.set_branch_parent(parent) review_config.add_review(review_id, '-i *') if not options.dry_run: print('Creating review configuration file {0}.'.format(config_path)) review_config.save() return review_file_set
def _execute_update(): config_path = _get_config_path() if isfile(config_path) and options.config is None: print( 'Using existing review configuration file {0}'.format(config_path)) elif not isfile(config_path): error( 'Could not find review configuration file {0}'.format(config_path)) review_file_set = ReviewFileSet(config_path) if options.unpushed: review_file_set.review_state.set_unpushed(True) review_file_set.review_state.set_branch_parent( _get_branch_parent(options.unpushed)) elif options.parent is not None: review_file_set.review_state.set_unpushed(False) review_file_set.review_state.set_branch_parent( _get_branch_parent_from_option()) _post_reviews_in_config(review_file_set)
def _execute_new(): config_path = _get_config_path() if isfile(config_path): if options.config is None: usage_error(USAGE_ERROR_CONFIG_FOUND.format(config_path)) else: review_file_set = ReviewFileSet(config_path) if any([ review.review_id is not None for review in review_file_set.review_config ]): usage_error( USAGE_ERROR_ID_FOUND_WITH_NEW.format( options.config, config_path)) review_file_set.review_state.reset() else: review_file_set = _init_default_review_config_file( config_path, None, options.unpushed, None) review_file_set.review_state.set_branch_parent( _get_branch_parent(options.unpushed)) _post_reviews_in_config(review_file_set)
def _user_choose_review_config(): config_path = _get_config_path() if isfile(config_path): print('Found previous review configuration {0}'.format(config_path)) choice_use_existing = prompt_user( 'Use it and send review update [y/n]?', ('y', 'n')) if choice_use_existing == 'y': return ReviewFileSet(config_path) print('''\ (1) Load other existing review configuration? (2) Create a NEW review request for all PUSHED changes on the branch? (3) Create a NEW review request for all UNPUSHED changes on the branch?\ ''') choice_of_action = prompt_user('Answer:', ('1', '2', '3')) config_path = prompt_user('Enter path of review configuration file:') if choice_of_action == '1': if not isfile(config_path): error('{0} does not exist'.format(config_path)) review_file_set = ReviewFileSet(config_path) if review_file_set.review_state.get_branch_parent() is None: review_file_set.review_state.set_branch_parent( _get_branch_parent(unpushed=False, query_user=True)) return review_file_set elif choice_of_action in ['2', '3']: if isfile(config_path): choice_overwrite = prompt_user( 'Overwrite {0} [y/n]?'.format(config_path), ('y', 'n')) if choice_overwrite == 'n': return None os.unlink(config_path) unpushed = choice_of_action == '3' parent = _get_branch_parent(unpushed, query_user=True) return _init_default_review_config_file(config_path, None, unpushed, parent) else: print('''\ Could not find a previous review configuration for this branch. (1) Create a NEW review request for all PUSHED changes on the branch? (2) Create a NEW review request for all UNPUSHED changes on the branch? (3) Update an EXISTING review request with all PUSHED changes on the \ branch? (4) Update an EXISTING review request with all UNPUSHED changes on the branch? ''') choice_of_action = prompt_user('Answer:', ('1', '2', '3', '4')) if choice_of_action in ['3', '4']: review_id = prompt_user('Give review ID:') if not review_id.isdigit(): error('invalid review ID given') else: review_id = None unpushed = choice_of_action in ['2', '4'] parent = _get_branch_parent(unpushed, query_user=True) return _init_default_review_config_file(config_path, review_id, unpushed, parent)