Example #1
0
    def help_resolve_recent_activity(self, labbook):
        """Method to create 4 activity records with show=True"""
        # Create instance of ActivityStore for this LabBook
        store = ActivityStore(labbook)

        records = list()
        # Get 4 records with show=True
        after = None
        while len(records) < 4:
            items = store.get_activity_records(first=4, after=after)

            if not items:
                # if no more items, continue
                break

            for item in items:
                if item.show is True and item.num_detail_objects > 0:
                    ar = ActivityRecordObject(
                        id=f"labbook&{self.owner}&{self.name}&{item.commit}",
                        owner=self.owner,
                        name=self.name,
                        _repository_type='labbook',
                        commit=item.commit,
                        _activity_record=item)
                    records.append(ar)
                    if len(records) >= 4:
                        break

                # Set after cursor to last commit
                after = item.commit

        return records
Example #2
0
    def helper_resolve_activity_records(self, dataset, kwargs):
        """Helper method to generate ActivityRecord objects and populate the connection"""
        # Create instance of ActivityStore for this dataset
        store = ActivityStore(dataset)

        if kwargs.get('before') or kwargs.get('last'):
            raise ValueError(
                "Only `after` and `first` arguments are supported when paging activity records"
            )

        # Get edges and cursors
        edges = store.get_activity_records(after=kwargs.get('after'),
                                           first=kwargs.get('first'))
        if edges:
            cursors = [x.commit for x in edges]
        else:
            cursors = []

        # Get ActivityRecordObject instances
        edge_objs = []
        for edge, cursor in zip(edges, cursors):
            edge_objs.append(
                ActivityConnection.Edge(node=ActivityRecordObject(
                    id=f"dataset&{self.owner}&{self.name}&{edge.commit}",
                    owner=self.owner,
                    name=self.name,
                    _repository_type='dataset',
                    commit=edge.commit,
                    _activity_record=edge),
                                        cursor=cursor))

        # Create page info based on first commit. Since only paging backwards right now, just check for commit
        if edges:
            has_next_page = True

            # Get the message of the linked commit and check if it is the non-activity record dataset creation commit
            if len(edges) > 1:
                if edges[-2].linked_commit != "no-linked-commit":
                    linked_msg = dataset.git.log_entry(
                        edges[-2].linked_commit)['message']
                    if linked_msg == f"Creating new empty Dataset: {dataset.name}" and "_GTM_ACTIVITY_" not in linked_msg:
                        # if you get here, this is the first activity record
                        has_next_page = False

            end_cursor = cursors[-1]
        else:
            has_next_page = False
            end_cursor = None

        page_info = graphene.relay.PageInfo(has_next_page=has_next_page,
                                            has_previous_page=False,
                                            end_cursor=end_cursor)

        return ActivityConnection(edges=edge_objs, page_info=page_info)
Example #3
0
    def mutate_and_get_payload(cls,
                               root,
                               info,
                               owner,
                               title,
                               labbook_name=None,
                               dataset_name=None,
                               body=None,
                               tags=None,
                               client_mutation_id=None):

        if labbook_name is not None and dataset_name is not None:
            raise ValueError(
                "A note can be created in only 1 repository at a time.")

        username = get_logged_in_username()
        if labbook_name:
            name = labbook_name
            repository_type = 'labbook'
            r = InventoryManager().load_labbook(username,
                                                owner,
                                                labbook_name,
                                                author=get_logged_in_author())
        elif dataset_name:
            name = dataset_name
            repository_type = 'dataset'
            r = InventoryManager().load_dataset(username,
                                                owner,
                                                dataset_name,
                                                author=get_logged_in_author())
        else:
            raise ValueError(
                "You must either set `labbookName` or `datasetName` to create a note."
            )

        with r.lock():
            ar = cls._create_user_note(r, title, body, tags)

        return CreateUserNote(new_activity_record_edge=ActivityConnection.Edge(
            node=ActivityRecordObject(owner=owner,
                                      name=name,
                                      _repository_type=repository_type,
                                      commit=ar.commit),
            cursor=ar.commit))
    def mutate_and_get_payload(cls,
                               root,
                               info,
                               owner,
                               labbook_name,
                               title,
                               body=None,
                               tags=None,
                               client_mutation_id=None):
        username = get_logged_in_username()

        # Load LabBook instance
        lb = LabBook(author=get_logged_in_author())
        lb.from_name(username, owner, labbook_name)

        # Create a Activity Store instance
        store = ActivityStore(lb)

        # Create detail record
        adr = ActivityDetailRecord(ActivityDetailType.NOTE,
                                   show=True,
                                   importance=255)
        if body:
            adr.add_value('text/markdown', body)

        # Create activity record
        ar = ActivityRecord(ActivityType.NOTE,
                            message=title,
                            linked_commit="no-linked-commit",
                            importance=255,
                            tags=tags)
        ar.add_detail_object(adr)
        ar = store.create_activity_record(ar)

        return CreateUserNote(new_activity_record_edge=ActivityConnection.Edge(
            node=ActivityRecordObject(
                owner=owner, name=labbook_name, commit=ar.commit),
            cursor=ar.commit))