def print_status(remotes: List[str] = ['origin'], target_branch: Optional[str] = None, list_commits: bool = False, query_ci_status: bool = False, graph_format: Optional[str] = None): graph = None if graph_format: # Try to create a new graph. This will throw an exception if the # Graphviz package is missing. try: graph = create_graph(graph_format) except Exception as e: print(e) return # Collect all branches across remotes and create corresponding # subgraphs. This needs to happen before we add the edges. branches: List[str] = [] for remote in remotes: for config in find_am_configs(remote): branches.append(config.upstream) branches.append(config.target) if config.secondary_upstream: branches.append(config.secondary_upstream) add_branches(graph, branches) for remote in remotes: configs: List[AMTargetBranchConfig] = find_am_configs(remote) if target_branch: configs = list( filter(lambda config: config.target == target_branch, configs)) if len(configs) == 0: msg = '' if target_branch: msg = f'for branch "{target_branch}" from ' print(f'No automerger configured for {msg}remote "{remote}"') return ms = find_inflight_merges(remote) printed = False for config in configs: if printed: print('') if config.secondary_upstream: print_zippered_edge_status(config, remote, graph) printed = True continue print_edge_status(config.upstream, config.target, ms, list_commits, remote, graph, query_ci_status=query_ci_status) printed = True if graph: graph.render('automergers', view=True)
def print_graph(remotes: List = ['origin'], query_ci_status: bool = False, fmt: str = 'pdf'): if 'graphviz' not in sys.modules: print( f'Generating the automerger graph requires the "graphviz" Python package.' ) return try: graph = Digraph(comment='Automergers', format=fmt, node_attr=NODE_ATTR) graph.attr(rankdir=RANKDIR, nodesep=NODESEP, ranksep=RANKSEP, splines=SPLINES) except ValueError as e: print(e) return # Collect all branches and create corresponding subgraphs. branches: List[str] = [] for remote in remotes: for config in find_am_configs(remote): branches.append(config.upstream) branches.append(config.target) if config.secondary_upstream: branches.append(config.secondary_upstream) add_branches(graph, branches) # Create the edges. for remote in remotes: configs: List[AMTargetBranchConfig] = find_am_configs(remote) if len(configs) == 0: print(f'No automerger configured for remote "{remote}"') continue merges = find_inflight_merges(remote) for config in configs: if config.secondary_upstream: left_state, right_state = get_zippered_state(config, remote) graph.edge(config.upstream, config.target, color=EdgeStates.get_color(left_state), penwidth=PENWIDTH) graph.edge(config.secondary_upstream, config.target, color=EdgeStates.get_color(right_state), penwidth=PENWIDTH, constraint='false') else: edge_state = get_state(config.upstream, config.target, merges, remote, query_ci_status) graph.edge(config.upstream, config.target, color=EdgeStates.get_color(edge_state), penwidth=PENWIDTH) graph.render('automergers', view=True)
def test_am_config(cd_to_am_tool_repo_clone): configs = find_am_configs() if len(configs) != 2: raise AssertionError if configs[0].upstream != 'upstream': raise AssertionError if configs[0].target != 'master': raise AssertionError if configs[0].test_command is not None: raise AssertionError if configs[0].secondary_upstream is not None: raise AssertionError if configs[0].common_ancestor is not None: raise AssertionError if configs[0].test_commits_in_bundle is not False: raise AssertionError if configs[1].upstream != 'master': raise AssertionError if configs[1].target != 'swift/master': raise AssertionError if configs[1].test_command is not None: raise AssertionError if configs[1].secondary_upstream is not None: raise AssertionError if configs[1].common_ancestor is not None: raise AssertionError if configs[1].test_commits_in_bundle is not True: raise AssertionError
def print_status(remote: str = 'origin', target_branch: Optional[str] = None, list_commits: bool = False, query_ci_status: bool = False): configs: List[AMTargetBranchConfig] = find_am_configs(remote) if target_branch: configs = list( filter(lambda config: config.target == target_branch, configs)) if len(configs) == 0: msg = '' if target_branch: msg = f'for branch "{target_branch}" from ' print(f'No automerger configured for {msg}remote "{remote}"') return ms = find_inflight_merges(remote) printed = False for config in configs: if printed: print('') if config.secondary_upstream: print_zippered_edge_status(config, remote) printed = True continue print_edge_status(config.upstream, config.target, ms, list_commits, remote, query_ci_status=query_ci_status) printed = True
def test_am_config(cd_to_am_tool_repo_clone): configs = find_am_configs() assert len(configs) == 1 assert configs[0].upstream == 'upstream' assert configs[0].target == 'master' assert configs[0].test_command is None assert configs[0].secondary_upstream is None assert configs[0].common_ancestor is None
def test_am_config(cd_to_am_tool_repo_clone): configs = find_am_configs() assert len(configs) == 2 assert configs[0].upstream == 'upstream' assert configs[0].target == 'master' assert configs[0].test_command is None assert configs[0].secondary_upstream is None assert configs[0].common_ancestor is None assert configs[0].test_commits_in_bundle is False assert configs[1].upstream == 'master' assert configs[1].target == 'swift/master' assert configs[1].test_command is None assert configs[1].secondary_upstream is None assert configs[1].common_ancestor is None assert configs[1].test_commits_in_bundle is True