예제 #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
예제 #2
0
def test_store_issue_stores_file(regular_issue, test_repo):
    ih = IssueHandler()
    ih.store_issue(regular_issue, None, True)
    result = ih.get_issue_from_issue_id(regular_issue.id)
    regular_issue.id = "ISSUE-11"  # 11 because tracker is mocked to have 10 entries

    assert regular_issue == result
예제 #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()
예제 #4
0
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))