示例#1
0
    def test_single_project(self):
        skip_test()
        u_to = User("admin")
        u_from = User("testuser")
        to_proj = self._prj("test", "admin")
        self._add(to_proj, u_to, "README.md", "hi")
        from_proj = self._prj("testuser/test", "testuser", to_proj.id)
        self._add(from_proj, u_from, "README.md", "hello")
        pullreq = PullRequest.open(from_proj, "master", to_proj, "master")
        ticket = Ticket(None, None, to_proj.id, "title", "desc", "testuser",
                        None, None)
        pullreq = add_pull(ticket, pullreq, u_from)

        iss = ProjectIssue.add(title='title1',
                               description='desc1',
                               creator='owner',
                               project=to_proj.id)
        IssuePRSearch.index_a_project(to_proj)
        res = IssueSearch.search_a_phrase('title1', to_proj.id)
        res = SearchEngine.decode(res, ('issue_id', ))
        res = [id for id, in res]
        assert len(res) == 1
        assert res[0] == iss.id
        res = PullRequestSearch.search_a_phrase('title', to_proj.id)
        res = SearchEngine.decode(res, ('issue_id', ))
        res = [id for id, in res]
        assert len(res) == 1
示例#2
0
文件: pull.py 项目: 000fan000/code
    def create(self, request):
        user = request.user
        if not user:
            raise AccessError
        from_proj = request.get_form_var('from_proj')
        from_ref = request.get_form_var('from_ref')
        to_ref = request.get_form_var('to_ref')
        to_proj = request.get_form_var('to_proj')
        title = request.get_form_var('title', '').decode('utf-8')
        comment = request.get_form_var('body', '').decode('utf-8')
        if not all([from_ref, from_proj, to_ref, to_proj]):
            raise TraversalError
        from_proj = CodeDoubanProject.get_by_name(from_proj)
        to_proj = CodeDoubanProject.get_by_name(to_proj)
        if from_proj != to_proj:
            if not from_proj.has_push_perm(user.name):
                raise AccessError(
                    "Need push permission to create PR on another project")

        pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
        ticket = Ticket(None, None, to_proj.id, title, comment,
                        user.username, None, None)
        pullreq = add_pull(ticket, pullreq, user)
        ticket = pullreq.ticket
        return request.redirect(str('/%s/pull/%s/' % (to_proj.name,
                                                      ticket.ticket_id)))
示例#3
0
    def test_get_commits(self):
        """应该能够得到所有将合并的改动"""
        with setup2repos('prj3') as (path, repo, fork_path, fork_repo):

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            commits = pullreq.commits
            eq_(len(commits), 1)
示例#4
0
    def test_single_project(self):
        skip_test()
        u_to = User("admin")
        u_from = User("testuser")
        to_proj = self._prj("test", "admin")
        self._add(to_proj, u_to, "README.md", "hi")
        from_proj = self._prj("testuser/test", "testuser", to_proj.id)
        self._add(from_proj, u_from, "README.md", "hello")
        pullreq = PullRequest.open(from_proj, "master", to_proj, "master")
        ticket = Ticket(None, None, to_proj.id, "title", "desc", "testuser",
                        None, None)
        pullreq = add_pull(ticket, pullreq, u_from)

        iss = ProjectIssue.add(title='title1', description='desc1',
                               creator='owner', project=to_proj.id)
        IssuePRSearch.index_a_project(to_proj)
        res = IssueSearch.search_a_phrase('title1', to_proj.id)
        res = SearchEngine.decode(res, ('issue_id',))
        res = [id for id, in res]
        assert len(res) == 1
        assert res[0] == iss.id
        res = PullRequestSearch.search_a_phrase('title', to_proj.id)
        res = SearchEngine.decode(res, ('issue_id',))
        res = [id for id, in res]
        assert len(res) == 1
示例#5
0
    def test_get_commits(self):
        """应该能够得到所有将合并的改动"""
        with setup2repos('prj3') as (path, repo, fork_path, fork_repo):

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            commits = pullreq.commits
            eq_(len(commits), 1)
示例#6
0
文件: pull.py 项目: jackfrued/code-1
    def create(self, request):
        user = request.user
        if not user:
            raise AccessError
        from_proj = request.get_form_var('from_proj')
        from_ref = request.get_form_var('from_ref')
        to_ref = request.get_form_var('to_ref')
        to_proj = request.get_form_var('to_proj')
        title = request.get_form_var('title', '').decode('utf-8')
        comment = request.get_form_var('body', '').decode('utf-8')
        if not all([from_ref, from_proj, to_ref, to_proj]):
            raise TraversalError
        from_proj = CodeDoubanProject.get_by_name(from_proj)
        to_proj = CodeDoubanProject.get_by_name(to_proj)
        if from_proj != to_proj:
            if not from_proj.has_push_perm(user.name):
                raise AccessError(
                    "Need push permission to create PR on another project")

        pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
        ticket = Ticket(None, None, to_proj.id, title, comment, user.username,
                        None, None)
        pullreq = add_pull(ticket, pullreq, user)
        ticket = pullreq.ticket
        return request.redirect(
            str('/%s/pull/%s/' % (to_proj.name, ticket.ticket_id)))
示例#7
0
    def test_ticket_count(self):
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'

        p1_t1 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq1 = PullRequest.open(
            self.proj1_fork, 'master', self.proj1, 'master')
        pullreq1 = pullreq1.insert(p1_t1.ticket_number)

        p1_t2 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq = PullRequest.open(
            self.proj1_fork, 'master', self.proj1, 'master')
        pullreq = pullreq.insert(p1_t2.ticket_number)

        # test ticket count
        assert int(Ticket.get_count_by_proj(self.proj1.id)) == 2
示例#8
0
    def test_ticket_count(self):
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'

        p1_t1 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq1 = PullRequest.open(self.proj1_fork, 'master', self.proj1,
                                    'master')
        pullreq1 = pullreq1.insert(p1_t1.ticket_number)

        p1_t2 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq = PullRequest.open(self.proj1_fork, 'master', self.proj1,
                                   'master')
        pullreq = pullreq.insert(p1_t2.ticket_number)

        # test ticket count
        assert int(Ticket.get_count_by_proj(self.proj1.id)) == 2
示例#9
0
文件: pull.py 项目: jackfrued/code-1
    def new(self, request):
        user = request.user
        if not user:
            raise AccessError
        from_proj = self.project
        from_ref = request.get_form_var('head_ref', from_proj.default_branch)
        parent_proj = from_proj.get_forked_from()
        to_proj = request.get_form_var('base_repo')
        if to_proj:
            to_proj = CodeDoubanProject.get_by_name(to_proj)
        elif parent_proj:
            to_proj = parent_proj
        else:
            to_proj = from_proj
        if not to_proj:
            raise TraversalError("The PR's upstream project is not existed")
        to_ref = request.get_form_var('base_ref', to_proj.default_branch)
        if from_proj != to_proj:
            # Allow to create PR to a different project only if user has push perm
            # ~~A bit weird, maybe should be separate perms
            # ~~If from and to projects are the same, we should be in online edit mode
            if not from_proj.has_push_perm(user.name):
                raise AccessError(
                    "Need push permission to add a PR on another project")
        pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
        family = from_proj.get_fork_network()
        from_branches = from_proj.repo.branches
        to_branches = to_proj.repo.branches
        from_commit = pullreq.from_commit
        to_commit = pullreq.to_commit
        if not pullreq.can_pull:
            raise TraversalError(
                "The PR's head_ref or base_ref is not existed")
        highlighted_projects = filter(None, [from_proj, parent_proj])
        commits = pullreq.commits
        n_commits = len(commits)
        n_authors = len(set(c.author.username for c in commits))
        ticket_title, ticket_desc = self._choose_default_PR_title_and_description(
            commits)  # noqa

        # get diff
        diff = pullreq.get_diff(rename_detection=True)
        n_files = diff.length

        grouped_commits = groupby(commits, lambda c: c.author_time.date())

        prs = PullRequest.get_by_from_and_to(from_proj.id, from_ref,
                                             to_proj.id, to_ref)
        open_pullreqs = []
        for pr in prs:
            t = Ticket.get_by_projectid_and_ticketnumber(
                to_proj.id, pr.ticket_id)
            if t and t.closed is None:
                open_pullreqs.append(pr)
        guideline_url = get_project_guidelines(to_proj)
        teams = Team.get_all_team_uids()
        return st('/pull/new.html', **locals())
示例#10
0
    def test_is_auto_mergable_should_not_commit_merge(self):
        """调用 is_auto_mergable() 不应该导致仓库被 merge """
        with setup2repos('prj1') as \
                (path, repo, fork_path, fork_repo):
            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            ok_(pullreq.is_auto_mergable())

            with self.clone_clean(path) as workdir:
                assert not os.path.exists(join(workdir, 'a'))
示例#11
0
    def test_is_auto_mergable_should_not_commit_merge(self):
        """调用 is_auto_mergable() 不应该导致仓库被 merge """
        with setup2repos('prj1') as \
                (path, repo, fork_path, fork_repo):
            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            ok_(pullreq.is_auto_mergable())

            with self.clone_clean(path) as workdir:
                assert not os.path.exists(join(workdir, 'a'))
示例#12
0
文件: pull.py 项目: 000fan000/code
    def new(self, request):
        user = request.user
        if not user:
            raise AccessError
        from_proj = self.project
        from_ref = request.get_form_var('head_ref', from_proj.default_branch)
        parent_proj = from_proj.get_forked_from()
        to_proj = request.get_form_var('base_repo')
        if to_proj:
            to_proj = CodeDoubanProject.get_by_name(to_proj)
        elif parent_proj:
            to_proj = parent_proj
        else:
            to_proj = from_proj
        if not to_proj:
            raise TraversalError("The PR's upstream project is not existed")
        to_ref = request.get_form_var('base_ref', to_proj.default_branch)
        if from_proj != to_proj:
            # Allow to create PR to a different project only if user has push perm
            # ~~A bit weird, maybe should be separate perms
            # ~~If from and to projects are the same, we should be in online edit mode
            if not from_proj.has_push_perm(user.name):
                raise AccessError(
                    "Need push permission to add a PR on another project")
        pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
        family = from_proj.get_fork_network()
        from_branches = from_proj.repo.branches
        to_branches = to_proj.repo.branches
        from_commit = pullreq.from_commit
        to_commit = pullreq.to_commit
        if not pullreq.can_pull:
            raise TraversalError(
                "The PR's head_ref or base_ref is not existed")
        highlighted_projects = filter(None, [from_proj, parent_proj])
        commits = pullreq.commits
        n_commits = len(commits)
        n_authors = len(set(c.author.username for c in commits))
        ticket_title, ticket_desc = self._choose_default_PR_title_and_description(commits)  # noqa

        # get diff
        diff = pullreq.get_diff(rename_detection=True)
        n_files = diff.length

        grouped_commits = groupby(commits, lambda c: c.author_time.date())

        prs = PullRequest.get_by_from_and_to(
            from_proj.id, from_ref, to_proj.id, to_ref)
        open_pullreqs = []
        for pr in prs:
            t = Ticket.get_by_projectid_and_ticketnumber(
                to_proj.id, pr.ticket_id)
            if t and t.closed is None:
                open_pullreqs.append(pr)
        guideline_url = get_project_guidelines(to_proj)
        teams = Team.get_all_team_uids()
        return st('/pull/new.html', **locals())
示例#13
0
    def test_is_up_to_date(self):
        """应该能探测是否是已经merge过的"""
        with setup2repos('prj_uptodate') as (path, repo, fork_path, fork_repo):

            with self.clone_clean(path) as work_path:
                with chdir(work_path):
                    gyt.call(['git', 'pull', fork_path])
                    gyt.call(['git', 'push', 'origin', 'master'])

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            ok_(pullreq.is_up_to_date())
示例#14
0
    def test_is_up_to_date(self):
        """应该能探测是否是已经merge过的"""
        with setup2repos('prj_uptodate') as (path, repo, fork_path, fork_repo):

            with self.clone_clean(path) as work_path:
                with chdir(work_path):
                    gyt.call(['git', 'pull', fork_path])
                    gyt.call(['git', 'push', 'origin', 'master'])

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            ok_(pullreq.is_up_to_date())
示例#15
0
    def test_merge(self):
        """merge()应该将远程代码合并到bare仓库中"""

        with setup2repos('prj_merge') as (path, repo, fork_path, fork_repo):

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            u = User('testmerge')
            pullreq.merge(u)

            with self.clone_clean(path) as work_path:
                content = open(join(work_path, 'a')).read()
                eq_(content, "a_hunk = [('idem', u'/* highlight style */'), ('rem', u'.highlight { color: #008000; font-weight: bold; } /* Keyword */'), ('add', u'.highlight .hll { background-color: #ffffcc; }'), ('add', u'.highlight  { backggggground: #ffffff; }'), ('add', u'.high .c { color: #808080; } /* Coomment */'), ('add', u'.highlight .err { color: #F00000; background-color: #F00A0A0; } /* Error */'), ('add', u'.highlight .k { color: #008000; font-weight: bold; } /* Keyword */'), ('idem', u'.highlight .o { color: #303; } /* Operator ****/'), ('idem', u'.highlight .cm { color: #808080; } /* Comment.Multiline */'),('idem', u'adfadsfadsf'),  ('idem', u'.highlight .cp { color: #507090; } /* Comment.Preproc */')]\n")  # noqa
示例#16
0
    def test_pr_stat(self):
        TestCase.setUp(self)
        _, self.proj1, _, self.proj1_fork = setup_repos(
            mkdtemp(), 'testproject1')
        _, self.proj2, _, self.proj2_fork = setup_repos(
            mkdtemp(), 'testproject2')
        pr_rs = get_all_ticket()
        assert len(pr_rs) == 0
        pr_open_count = len(filter(lambda x: x[1] is None, pr_rs))
        assert pr_open_count == 0
        assert len(pr_rs) - pr_open_count == 0

        pullreq1 = PullRequest.open(
            self.proj1_fork, 'master', self.proj1, 'master')
        ticket1 = Ticket.add(self.proj1.id, 'title', 'content', 'testuser')
        pullreq1 = pullreq1.insert(ticket1.ticket_number)
        pullreq2 = PullRequest.open(
            self.proj2_fork, 'master', self.proj2, 'master')
        ticket2 = Ticket.add(self.proj2.id, 'title', 'content', 'testuser')
        pullreq2 = pullreq2.insert(ticket2.ticket_number)
        pr_rs = get_all_ticket()
        assert len(pr_rs) == 2
        pr_open_count = len(filter(lambda x: x[1] is None, pr_rs))
        assert pr_open_count == 2
        assert len(pr_rs) - pr_open_count == 0

        ticket1.close("testuser")
        pr_rs = get_all_ticket()
        assert len(pr_rs) == 2
        pr_open_count = len(filter(lambda x: x[1] is None, pr_rs))
        assert pr_open_count == 1
        assert len(pr_rs) - pr_open_count == 1

        pr_comment_count = get_ticket_comment_count()
        assert(pr_comment_count) == 0
        ticket2.add_comment("comment1", "testuse1")
        ticket2.add_comment("comment2", "testuse2")
        pr_comment_count = get_ticket_comment_count()
        assert(pr_comment_count) == 2
示例#17
0
    def test_pr_stat(self):
        TestCase.setUp(self)
        _, self.proj1, _, self.proj1_fork = setup_repos(
            mkdtemp(), 'testproject1')
        _, self.proj2, _, self.proj2_fork = setup_repos(
            mkdtemp(), 'testproject2')
        pr_rs = get_all_ticket()
        assert len(pr_rs) == 0
        pr_open_count = len(filter(lambda x: x[1] is None, pr_rs))
        assert pr_open_count == 0
        assert len(pr_rs) - pr_open_count == 0

        pullreq1 = PullRequest.open(self.proj1_fork, 'master', self.proj1,
                                    'master')
        ticket1 = Ticket.add(self.proj1.id, 'title', 'content', 'testuser')
        pullreq1 = pullreq1.insert(ticket1.ticket_number)
        pullreq2 = PullRequest.open(self.proj2_fork, 'master', self.proj2,
                                    'master')
        ticket2 = Ticket.add(self.proj2.id, 'title', 'content', 'testuser')
        pullreq2 = pullreq2.insert(ticket2.ticket_number)
        pr_rs = get_all_ticket()
        assert len(pr_rs) == 2
        pr_open_count = len(filter(lambda x: x[1] is None, pr_rs))
        assert pr_open_count == 2
        assert len(pr_rs) - pr_open_count == 0

        ticket1.close("testuser")
        pr_rs = get_all_ticket()
        assert len(pr_rs) == 2
        pr_open_count = len(filter(lambda x: x[1] is None, pr_rs))
        assert pr_open_count == 1
        assert len(pr_rs) - pr_open_count == 1

        pr_comment_count = get_ticket_comment_count()
        assert (pr_comment_count) == 0
        ticket2.add_comment("comment1", "testuse1")
        ticket2.add_comment("comment2", "testuse2")
        pr_comment_count = get_ticket_comment_count()
        assert (pr_comment_count) == 2
示例#18
0
    def test_get_diffs(self):
        """应该能够得到所有将合并的diff"""
        with setup2repos('prj4') as (path, repo, fork_path, fork_repo):

            # make some change in origin repo, too
            with clone(path) as work_path:
                with chdir(work_path):
                    with open('b', 'w') as f:
                        f.write('b')

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            diffs = pullreq.get_diff()
            # should not contain file b in origin
            eq_(diffs.length, 1)
示例#19
0
    def test_ticket_close(self):
        # close ticket
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'

        p2_t1 = Ticket.add(self.proj2.id, title, desc, author)
        pullreq2 = PullRequest.open(self.proj2_fork, 'master', self.proj2,
                                    'master')
        pullreq2 = pullreq2.insert(p2_t1.ticket_number)

        assert p2_t1.closed is None
        p2_t1.close('testuser')
        assert Ticket.get(p2_t1.id).closed is not None
示例#20
0
 def test_ticket(self):
     title = 'test title'
     desc = 'test desc'
     author = 'testuser'
     p1_t1 = Ticket.add(self.proj1.id, title, desc, author)
     pullreq1 = PullRequest.open(
         self.proj1_fork, 'master', self.proj1, 'master')
     pullreq1 = pullreq1.insert(p1_t1.ticket_number)
     assert p1_t1.ticket_id == 1
     assert p1_t1.title == title
     assert p1_t1.description == desc
     assert p1_t1.author == author
     p2_t1 = Ticket.add(self.proj2.id, title, desc, author)
     pullreq2 = PullRequest.open(
         self.proj2_fork, 'master', self.proj2, 'master')
     pullreq2 = pullreq2.insert(p2_t1.ticket_number)
     assert p2_t1.ticket_id == 1
     ticket = Ticket.get_by_projectid_and_ticketnumber(
         self.proj1.id, p1_t1.ticket_id)
     assert ticket.id == p1_t1.id
     ticket = Ticket.get_by_projectid_and_ticketnumber(
         self.proj2.id, p2_t1.ticket_id)
     assert ticket.id == p2_t1.id
示例#21
0
 def test_ticket(self):
     title = 'test title'
     desc = 'test desc'
     author = 'testuser'
     p1_t1 = Ticket.add(self.proj1.id, title, desc, author)
     pullreq1 = PullRequest.open(self.proj1_fork, 'master', self.proj1,
                                 'master')
     pullreq1 = pullreq1.insert(p1_t1.ticket_number)
     assert p1_t1.ticket_id == 1
     assert p1_t1.title == title
     assert p1_t1.description == desc
     assert p1_t1.author == author
     p2_t1 = Ticket.add(self.proj2.id, title, desc, author)
     pullreq2 = PullRequest.open(self.proj2_fork, 'master', self.proj2,
                                 'master')
     pullreq2 = pullreq2.insert(p2_t1.ticket_number)
     assert p2_t1.ticket_id == 1
     ticket = Ticket.get_by_projectid_and_ticketnumber(
         self.proj1.id, p1_t1.ticket_id)
     assert ticket.id == p1_t1.id
     ticket = Ticket.get_by_projectid_and_ticketnumber(
         self.proj2.id, p2_t1.ticket_id)
     assert ticket.id == p2_t1.id
示例#22
0
    def test_get_diffs(self):
        """应该能够得到所有将合并的diff"""
        with setup2repos('prj4') as (path, repo, fork_path, fork_repo):

            # make some change in origin repo, too
            with clone(path) as work_path:
                with chdir(work_path):
                    with open('b', 'w') as f:
                        f.write('b')

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            diffs = pullreq.get_diff()
            # should not contain file b in origin
            eq_(diffs.length, 1)
示例#23
0
    def test_ticket_close(self):
        # close ticket
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'

        p2_t1 = Ticket.add(self.proj2.id, title, desc, author)
        pullreq2 = PullRequest.open(
            self.proj2_fork, 'master', self.proj2, 'master')
        pullreq2 = pullreq2.insert(p2_t1.ticket_number)

        assert p2_t1.closed is None
        p2_t1.close('testuser')
        assert Ticket.get(p2_t1.id).closed is not None
示例#24
0
    def test_merge(self):
        """merge()应该将远程代码合并到bare仓库中"""

        with setup2repos('prj_merge') as (path, repo, fork_path, fork_repo):

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            u = User('testmerge')
            pullreq.merge(u)

            with self.clone_clean(path) as work_path:
                content = open(join(work_path, 'a')).read()
                eq_(content,
                    "a_hunk = [('idem', u'/* highlight style */'), ('rem', u'.highlight { color: #008000; font-weight: bold; } /* Keyword */'), ('add', u'.highlight .hll { background-color: #ffffcc; }'), ('add', u'.highlight  { backggggground: #ffffff; }'), ('add', u'.high .c { color: #808080; } /* Coomment */'), ('add', u'.highlight .err { color: #F00000; background-color: #F00A0A0; } /* Error */'), ('add', u'.highlight .k { color: #008000; font-weight: bold; } /* Keyword */'), ('idem', u'.highlight .o { color: #303; } /* Operator ****/'), ('idem', u'.highlight .cm { color: #808080; } /* Comment.Multiline */'),('idem', u'adfadsfadsf'),  ('idem', u'.highlight .cp { color: #507090; } /* Comment.Preproc */')]\n"
                    )  # noqa
示例#25
0
    def test_ticket_commit(self):
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'
        p1_t1 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq1 = PullRequest.open(
            self.proj1_fork, 'master', self.proj1, 'master')
        pullreq1 = pullreq1.insert(p1_t1.ticket_number)

        # ticket commits
        commits_value = '454418c61cd7ef1a65818121746b45064a5af5d6,454418c61cd7ef1a65818121746b45064a5af574'  # noqa
        p1_t1.add_commits(commits_value, author)
        commits = p1_t1.get_commits()
        assert len(commits) == 1
        assert commits[0].commits == commits_value
示例#26
0
    def test_ticket_commit(self):
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'
        p1_t1 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq1 = PullRequest.open(self.proj1_fork, 'master', self.proj1,
                                    'master')
        pullreq1 = pullreq1.insert(p1_t1.ticket_number)

        # ticket commits
        commits_value = '454418c61cd7ef1a65818121746b45064a5af5d6,454418c61cd7ef1a65818121746b45064a5af574'  # noqa
        p1_t1.add_commits(commits_value, author)
        commits = p1_t1.get_commits()
        assert len(commits) == 1
        assert commits[0].commits == commits_value
示例#27
0
    def test_pullrequest(self):
        pullreq1 = PullRequest.open(
            self.proj1_fork, 'master', self.proj1, 'master')
        ticket1 = Ticket.add(self.proj1.id, 'title', 'content', 'testuser')
        pullreq1.insert(ticket1.ticket_number)

        pullreq2 = PullRequest.open(
            self.proj2_fork, 'master', self.proj2, 'master')
        ticket2 = Ticket.add(self.proj2.id, 'title', 'content', 'testuser')
        pullreq2.insert(ticket2.ticket_number)

        opened_prs = self.proj1_fork.open_parent_pulls
        assert len(opened_prs) == 1

        opened_prs = self.proj2_fork.open_parent_pulls
        assert len(opened_prs) == 1

        ticket1.close('testuser')
        opened_prs = self.proj1_fork.open_parent_pulls
        assert len(opened_prs) == 0

        ticket2.close('testuser')
        opened_prs = self.proj2_fork.open_parent_pulls
        assert len(opened_prs) == 0
示例#28
0
    def test_ticket_update_desc(self):
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'

        p1_t2 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq = PullRequest.open(self.proj1_fork, 'master', self.proj1,
                                   'master')
        pullreq = pullreq.insert(p1_t2.ticket_number)

        new_title = 'this is new title'
        new_desc = 'this is new desc!'
        p1_t2.update(new_title, new_desc)
        p1_t2 = Ticket.get(p1_t2.id)
        assert p1_t2.title == new_title
        assert p1_t2.description == new_desc
示例#29
0
    def test_ticket_update_desc(self):
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'

        p1_t2 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq = PullRequest.open(
            self.proj1_fork, 'master', self.proj1, 'master')
        pullreq = pullreq.insert(p1_t2.ticket_number)

        new_title = 'this is new title'
        new_desc = 'this is new desc!'
        p1_t2.update(new_title, new_desc)
        p1_t2 = Ticket.get(p1_t2.id)
        assert p1_t2.title == new_title
        assert p1_t2.description == new_desc
示例#30
0
    def test_ticket_participants(self):
        # test participants
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'

        p1_t2 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq = PullRequest.open(self.proj1_fork, 'master', self.proj1,
                                   'master')
        pullreq = pullreq.insert(p1_t2.ticket_number)
        assert len(p1_t2.participants) == 1
        assert p1_t2.participants[0] == author

        user2 = 'testuser2'
        p1_t2.add_comment('comment contet', user2)
        assert len(p1_t2.participants) == 2
        assert p1_t2.participants[0] == author
        assert p1_t2.participants[1] == user2
示例#31
0
    def test_ticket_participants(self):
        # test participants
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'

        p1_t2 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq = PullRequest.open(
            self.proj1_fork, 'master', self.proj1, 'master')
        pullreq = pullreq.insert(p1_t2.ticket_number)
        assert len(p1_t2.participants) == 1
        assert p1_t2.participants[0] == author

        user2 = 'testuser2'
        p1_t2.add_comment('comment contet', user2)
        assert len(p1_t2.participants) == 2
        assert p1_t2.participants[0] == author
        assert p1_t2.participants[1] == user2
示例#32
0
 def test_single_project(self):
     skip_test()
     u_to = User("admin")
     u_from = User("testuser")
     to_proj = self._prj("test", "admin")
     self._add(to_proj, u_to, "README.md", "hi")
     from_proj = self._prj("testuser/test", "testuser", to_proj.id)
     self._add(from_proj, u_from, "README.md", "hello")
     pullreq = PullRequest.open(from_proj, "master", to_proj, "master")
     ticket = Ticket(None, None, to_proj.id, "title", "desc", "testuser",
                     None, None)
     pullreq = add_pull(ticket, pullreq, u_from)
     ticket = pullreq.ticket
     PullRequestSearch.index_a_project_pr(to_proj)
     res = PullRequestSearch.search_a_phrase('title', to_proj.id)
     res = SearchEngine.decode(res, ('to_proj_id', ))
     res = [id for id, in res]
     assert len(res) == 1
示例#33
0
 def test_single_project(self):
     skip_test()
     u_to = User("admin")
     u_from = User("testuser")
     to_proj = self._prj("test", "admin")
     self._add(to_proj, u_to, "README.md", "hi")
     from_proj = self._prj("testuser/test", "testuser", to_proj.id)
     self._add(from_proj, u_from, "README.md", "hello")
     pullreq = PullRequest.open(from_proj, "master", to_proj, "master")
     ticket = Ticket(None, None, to_proj.id, "title", "desc", "testuser",
                     None, None)
     pullreq = add_pull(ticket, pullreq, u_from)
     ticket = pullreq.ticket
     PullRequestSearch.index_a_project_pr(to_proj)
     res = PullRequestSearch.search_a_phrase('title', to_proj.id)
     res = SearchEngine.decode(res, ('to_proj_id',))
     res = [id for id, in res]
     assert len(res) == 1
示例#34
0
    def test_ticket_code_review(self):
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'
        p1_t1 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq1 = PullRequest.open(self.proj1_fork, 'master', self.proj1,
                                    'master')
        pullreq1 = pullreq1.insert(p1_t1.ticket_number)

        # ticket code review
        path = '/README.md'
        #position = 10
        from_sha = '454418c61cd7ef1a65818121746b45064a5af5d6'
        oid = '454418c61cd7ef1a65818121746b45064a5af5d6'
        codereview = p1_t1.add_codereview(from_sha, '', path, path, oid, oid,
                                          LINECOMMENT_INDEX_EMPTY,
                                          LINECOMMENT_INDEX_EMPTY, author,
                                          'comment content')
        assert codereview.ticket_id == p1_t1.id
        assert codereview.path == path
        assert codereview.from_sha == from_sha

        # test update content
        assert codereview.content == 'comment content'
        codereview.update('content updated')
        codereview = PullLineComment.get(codereview.id)
        assert codereview.content == 'content updated'

        codereviews = PullLineComment.gets_by_target_and_ref(
            p1_t1.id, from_sha)
        assert len(codereviews) == 1
        p1_t1.add_codereview(from_sha, '', path, path, oid, oid,
                             LINECOMMENT_INDEX_EMPTY, LINECOMMENT_INDEX_EMPTY,
                             author, 'another comment content')
        codereviews = PullLineComment.gets_by_target_and_ref(
            p1_t1.id, from_sha)
        assert len(codereviews) == 2

        # test delete comment
        codereview.delete()
        codereviews = PullLineComment.gets_by_target_and_ref(
            p1_t1.id, from_sha)
        assert len(codereviews) == 1
示例#35
0
    def test_ticket_code_review(self):
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'
        p1_t1 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq1 = PullRequest.open(
            self.proj1_fork, 'master', self.proj1, 'master')
        pullreq1 = pullreq1.insert(p1_t1.ticket_number)

        # ticket code review
        path = '/README.md'
        #position = 10
        from_sha = '454418c61cd7ef1a65818121746b45064a5af5d6'
        oid = '454418c61cd7ef1a65818121746b45064a5af5d6'
        codereview = p1_t1.add_codereview(
            from_sha, '', path, path, oid, oid, LINECOMMENT_INDEX_EMPTY,
            LINECOMMENT_INDEX_EMPTY, author, 'comment content')
        assert codereview.ticket_id == p1_t1.id
        assert codereview.path == path
        assert codereview.from_sha == from_sha

        #test update content
        assert codereview.content == 'comment content'
        codereview.update('content updated')
        codereview = PullLineComment.get(codereview.id)
        assert codereview.content == 'content updated'

        codereviews = PullLineComment.gets_by_target_and_ref(
            p1_t1.id, from_sha)
        assert len(codereviews) == 1
        p1_t1.add_codereview(
            from_sha, '', path, path, oid, oid, LINECOMMENT_INDEX_EMPTY,
            LINECOMMENT_INDEX_EMPTY, author, 'another comment content')
        codereviews = PullLineComment.gets_by_target_and_ref(
            p1_t1.id, from_sha)
        assert len(codereviews) == 2

        #test delete comment
        codereview.delete()
        codereviews = PullLineComment.gets_by_target_and_ref(
            p1_t1.id, from_sha)
        assert len(codereviews) == 1
示例#36
0
    def test_conflict_detection(self):
        """有冲突存在时,is_auto_mergable()应返回False"""
        with mkdtemp() as tmpdir:
            path, repo, fork_path, fork_repo = setup_repos(
                tmpdir, 'test_conflict_detection')

            # make conflict changes

            with clone(path) as work_path:
                with open(join(work_path, 'a'), 'w') as f:
                    f.write("asdf")

            with clone(fork_path) as work_path:
                with open(join(work_path, 'a'), 'w') as f:
                    f.write("fdsa")

            # submit a pull request

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            assert not pullreq.is_auto_mergable()
            # assure merge --abort
            assert not os.path.exists(os.path.join(path, 'MERGE_MODE'))
示例#37
0
    def test_conflict_detection(self):
        """有冲突存在时,is_auto_mergable()应返回False"""
        with mkdtemp() as tmpdir:
            path, repo, fork_path, fork_repo = setup_repos(
                tmpdir, 'test_conflict_detection')

            # make conflict changes

            with clone(path) as work_path:
                with open(join(work_path, 'a'), 'w') as f:
                    f.write("asdf")

            with clone(fork_path) as work_path:
                with open(join(work_path, 'a'), 'w') as f:
                    f.write("fdsa")

            # submit a pull request

            pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
            assert not pullreq.is_auto_mergable()
            # assure merge --abort
            assert not os.path.exists(os.path.join(path, 'MERGE_MODE'))
示例#38
0
文件: diff.py 项目: 000fan000/code
    def _toggle_whitespace(self, request, project, paths, ignore_space,
                           **kwargs):
        # For pull/new
        from_proj = request.get_form_var('from_proj')
        from_ref = request.get_form_var('from_ref')
        to_ref = request.get_form_var('to_ref')
        to_proj = request.get_form_var('to_proj')

        sha1 = kwargs.get('sha1')
        context_lines = kwargs.get('context_lines')
        ref = sha1
        if ref is None:
            ref = project.default_branch
        if hasattr(self, 'ticket'):
            pullreq = PullRequest.get_by_proj_and_ticket(
                project.id, self.ticket.ticket_number)
            linecomments = PullLineComment.gets_by_target(self.ticket.id)
        else:
            from_proj = CodeDoubanProject.get_by_name(from_proj)
            parent_proj = from_proj.get_forked_from()
            if to_proj:
                to_proj = CodeDoubanProject.get_by_name(to_proj)
            elif parent_proj:
                to_proj = parent_proj
            else:
                to_proj = from_proj
            pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
            linecomments = []

        kw = {
            'paths': paths,
            'rename_detection': True,
            'linecomments': linecomments
        }
        if context_lines is not None:
            kw.update({'context_lines': context_lines})
        diff = pullreq.get_diff(**kw)
        return diff
示例#39
0
文件: diff.py 项目: jackfrued/code-1
    def _toggle_whitespace(self, request, project, paths, ignore_space,
                           **kwargs):
        # For pull/new
        from_proj = request.get_form_var('from_proj')
        from_ref = request.get_form_var('from_ref')
        to_ref = request.get_form_var('to_ref')
        to_proj = request.get_form_var('to_proj')

        sha1 = kwargs.get('sha1')
        context_lines = kwargs.get('context_lines')
        ref = sha1
        if ref is None:
            ref = project.default_branch
        if hasattr(self, 'ticket'):
            pullreq = PullRequest.get_by_proj_and_ticket(
                project.id, self.ticket.ticket_number)
            linecomments = PullLineComment.gets_by_target(self.ticket.id)
        else:
            from_proj = CodeDoubanProject.get_by_name(from_proj)
            parent_proj = from_proj.get_forked_from()
            if to_proj:
                to_proj = CodeDoubanProject.get_by_name(to_proj)
            elif parent_proj:
                to_proj = parent_proj
            else:
                to_proj = from_proj
            pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
            linecomments = []

        kw = {
            'paths': paths,
            'rename_detection': True,
            'linecomments': linecomments
        }
        if context_lines is not None:
            kw.update({'context_lines': context_lines})
        diff = pullreq.get_diff(**kw)
        return diff
示例#40
0
文件: pulls.py 项目: 000fan000/code
    def post(self, request):
        """
        title
        body
        to_ref
        from_project
        from_ref
        """
        user = request.user
        if not request.data:
            raise NotJSONError
        data = request.data

        title = data.get('title').decode('utf8')
        body = data.get('body').decode('utf8')
        base_ref = data.get('base_ref')
        head = data.get('head')
        head_repo = data.get('head_repo')

        from_proj = head_repo
        from_ref = head
        to_ref = base_ref
        to_proj = self.repo
        if not all([from_ref, from_proj, to_ref, to_proj, title]):
            # FIXME: more details
            raise api_errors.UnprocessableEntityError

        from_proj = CodeDoubanProject.get_by_name(from_proj)

        if not from_proj.has_push_perm(user.name):
            raise api_errors.NoPushPermissionError

        pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
        ticket = Ticket(None, None, to_proj.id, title, body, user.username,
                        None,
                        None)
        pullreq = add_pull(ticket, pullreq, user)
        return pullreq.as_dict()
示例#41
0
    def test_ticket_comment(self):
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'
        p1_t1 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq1 = PullRequest.open(self.proj1_fork, 'master', self.proj1,
                                    'master')
        pullreq1 = pullreq1.insert(p1_t1.ticket_number)

        # add ticket comment
        comment = p1_t1.add_comment('comment contet', author)
        assert comment is not None

        # update ticket_comment
        assert comment.content == 'comment contet'
        comment.update('comment content updated')
        comment = TicketComment.get(id=comment.id)
        assert comment.content == 'comment content updated'

        # delete ticket_comment
        assert len(TicketComment.gets_by_ticketid(p1_t1.id)) == 1
        comment.delete()
        assert TicketComment.gets_by_ticketid(p1_t1.id) == []
示例#42
0
    def test_ticket_comment(self):
        title = 'test title'
        desc = 'test desc'
        author = 'testuser'
        p1_t1 = Ticket.add(self.proj1.id, title, desc, author)
        pullreq1 = PullRequest.open(
            self.proj1_fork, 'master', self.proj1, 'master')
        pullreq1 = pullreq1.insert(p1_t1.ticket_number)

        # add ticket comment
        comment = p1_t1.add_comment('comment contet', author)
        assert comment is not None

        # update ticket_comment
        assert comment.content == 'comment contet'
        comment.update('comment content updated')
        comment = TicketComment.get(id=comment.id)
        assert comment.content == 'comment content updated'

        # delete ticket_comment
        assert len(TicketComment.gets_by_ticketid(p1_t1.id)) == 1
        comment.delete()
        assert TicketComment.gets_by_ticketid(p1_t1.id) == []
示例#43
0
    def post(self, request):
        """
        title
        body
        to_ref
        from_project
        from_ref
        """
        user = request.user
        if not request.data:
            raise NotJSONError
        data = request.data

        title = data.get('title').decode('utf8')
        body = data.get('body').decode('utf8')
        base_ref = data.get('base_ref')
        head = data.get('head')
        head_repo = data.get('head_repo')

        from_proj = head_repo
        from_ref = head
        to_ref = base_ref
        to_proj = self.repo
        if not all([from_ref, from_proj, to_ref, to_proj, title]):
            # FIXME: more details
            raise api_errors.UnprocessableEntityError

        from_proj = CodeDoubanProject.get_by_name(from_proj)

        if not from_proj.has_push_perm(user.name):
            raise api_errors.NoPushPermissionError

        pullreq = PullRequest.open(from_proj, from_ref, to_proj, to_ref)
        ticket = Ticket(None, None, to_proj.id, title, body, user.username,
                        None, None)
        pullreq = add_pull(ticket, pullreq, user)
        return pullreq.as_dict()
示例#44
0
 def test_get_merge_base(self):
     """应该能够得到merge_base,即from_sha、to_sha的最近公共父commit sha"""
     with setup2repos('prj5') as (path, repo, fork_path, fork_repo):
         pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
         merge_base = pullreq.merge_base
         assert merge_base is not None
示例#45
0
文件: add_pr.py 项目: 000fan000/code
if p2_id:
    store.execute("delete from pullreq where from_project=%s", p2_id)
store.commit()


def setup2repos(proj1, proj2):
    path = proj1.git_real_path
    with clone(path) as workdir:
        with open(join(workdir, 'origin'), 'w') as f:
            f.write('origin')

    path = proj2.git_real_path
    with clone(path) as workdir:
        with open(join(workdir, 'origin'), 'w') as f:
            f.write('modified')

project = Project.add(
    p1_name, owner_id="testuser", summary="test", product="")
assert project
project_fork = Project.add(
    p2_name, owner_id="testuser", summary="test", product="",
    fork_from=project.id)

setup2repos(project, project_fork)

pullreq1 = PullRequest.open(project_fork, 'master', project, 'master')
ticket1 = Ticket.add(project.id, 'title', 'content', 'testuser')
pullreq1.insert(ticket1.ticket_number)

print "PR has been built at: %s" % (DOMAIN + ticket1.url)
示例#46
0
store.commit()


def setup2repos(proj1, proj2):
    path = proj1.git_real_path
    with clone(path) as workdir:
        with open(join(workdir, 'origin'), 'w') as f:
            f.write('origin')

    path = proj2.git_real_path
    with clone(path) as workdir:
        with open(join(workdir, 'origin'), 'w') as f:
            f.write('modified')


project = Project.add(p1_name, owner_id="testuser", summary="test", product="")
assert project
project_fork = Project.add(p2_name,
                           owner_id="testuser",
                           summary="test",
                           product="",
                           fork_from=project.id)

setup2repos(project, project_fork)

pullreq1 = PullRequest.open(project_fork, 'master', project, 'master')
ticket1 = Ticket.add(project.id, 'title', 'content', 'testuser')
pullreq1.insert(ticket1.ticket_number)

print "PR has been built at: %s" % (DOMAIN + ticket1.url)
示例#47
0
 def test_get_merge_base(self):
     """应该能够得到merge_base,即from_sha、to_sha的最近公共父commit sha"""
     with setup2repos('prj5') as (path, repo, fork_path, fork_repo):
         pullreq = PullRequest.open(fork_repo, 'master', repo, 'master')
         merge_base = pullreq.merge_base
         assert merge_base is not None