Beispiel #1
0
    def group_by_field(self, root_node, field_name):
        graph = self.graph
        issues = graph.get_nodes_issues()  # resolve current node's issues
        nodes = graph.nodes  # save current nodes
        edges = graph.edges  # save current edges
        graph.nodes = []  # reset nodes
        graph.edges = []  # reset edges
        graph.add_node(root_node)
        if field_name == 'Issue Links':
            for edge in edges:
                link_type = edge[1]
                to_key = edge[2]
                to_issue = Misc.get_value(issues, to_key, {})
                to_key = Misc.get_value(to_issue, 'Key')
                graph.add_node(link_type)
                graph.add_node(to_key)
                graph.add_edge(root_node, '', link_type)
                graph.add_edge(link_type, '', to_key)

        else:
            for node in nodes:
                issue = issues.get(node)
                if issue:
                    value = issue.get(field_name)
                    graph.add_node(value)
                    graph.add_node(node)
                    graph.add_edge(root_node, field_name, value)
                    graph.add_edge(value, '', node)
        return self
Beispiel #2
0
def run(event, context):
    try:
        load_dependencies('requests,syncer,pyppeteer,websocket-client')
        from osbot_jupyter.osbot.Jupyter_Commands import Jupyter_Commands
        params = Misc.get_value(event, 'params', [])
        if not params: params = ['']
        data = event.get('data')
        channel = Misc.get_value(data, 'channel')
        team_id = Misc.get_value(data, 'team_id')
        params.append({"data": data})
        return Slack_Commands_Helper(Jupyter_Commands).invoke(
            team_id, channel, params)
    except Exception as error:
        message = "[lambda_osbot] Error: {0}".format(error)
        #log_to_elk(message, level='error')
        return message
    def handle_action(self, event):
        action = Misc.get_value(Misc.array_pop(event.get('actions'), 0),
                                'value')
        try:
            target = getattr(self, action)
        except:
            return self.message_not_supported_action(action)

        try:
            return target(event)
        except Exception as error:
            return self.message_execution_error(error)
Beispiel #4
0
 def handle_block_action(self,event):        # todo: refactor in to separate method handler (specially when adding the lambda capability)
     channel  = Misc.get_value(Misc.get_value(event,'channel'),'id')
     team_id  = Misc.get_value(Misc.get_value(event,'team'),'id')
     actions  = event.get('actions')
     handlers = { 'Jira_View_Issue': Jira_View_Issue}
     def send_message(message):
         if channel:
             slack_message(message,[], channel, team_id)
         else:
             return message
     try:
         for action in actions:
             split_action  = action.get('action_id').split('::')
             action_type   = Misc.array_get(split_action, 0)
             action_class  = Misc.array_get(split_action, 1)
             action_method = Misc.array_get(split_action, 2)
             if action_type == 'class_method':
                 if action_class and action_method:
                     target = handlers.get(action_class)
                     if target:
                         try:
                             method = getattr(target, action_method)
                             #slack_message(':point_right: Invoking method `{0}.{1}`'.format(action_class,action_method), [], channel, team_id)
                             try:
                                 target_obj = target(channel=channel,team_id=team_id, event=event)
                                 return method(target_obj, action)
                             except Exception as error:
                                 return send_message(':red_circle: Error in `handle_block_action` invocation of method `{0}.{1}`: `{2}`'.format(action_class,action_method, error))
                         except:
                             return send_message(':red_circle: Error in `handle_block_action` could not resolve method: `{0}.{1}`'.format(action_class,action_method))
                     else:
                         return send_message(':red_circle: Error in `handle_block_action` could not resolve class action: `{0}`'.format(action_class))
                 else:
                     return send_message(':red_circle: Error in `handle_block_action` could not resolve action: `{0}`'.format(action))
             #elif action_type == 'lambda':
             else:
                 return send_message(':red_circle: Error in `handle_block_action` un-supported action type: `{0}`'.format(split_action))
         return None
     except Exception as error:
         return send_message(":red_circle: error in handle_block_action: `{0}` . Actions value was `{1}`".format(error,actions))
    def handle_action(self, event):
        self.send_message('aaaa')
        action = Misc.array_pop(event.get('actions'), 0)
        action_value = Misc.get_value(action, 'value')
        try:
            target = getattr(self, action_value)
        except:
            channel = event.get('channel').get('id')
            team_id = event.get('team').get('id')
            # temp code (refactor when adding full support for blocks)
            text = ':point_right: message not recognised: {0}'.format(action)
            API_Slack_Blocks().set_text(text).send_message(channel, team_id)

            return self.message_not_supported_action(
                action)  # event.get('original_message'))

        try:
            return target(event)
        except Exception as error:
            return self.message_execution_error(error)
    def start(team_id=None, channel=None, params=None):
        try:
            server_size = 'large'
            event       = Misc.array_pop(params)
            user        = Misc.get_value(event,'data', {}).get('user')
            repo_name   = Misc.array_pop(params,0)

            if repo_name is None:
                repo_name = 'gwbot-jupyter-notebooks'                   # todo: move to global param value
                #return ":red_circle: you need to provide an git repo with notebooks, for example try `gs-notebook-gscs`"
            if '-' not in repo_name and len(repo_name) < 10:
                repo_name = 'gs-notebook-{0}'.format(repo_name)         # todo: move to config value (since this is implementation specific)
            payload = {
                        'repo_name': repo_name,
                        "channel"  : channel  ,
                        'user'     : user     ,
                        'server_size': server_size}
            #slack_message(f':point_right: about to start a jupyter notebook with params: {payload} ', [], channel)
            Lambda('osbot_jupyter.lambdas.start_server').invoke_async(payload)
        except Exception as error:
            return f':red_circle: error in Jupyter start command: {error}'
 def __init__(self, data, channel=None, team_id=None):
     self.data = data
     self.submission = Misc.get_value(data, 'submission')
     self.channel = channel
     self.team_id = team_id
Beispiel #8
0
 def value_secret(self):
     return Misc.get_value(self.get_secret(),'Value')
Beispiel #9
0
 def project_info(self):
     projects = Misc.get_value(
         self.codebuild.batch_get_projects(names=[self.project_name]),
         'projects', [])
     return Misc.array_pop(projects, 0)
Beispiel #10
0
 def stream_arn(self):
     streams   = self.dynamo.dynamo_streams().list_streams(TableName=self.table_name).get('Streams')
     first_one = Misc.array_pop(streams,0)
     return Misc.get_value(first_one,'StreamArn')
Beispiel #11
0
 def role_arn(self):
     return Misc.get_value(self.role_info(), 'Arn')