Exemplo n.º 1
0
def merge(args):
    def action():
        sync = GitSynchronizer()
        sync.merge(GitMerge(sync.repo))
        sync = None
    gm = GitManager()
    gm.perform_git_workflow(action)
Exemplo n.º 2
0
def pull(args):
    def action():
        sync = GitSynchronizer()
        sync.pull(args.with_merge)
        sync = None
    gm = GitManager()
    gm.perform_git_workflow(action)
Exemplo n.º 3
0
def push(args):
    def action():
        sync = GitSynchronizer()
        sync.push()
        sync = None
    gm = GitManager()
    gm.perform_git_workflow(action)
Exemplo n.º 4
0
    def post(self):
        json = request.get_json()

        issue = Issue()
        issue.summary = json.get("summary")
        issue.description = json.get("description")
        reporter = json.get("reporter")
        assignee = json.get("assignee")
        issue.reporter = GitUser(email=reporter.get(
            "email")) if reporter is not None else GitUser()
        issue.assignee = GitUser(
            email=assignee.get("email")) if assignee is not None else None

        issue.subscribers.append(issue.reporter)
        if issue.assignee is not None and issue.assignee not in issue.subscribers:
            issue.subscribers.append(issue.assignee)

        gm = GitManager()
        handler = gm.perform_git_workflow(lambda: IssueHandler())
        created_issue = handler.store_issue(issue,
                                            "create",
                                            generate_id=True,
                                            store_tracker=True)
        result = to_payload(GitUser(), issue, IssueSchema)

        return result.data, HTTPStatus.CREATED, {
            'location': f'issues/${created_issue.id}'
        }
Exemplo n.º 5
0
def get_issue(id):
    gm = GitManager()
    try:
        return gm.perform_git_workflow(
            lambda: JsonConvert.FromFile(_generate_issue_file_path(id)))
    except IOError:
        return None
Exemplo n.º 6
0
def get_comment_range(issue_id, range: int, start_pos: int = 0):
    gm = GitManager()

    def action():
        handler = CommentHandler(_generate_issue_folder_path(issue_id),
                                 issue_id)
        return handler.get_comment_range(range, start_pos)

    return gm.perform_git_workflow(action)
Exemplo n.º 7
0
def get_all_issues():
    gm = GitManager()

    def action():
        path = Path.cwd()
        dirs = [d for d in path.iterdir() if d.is_dir() and d.match("ISSUE-*")]
        return [
            JsonConvert.FromFile(_generate_issue_file_path(i.parts[-1]))
            for i in dirs
        ]

    return gm.perform_git_workflow(action)
Exemplo n.º 8
0
    def add_comment(self, comment) -> IndexEntry:
        gm = GitManager()

        def gen_paths():
            return [str(self.generate_comment_path(comment.uuid))]

        def action():
            self.index = index.Index.obtain_index(self.issue_path)
            path = self.generate_comment_path(comment.uuid)
            JsonConvert.ToFile(comment, path)
            entry = self.index.add_entry(path, comment)
            self.index.store_index(self.issue_id)
            return entry

        return gm.perform_git_workflow(action, True, gen_paths, "add_comment",
                                       self.issue_id)
Exemplo n.º 9
0
    def store_issue(self, issue, cmd, generate_id=False, store_tracker=False):
        def gen_paths():
            return [str(self._generate_issue_file_path(issue.id))]

        def action():
            if generate_id:
                issue.id = self.generate_issue_id()

            JsonConvert.ToFile(issue, self._generate_issue_file_path(issue.id))
            self.tracker.track_or_update_uuid(issue.uuid, issue.id)

            if store_tracker:
                self.tracker.store_tracker()

            return issue

        gm = GitManager()
        return gm.perform_git_workflow(action, True, gen_paths, cmd, issue.id)
Exemplo n.º 10
0
    def get_issue_range(self, page: int = 1, limit: int = 10):
        gm = GitManager()

        def action():
            start_pos = (page - 1) * limit
            end = start_pos + limit

            path = Path.cwd()
            dirs = [
                d for d in path.iterdir() if d.is_dir() and d.match("ISSUE-*")
            ]
            range = dirs[start_pos:end]
            return [
                JsonConvert.FromFile(_generate_issue_file_path(i.parts[-1]))
                for i in range
            ], len(dirs)

        return gm.perform_git_workflow(action)
Exemplo n.º 11
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
Exemplo n.º 12
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
Exemplo n.º 13
0
def does_issue_exist(id):
    gm = GitManager()
    return gm.perform_git_workflow(
        lambda: _generate_issue_file_path(id).exists())