Exemplo n.º 1
0
    def expand(team_id=None,
               channel=None,
               params=None,
               data=None,
               only_create=False,
               save_graph=True):

        if len(params) < 3:
            text = ':red_circle: Hi, for the `expand` command, you need to provide the following parameters: '
            attachment_text =  '- *graph_name*: the graph to expand\n'  \
                               '- *depth* : how many cycles to expand\n'  \
                               '- *links to expand*: as a comma-delimited list '
            slack_message(text, [{'text': attachment_text}], channel, team_id)
            return
        create_params = ["expand"] + list(
            params
        )  # create copy of array so that we don't lose data with the pops below
        graph_or_key = params.pop(0)
        depth = int(params.pop(0))
        link_types_to_add = ' '.join(params).split(',')

        graph = Lambda_Graph().get_gs_graph___by_name(graph_or_key)
        if graph is None:
            graph = GS_Graph()  # if it wasn't a graph
            graph.add_node(graph_or_key)  # use it as key

        (graph.set_puml_link_types_to_add(
            link_types_to_add).add_all_linked_issues(
                [], depth).set_create_params(create_params))
        if save_graph:
            new_graph_name = graph.reset_puml().render_and_save_to_elk()
        else:
            return graph

        if only_create:
            return graph, new_graph_name, graph_or_key, depth, link_types_to_add

        if channel:  # if the channel value is provided render the new graph and send it to slack, if not, just return the new graph data
            text = "Rendering new graph called `{0}`,\n Which was created by expanding the graph/key `{1}` with depth `{2}`, for link types `{3}` (`{4}` nodes, `{5}` edges)"\
                        .format(new_graph_name, graph_or_key, depth, link_types_to_add,
                                len(graph.nodes), len(graph.edges))
            slack_message(text, [], channel, team_id)

            Lambda('gw_bot.lambdas.puml_to_slack').invoke({
                "puml":
                graph.get_puml(),
                "channel":
                channel,
                "team_id":
                team_id
            })
        else:
            data = {
                "graph_or_key": graph_or_key,
                "depth": depth,
                "nodes": graph.nodes,
                "edges": graph.edges,
                "puml": graph.puml.puml,
                "graph_name": new_graph_name
            }
            return json.dumps(data, indent=4)
Exemplo n.º 2
0
    def show(team_id, channel, params, data=None):

        if len(params) < 1:
            text = ':red_circle: Hi, for the `show` command, you need to provide an `graph_name`'
            slack_message(text, [], channel, team_id)
            return

        graph_name = Misc.array_pop(params, 0)
        graph = Lambda_Graph().get_gs_graph___by_name(graph_name)
        if graph is None:
            text = ':red_circle: Graph with name `{0}` not found'.format(
                graph_name)
            slack_message(text, [], channel, team_id)
        else:
            default_engine = 'viva_graph'
            engines = Misc.array_pop(params, 0)
            if engines is None: engines = default_engine

            if engines != default_engine:  # only show in case there is more than one engine
                text = f":point_right: Showing graph with name `{graph_name}`, with `{len(graph.nodes)}` nodes and `{len(graph.edges)}` edges)"
                slack_message(text, [], channel, team_id)

            if 'plantuml' in engines:
                slack_message('...using `plantuml`', [], channel, team_id)
                Lambda('gw_bot.lambdas.puml_to_slack').invoke_async({
                    "puml":
                    graph.get_puml(),
                    "channel":
                    channel,
                    "team_id":
                    team_id
                })

            if 'vis_js' in engines:
                slack_message('...using `vis_js`', [], channel, team_id)
                params = ['graph', graph_name, 'default']
                Lambda('osbot_browser.lambdas.lambda_browser').invoke_async({
                    "params":
                    params,
                    'data': {
                        'team_id': team_id,
                        'channel': channel
                    }
                })

            if 'viva_graph' in engines:
                if engines != default_engine:  # only show in case there is more than one engine
                    slack_message('...using `viva_graph`', [], channel,
                                  team_id)
                params = ['viva_graph', graph_name, 'default']
                Lambda('osbot_browser.lambdas.lambda_browser').invoke_async({
                    "params":
                    params,
                    'data': {
                        'team_id': team_id,
                        'channel': channel
                    }
                })

            if 'go_js' in engines:
                slack_message('...using `go_js`', [], channel, team_id)
                params = ['go_js', graph_name, 'circular']
                Lambda('osbot_browser.lambdas.lambda_browser').invoke_async({
                    "params":
                    params,
                    'data': {
                        'team_id': team_id,
                        'channel': channel
                    }
                })