Ejemplo n.º 1
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
Ejemplo n.º 2
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}'
        }
Ejemplo n.º 3
0
def test_store_issue_has_correct_path(regular_issue, test_repo):
    root = f"{test_repo.working_dir}/issue"
    ih = IssueHandler()
    ih.store_issue(regular_issue, None)
    gm = GitManager()
    gm.load_issue_branch()
    assert Path(f"{root}/{regular_issue.id}/issue.json").exists()
Ejemplo n.º 4
0
def pull(args):
    def action():
        sync = GitSynchronizer()
        sync.pull(args.with_merge)
        sync = None
    gm = GitManager()
    gm.perform_git_workflow(action)
Ejemplo n.º 5
0
def merge(args):
    def action():
        sync = GitSynchronizer()
        sync.merge(GitMerge(sync.repo))
        sync = None
    gm = GitManager()
    gm.perform_git_workflow(action)
Ejemplo n.º 6
0
def push(args):
    def action():
        sync = GitSynchronizer()
        sync.push()
        sync = None
    gm = GitManager()
    gm.perform_git_workflow(action)
Ejemplo n.º 7
0
    def _generate_issue_folder_path(id):
        dir = Path.cwd()

        gm = GitManager()
        if dir.parts[-1] != "issue" and gm.is_worktree():
            dir = dir.joinpath("issue")

        return dir.joinpath(id)
Ejemplo n.º 8
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)
Ejemplo n.º 9
0
def show(args):
    if args.issue is not None:
        handler = GitManager().perform_git_workflow(lambda: IssueHandler())
        issue = handler.get_issue_from_issue_id(args.issue)

        if issue == None:
            print(f"Issue with ID {args.issue} was not found.")
        else:
            handler.display_issue(issue)
    else:
        list(args)
Ejemplo n.º 10
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)
Ejemplo n.º 11
0
def test_repo(tmpdir):
    repo = git.Repo.init(tmpdir.mkdir("test_repo"))

    fake_file_dir = Path(repo.working_dir + "/fake-file.pla")
    open(fake_file_dir, 'w').close()
    repo.index.add([str(fake_file_dir)])
    repo.index.commit("Blah")

    os.chdir(repo.working_dir)
    gm = GitManager()
    setattr(gm, "get_choice_from_user", lambda x: True)
    gm.load_issue_branch()

    return repo
Ejemplo n.º 12
0
    def resolve(self):
        gm = GitManager()
        gm.load_issue_branch()
        paths = []
        handler = IssueHandler()

        for issue in self.resolved_issues:
            file_path = handler.get_issue_path(issue)
            JsonConvert.ToFile(issue, file_path)
            paths.append(str(file_path))

        repo = gm.obtain_repo()
        for path in paths:
            repo.git.add(path)
Ejemplo n.º 13
0
def comment(args):
    ih = GitManager().perform_git_workflow(lambda: IssueHandler())
    handler = GitManager().perform_git_workflow(lambda: CommentHandler(ih.get_issue_folder_path(args.issue), args.issue))

    if args.comment:
        c = Comment(args.comment)
        handler.add_comment(c)
    else:
        comments = GitManager().perform_git_workflow(lambda: handler.get_comment_range(10000, 0))
        for c in comments:
            print(f"Email: {c.user.email}\tDate: {c.date}\n\t{c.comment}\n")
Ejemplo n.º 14
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)
Ejemplo n.º 15
0
def test_create_resolution(issue_1: Issue, issue_2: Issue, monkeypatch, first_repo: git.Repo):
    handler = IssueHandler()

    issue_1_path = handler.get_issue_path(issue_1)
    issue_2_path = handler.get_issue_path(issue_2)
    issues = [issue_1, issue_2]

    os.chdir(first_repo.working_dir)
    monkeypatch.setattr("git_issue.git_manager.GitManager.get_choice_from_user", lambda x, y: True)
    monkeypatch.setattr("builtins.input", lambda x: 'Y')

    uuids = [UUIDTrack(issue_1.uuid, issue_1.id), UUIDTrack(issue_2.uuid, issue_2.id)]

    resolution = CreateResolutionTool(issues, Tracker(len(uuids), uuids))

    resolution.resolve()
    GitManager().commit("-m", "merge conflict resolution")

    assert issue_1_path.exists()
    assert issue_2_path.exists()

    result_1 = handler.get_issue_from_issue_id(issues[0].id)
    result_2 = handler.get_issue_from_issue_id(issues[1].id)

    assert issues[0] == result_1
    assert issues[1] == result_2
Ejemplo n.º 16
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)
Ejemplo n.º 17
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)
Ejemplo n.º 18
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
Ejemplo n.º 19
0
    def merge(self, merger):
        print("Beginning merge process")
        conflicts = merger.parse_unmerged_conflicts()
        create_resolver = merger.produce_create_resolver(conflicts)
        create_resolution = create_resolver.generate_resolution()
        create_resolution.resolve()

        tracker = create_resolution.tracker if create_resolution.tracker.issue_count != 0 else Tracker.obtain_tracker(
        )

        divergence_resolver = merger.produce_create_edit_divergence_resolver(
            conflicts, create_resolution.resolved_issues, tracker)
        divergence_resolution = divergence_resolver.generate_resolution()
        divergence_resolution.resolve()

        comment_resolvers = merger.produce_comment_index_resolvers(conflicts)
        for resolver in comment_resolvers:
            resolution = resolver.generate_resolution()
            resolution.resolve()

        manual_conflicts = merger.filter_manual_conflicts(conflicts)

        if manual_conflicts == []:
            self.repo.git.commit("-m", "merge conflict resolution")
            print("Merge successful. All files have been merged.")
        else:
            print(
                "I wasn't able to resolve all the conflicts. This typically happens when something's been edited "
                "in both the remote and current repository.")
            print("Here are the files I couldn't resolve:")

            for conflict in manual_conflicts:
                print(f"\t{conflict.path}")

            gm = GitManager()
            if gm.is_worktree():
                print(
                    "Exiting program to prevent branch unloading. This would cause loss of resolved conflicts."
                )
                exit()
Ejemplo n.º 20
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
Ejemplo n.º 21
0
    def does_issue_exist(self, id: str):
        gm = GitManager()

        is_loaded = gm.is_inside_branch()
        if not is_loaded:
            gm.load_issue_branch()

        exists = _generate_issue_file_path(id).exists()

        if not is_loaded:
            gm.unload_issue_branch()

        return exists
Ejemplo n.º 22
0
    def from_email(email):
        repo = GitManager.obtain_repo()

        #repo.git.shortlog(se)...
        """ To get all contributors we need to query git's CLI directly and
            analyse the shortlog. The command "git shortlog -se" will give all
            contributors names and email addresses in the format of:
            1\tUser <email>\n - and repeats like this until the end."""
        shortlog = repo.git.shortlog("-se")
        if shortlog != "":
            for line in shortlog.split("\n"):
                str = line.split("\t")[1]
                temp = str.split(" <")
                if (temp[1].replace(">", "") == email):
                    return GitUser(temp[0], email)

        return None
Ejemplo n.º 23
0
def change_status(issue_id, status):
    handler = GitManager().perform_git_workflow(lambda: IssueHandler())

    if not handler.does_issue_exist(issue_id):
        print("Error: Issue does not exist")
        return

    issue = handler.get_issue_from_issue_id(issue_id)
    original_status = issue.status
    issue.status = status
    handler.store_issue(issue, "edit")
    print(f"Status of {issue.id} changed from '{original_status}' to '{issue.status}'")
Ejemplo n.º 24
0
    def get_issue_from_issue_id(self, id):
        gm = GitManager()
        is_loaded = gm.is_inside_branch()

        if not is_loaded:
            gm.load_issue_branch()

        try:
            file = JsonConvert.FromFile(_generate_issue_file_path(id))
        except FileNotFoundError:
            return None

        if not is_loaded:
            gm.unload_issue_branch()

        return file
Ejemplo n.º 25
0
def edit(args):
    handler = GitManager().perform_git_workflow(lambda: IssueHandler())
    if not handler.does_issue_exist(args.issue):
        print("Error: Issue does not exist")
        return

    issue = handler.get_issue_from_issue_id(args.issue)

    if (issue == None):
        print("There was a problem ")

    print("Issue before editing:")
    handler.display_issue(issue)

    issue.summary = args.summary if args.summary != None else issue.summary
    issue.description = args.description if args.description != None else issue.description
    issue.assignee = GitUser(email=args.assignee) if args.assignee != None else issue.assignee
    issue.reporter = GitUser(email=args.reporter) if args.reporter != None else issue.reporter
    issue.status = args.status if args.status != None else issue.status

    print()
    confirm_operation(issue, lambda: handler.store_issue(issue, "edit"))
Ejemplo n.º 26
0
 def resolve(self):
     JsonConvert.ToFile(self.index, Path(self.path))
     gm = GitManager()
     repo = gm.obtain_repo()
     repo.git.add(self.path)
Ejemplo n.º 27
0
def list(args):
    handler = GitManager().perform_git_workflow(lambda: IssueHandler())
    issues = issue_handler.get_all_issues()
    for i in issues:
        handler.display_issue(i)
        print()
Ejemplo n.º 28
0
 def operation():
     handler = GitManager().perform_git_workflow(lambda: IssueHandler())
     new_issue = handler.store_issue(issue, "creation", True, True)
     print(f"ID of newly created issue: {new_issue.id}")
Ejemplo n.º 29
0
 def store_index(self, issue_id):
     loc = self._generate_index_path(
         Path(issue_id)) if issue_id is not None else self._path_to_index
     JsonConvert.ToFile(self, loc)
     gm = GitManager()
     gm.add_to_index([str(loc)])
Ejemplo n.º 30
0
def does_issue_exist(id):
    gm = GitManager()
    return gm.perform_git_workflow(
        lambda: _generate_issue_file_path(id).exists())