Exemple #1
0
    def put(self, id):
        edit_schema = IssueSchema(only=tuple(IssueSchema.issue_fields.keys()))
        parsed_data = edit_schema.load(request.get_json())

        if (len(parsed_data.errors.items()) > 0):
            return f"Errors encountered with the request: {parsed_data.errors}", 416

        updated_issue = parsed_data.data

        issue = None
        httpStatus: HTTPStatus = None
        headers = {}

        handler = IssueHandler()
        if (not handler.does_issue_exist(id)):
            issue = handler.store_issue(updated_issue, "create", True)

            hash = hashlib.sha256(
                b"{regular_schema.dump(issue).data}").hexdigest()
            print(f"Hash: {hash}")
            headers["ETag"] = hash
            httpStatus = HTTPStatus.CREATED

        else:
            current_issue = handler.get_issue_from_issue_id(id)

            if (updated_issue.id != id):
                return "Given issue ID does not match url", 416

            updated_issue.date = current_issue.date  # Ensure date NEVER changes
            issue = handler.store_issue(updated_issue, "edit")

        result = to_payload(GitUser(), issue, IssueSchema)

        return result.data, HTTPStatus.OK
Exemple #2
0
    def get(self, id):
        handler = IssueHandler()
        if (not handler.does_issue_exist(id)):
            abort(HTTPStatus.NOT_FOUND)

        issue = handler.get_issue_from_issue_id(id)
        result = to_payload(GitUser(), issue, IssueSchema)
        return result.data
Exemple #3
0
    def post(self, id):
        ih = IssueHandler()

        if (not ih.does_issue_exist(id)):
            raise BadRequest(f"Issue with id {id} does not exist.")

        comment = request.get_json().get("comment")

        if (comment is None):
            raise BadRequest(f"No comment given.")

        comment = Comment(comment)
        gm = GitManager()
        path = gm.perform_git_workflow(lambda: ih.get_issue_folder_path(id))
        handler = CommentHandler(path, id)
        created_comment = handler.add_comment(comment)

        schema = CommentSchema()
        result = schema.dump(comment)

        return result.data, HTTPStatus.CREATED
Exemple #4
0
    def get(self, args, id):
        issue_handler = IssueHandler()
        if not issue_handler.does_issue_exist(id):
            raise BadRequest(f"Issue with id {id} does not exist.")

        page = args.get("page", 1)
        limit = 1000  # args.get("limit", 10)

        # Each page is limit amount of comments, therefore start_pos
        # is the limit of comments per page, times by the page number
        start_pos = limit * (page - 1)
        gm = GitManager()

        def action():
            path = issue_handler.get_issue_folder_path(id)
            comment_handler = CommentHandler(path, id)
            return comment_handler.get_comment_range(limit, start_pos)

        comments = gm.perform_git_workflow(action)
        schema = CommentSchema()
        result = schema.dump(comments, many=True)

        return result.data
    def generate_resolution(self):
        """
            Resolves conflicts by re-ordering the issues based on their creation date.
            The conflicts are resolved by giving the oldest issue the first conflicting issue ID.

            Returns a tuple containing the list of resolved conflicts, and an updated tracker.
            These resolved conflicts are NOT stored to fie by this method. This is left as a job for the consumer.
        """

        # Create copies of data to avoid mutating them as a side affect
        conflicts = []

        for info in self.conflicts:
            for issue in info.conflicts:
                conflicts.append(issue)

        if self.tracker is None:
            tracker = Tracker.obtain_tracker()
        else:
            tracker = Tracker(self.tracker.issue_count,
                              self.tracker.tracked_uuids.copy())

        complete = False
        handler = IssueHandler(tracker)
        ids = [issue.id for issue in conflicts]

        while not complete:
            to_add = []

            for issue in conflicts:
                next_id = handler.next_issue_id(issue.id)
                while next_id in ids:
                    next_id = handler.next_issue_id(next_id)

                if next_id not in ids:
                    if handler.does_issue_exist(next_id):
                        missing = handler.get_issue_from_issue_id(next_id)
                        to_add.append(missing)

                    ids.append(next_id)

            for issue in to_add:
                conflicts.append(issue)
                ids.append(issue.id)

            complete = len(to_add) == 0

        conflicts.sort(key=lambda x: x.date)
        sorted_ids = list(set(ids))
        sorted_ids.sort()

        assert len(sorted_ids) >= len(conflicts)

        index = 0
        for issue in conflicts:
            new_id = sorted_ids[index]
            issue.id = new_id
            tracker.track_or_update_uuid(issue.uuid, new_id)
            index += 1

        return CreateResolutionTool(conflicts, tracker)