def test_divergence_resolver(issue_1, issue_2, issue_3, monkeypatch):
    resolved_issues = [issue_1, issue_2, issue_3]
    resolved_tracker = Tracker()

    summary_edit = "This edit resolves the create-edit-divergence"
    monkeypatch.setattr("builtins.input", lambda x: summary_edit)

    for issue in resolved_issues:
        resolved_tracker.track_or_update_uuid(issue.uuid, issue.id)

    issue_3_json = JsonConvert.ToJSON(issue_3)
    issue_3_copy = JsonConvert.FromJSON(issue_3_json)
    issue_3_copy.summary = "This is the edited field for the create-edit-divergence"
    issue_3_copy.id = issue_2.id

    expected = JsonConvert.FromJSON(issue_3_json)
    expected.summary = summary_edit

    resolver = DivergenceConflictResolver()
    resolver.resolved_tracker = resolved_tracker
    resolver.resolved_conflicts = resolved_issues
    resolver.diverged_issues = [(issue_3, issue_3_copy)]

    resolution = resolver.generate_resolution()
    assert [issue_3, expected] == resolution.resolved_issues
def test_filter_manual_conflicts(issue_1, issue_2, first_repo):
    create = ConflictInfo(None, [issue_1, issue_1, issue_2])

    issue_1_json = JsonConvert.ToJSON(issue_1)
    issue_1_copy = JsonConvert.FromJSON(issue_1_json)
    issue_1_copy.uuid = issue_2.uuid

    manual = ConflictInfo(None, [issue_1_copy, issue_1_copy, issue_1_copy])

    result = GitMerge(first_repo).filter_manual_conflicts([create, manual])
    assert [manual] == result
Example #3
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
Example #4
0
 def _get_comment(self, entry):
     try:
         return JsonConvert.FromFile(entry.path)
     except FileNotFoundError as err:
         msg = f"An invalid index entry has been found for file \"{err.filename}\"." \
               f" Please reconstruct the index for {self.folder_path}"
         raise index.IndexEntryInvalidError(msg)
Example #5
0
 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
     ]
Example #6
0
 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
Example #7
0
    def obtain_index(cls, path):
        index_path = cls._generate_index_path(path)

        if (index_path.exists()):
            return JsonConvert.FromFile(index_path)
        else:
            index = Index()
            return index
def test_produce_divergence_resolver(issue_1, issue_2, issue_3, first_repo):
    resolved_issues = [issue_1, issue_2, issue_3]
    resolved_tracker = Tracker()

    for issue in resolved_issues:
        resolved_tracker.track_or_update_uuid(issue.uuid, issue.id)

    issue_2_json = JsonConvert.ToJSON(issue_2)
    issue_2_copy = JsonConvert.FromJSON(issue_2_json)
    issue_2_copy.uuid = 53368803138698180295652887974160049016

    conflict = ConflictInfo(IssueHandler().get_issue_path(issue_2), [issue_2, issue_2, issue_2_copy])

    merger = GitMerge(first_repo)
    resolver = merger.produce_create_edit_divergence_resolver([conflict], resolved_issues, resolved_tracker)
    assert resolved_issues == resolver.resolved_conflicts and resolved_tracker == resolver.resolved_tracker
    assert [(issue_2, issue_2_copy)] == resolver.diverged_issues
Example #9
0
def create_tmp_file(dir, issue):
    class FakeParent():
        def exists(any=None):
            return True

    new_dir = Path(dir).joinpath(f"{issue.id}/issue.json")
    JsonConvert.ToFile(issue, new_dir)

    return new_dir
Example #10
0
    def obtain_tracker(cls):
        tracker = None    
        path = cls.get_path()

        if path.exists():
            tracker = JsonConvert.FromFile(path)
        else:
            tracker = Tracker()

        return tracker
Example #11
0
        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
Example #12
0
        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)
Example #13
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)
Example #14
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
Example #15
0
    def parse_unmerged_conflicts(self) -> [ConflictInfo]:
        unmerged_blobs = self.repo.index.unmerged_blobs()
        unmerged: [ConflictInfo] = []

        for unmerged_file in unmerged_blobs:
            conflicts = []

            for (stage, blob) in unmerged_blobs[unmerged_file]:
                if stage != 0:
                    data = blob.data_stream.read().decode()
                    obj = JsonConvert.FromJSON(data)

                    conflicts.append(obj)

            unmerged.append(ConflictInfo(unmerged_file, conflicts))

        return unmerged
Example #16
0
 def store_tracker(self):
     JsonConvert.ToFile(self, Tracker.get_path())
     gm = GitManager()
     gm.add_to_index([str(Tracker.get_path())])
def test_unmerged_conflicts(issue_1: Issue, issue_2: Issue, issue_3: Issue, first_repo: git.Repo, second_repo: git.Repo,
                            monkeypatch):
    # Create, Create-Edit-Divergence, Comment-Index, Manual
    issue_2_json = JsonConvert.ToJSON(issue_2)
    issue_2_copy = JsonConvert.FromJSON(issue_2_json)
    issue_2_copy.summary = "Edited Summary"

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

    def merge(repo):
        try:
            repo.git.checkout("issue")
            repo.git.pull("--allow-unrelated-histories", "other", GitManager.ISSUE_BRANCH)
        except:
            pass

        merger = GitMerge(repo)
        return merger.parse_unmerged_conflicts()

    # Set up first repo for Create conflict
    os.chdir(first_repo.working_dir)
    handler = IssueHandler()
    handler.store_issue(issue_2, "test", generate_id=True)

    # Set up second repo for Create conflict
    os.chdir(second_repo.working_dir)
    handler = IssueHandler()
    handler.store_issue(issue_1, "test", generate_id=True)

    result = merge(second_repo)
    expected = [ConflictInfo("ISSUE-1/issue.json", [issue_1, issue_2])]
    assert expected == result
    GitSynchronizer().merge(GitMerge(second_repo))

    # Set up first repo for divergence conflict
    os.chdir(first_repo.working_dir)
    handler = IssueHandler()
    issue_2_copy.id = issue_1.id
    handler.store_issue(issue_2_copy, "test")

    os.chdir(second_repo.working_dir)
    result = merge(second_repo)
    expected = [ConflictInfo("ISSUE-1/issue.json", [issue_2, issue_1, issue_2_copy])]
    assert expected == result
    GitSynchronizer().merge(GitMerge(second_repo))


    # Comment
    os.chdir(first_repo.working_dir)
    handler = IssueHandler()
    comment_handler = CommentHandler(handler.get_issue_path(issue_1), issue_1.id)
    first_comment = Comment("first repo")
    first_entry = comment_handler.add_comment(first_comment)

    # Comment
    os.chdir(second_repo.working_dir)
    handler = IssueHandler()
    comment_handler = CommentHandler(handler.get_issue_path(issue_1), issue_1.id)
    second_comment = Comment("second repo")
    second_entry = comment_handler.add_comment(second_comment)

    result = merge(second_repo)
    expected = [ConflictInfo("ISSUE-1/index.json", [Index([second_entry]), Index([first_entry])])]

    assert expected == result
    GitSynchronizer().merge(GitMerge(second_repo))

    # Edit conflict
    issue_1.id = "ISSUE-10" # Just so we don't need to work out the ID
    issue_1_json = JsonConvert.ToJSON(issue_1)
    issue_1_first_repo = JsonConvert.FromJSON(issue_1_json)
    issue_1_second_repo = JsonConvert.FromJSON(issue_1_json)
    issue_1_first_repo.summary = "First Repo"
    issue_1_second_repo.summary = "Second Repo"

    # Set up both repos with the issue that will be used as a conflict
    os.chdir(first_repo.working_dir)
    handler = IssueHandler()
    handler.store_issue(issue_1, "test")
    os.chdir(second_repo.working_dir)
    result = merge(second_repo)

    # Edit first repo
    os.chdir(first_repo.working_dir)
    handler.store_issue(issue_1_first_repo, "test")

    # Edit second repo
    os.chdir(second_repo.working_dir)
    handler = IssueHandler()
    handler.store_issue(issue_1_second_repo, "issue 10 edit")
    result = merge(second_repo)

    expected = [ConflictInfo("ISSUE-10/issue.json", [issue_1, issue_1_second_repo, issue_1_first_repo])]
    assert expected == result
    GitSynchronizer().merge(GitMerge(second_repo))
Example #18
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)])
Example #19
0
 def resolve(self):
     JsonConvert.ToFile(self.index, Path(self.path))
     gm = GitManager()
     repo = gm.obtain_repo()
     repo.git.add(self.path)