def _find_what_version_parser_to_use(file_): start_string_then_version_class = [cls for path, cls in _VERSION_CLASS_PER_BEGINNING_OF_PATH.items() if file_.startswith(path)] try: return start_string_then_version_class[0] except IndexError as exc: raise TreeScriptError(exc) from exc
async def async_main(config, task): """Run all the vcs things. Args: config (dict): the running config. task (dict): the running task. """ work_dir = config["work_dir"] repo_path = os.path.join(work_dir, "src") actions_to_perform = task_action_types(config, task) await log_mercurial_version(config) if not await validate_robustcheckout_works(config): raise TreeScriptError("Robustcheckout can't run on our version of hg, aborting") await retry_async(do_actions, args=(config, task, actions_to_perform, repo_path), retry_exceptions=(CheckoutError, PushError)) log.info("Done!")
async def do_actions(config, task, actions, repo_path): """Perform the set of actions that treescript can perform. The actions happen in order, tagging, ver bump, then push Args: config (dict): the running config task (dict): the running task actions (list): the actions to perform repo_path (str): the source directory to use. attempts (int, optional): the number of attempts to perform, retrying on error. """ await checkout_repo(config, task, repo_path) num_changes = 0 for action in actions: if action in ["tagging", "tag"]: num_changes += await do_tagging(config, task, repo_path) elif "version_bump" == action: num_changes += await bump_version(config, task, repo_path) elif "l10n_bump" == action: num_changes += await l10n_bump(config, task, repo_path) elif "push" == action: pass # handled after log_outgoing else: raise NotImplementedError("Unexpected action") num_outgoing = await log_outgoing(config, task, repo_path) if num_outgoing != num_changes: raise TreeScriptError( "Outgoing changesets don't match number of expected changesets!" " {} vs {}".format(num_outgoing, num_changes)) if is_dry_run(task): log.info("Not pushing changes, dry_run was forced") elif "push" in actions: if num_changes: await push(config, task, repo_path) else: log.info("No changes; skipping push.") else: log.info("Not pushing changes, lacking scopes") await strip_outgoing(config, task, repo_path)
async def do_actions(config, task, actions, repo_path): """Perform the set of actions that treescript can perform. The actions happen in order, tagging, ver bump, then push Args: config (dict): the running config task (dict): the running task actions (list): the actions to perform repo_path (str): the source directory to use. """ await checkout_repo(config, task, repo_path) # Split the action selection up due to complexity in do_actions # caused by different push behaviour, and action return values. if "merge_day" in actions: await perform_merge_actions(config, task, actions, repo_path) return num_changes = 0 if "tag" in actions: num_changes += await do_tagging(config, task, repo_path) if "version_bump" in actions: num_changes += await bump_version(config, task, repo_path) if "l10n_bump" in actions: num_changes += await l10n_bump(config, task, repo_path) num_outgoing = await log_outgoing(config, task, repo_path) if num_outgoing != num_changes: raise TreeScriptError( "Outgoing changesets don't match number of expected changesets!" " {} vs {}".format(num_outgoing, num_changes)) if should_push(task, actions): if num_changes: await push(config, task, repo_path, target_repo=get_source_repo(task)) else: log.info("No changes; skipping push.") await strip_outgoing(config, task, repo_path)
async def do_actions(config, task, actions, repo_path): """Perform the set of actions that treescript can perform. The actions happen in order, tagging, ver bump, then push Args: config (dict): the running config task (dict): the running task actions (list): the actions to perform repo_path (str): the source directory to use. """ source_repo = get_source_repo(task) # mercurial had been the only default choice until git was supported, default to it. repo_type = "git" if is_github_url(source_repo) else "hg" vcs = get_vcs_module(repo_type) await vcs.checkout_repo(config, task, repo_path) # Split the action selection up due to complexity in do_actions # caused by different push behaviour, and action return values. if "merge_day" in actions: await perform_merge_actions(config, task, actions, repo_path, repo_type) return num_changes = 0 if "tag" in actions: num_changes += await vcs.do_tagging(config, task, repo_path) if "version_bump" in actions: num_changes += await bump_version(config, task, repo_path, repo_type) if "l10n_bump" in actions: num_changes += await l10n_bump(config, task, repo_path, repo_type) num_outgoing = await vcs.log_outgoing(config, task, repo_path) if num_outgoing != num_changes: raise TreeScriptError("Outgoing changesets don't match number of expected changesets!" " {} vs {}".format(num_outgoing, num_changes)) if should_push(task, actions): if num_changes: await vcs.push(config, task, repo_path, target_repo=get_source_repo(task)) else: log.info("No changes; skipping push.") await vcs.strip_outgoing(config, task, repo_path)