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
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)))
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)))
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
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
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
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()