def get(self, request): _date_from = None _date_to = None state = request.get_form_var('state', '') author = request.get_form_var('author', '') date_from = request.get_form_var('from', '') date_to = request.get_form_var('to', '') if not state or state == "open": closed = False else: closed = True if date_from: _date_from = date_from if date_to: _date_to = date_to tickets = Ticket.gets(project_id=self.repo.id, author=author, date_from=_date_from, date_to=_date_to, closed=closed) pulls = [] for t in tickets: pull = PullRequest.get_by_proj_and_ticket(self.repo.id, t.ticket_number) pulls.append(pull.as_dict()) return pulls
def __init__(self, ticket): self.project = CodeDoubanProject.get(ticket.project_id) self.proj_name = self.project.name self.ticket_id = ticket.ticket_number self.ticket = ticket self.pullreq = PullRequest.get_by_proj_and_ticket( self.project.id, self.ticket_id)
def get(self, request): _date_from = None _date_to = None state = request.get_form_var('state', '') author = request.get_form_var('author', '') date_from = request.get_form_var('from', '') date_to = request.get_form_var('to', '') if not state or state == "open": closed = False else: closed = True if date_from: _date_from = date_from if date_to: _date_to = date_to tickets = Ticket.gets(project_id=self.repo.id, author=author, date_from=_date_from, date_to=_date_to, closed=closed) pulls = [] for t in tickets: pull = PullRequest.get_by_proj_and_ticket(self.repo.id, t.ticket_number) pulls.append(pull.as_dict()) return pulls
def open_pulls(self): from vilya.models.ticket import Ticket from vilya.models.pull import PullRequest pulls = [PullRequest.get_by_proj_and_ticket(self.id, t.ticket_id) for t in Ticket.gets_by_proj(self.id, limit=9999)] return pulls
def open_pulls(self): from vilya.models.ticket import Ticket from vilya.models.pull import PullRequest pulls = [PullRequest.get_by_proj_and_ticket(self.id, t.ticket_id) for t in Ticket.gets_by_proj(self.id, limit=9999)] return pulls
def index_a_project_pr(cls, project): rs = store.execute("select ticket_id from pullreq " "where to_project=%s", project.id) for r, in rs: pr = PullRequest.get_by_proj_and_ticket(project.id, r) if pr: data = pr.as_dict() if data: serial = "%s_%s" % (project.index_name, r) cls.index_an_object(serial, data)
def commits(self, request): if not self.ticket: raise TraversalError() pr = PullRequest.get_by_proj_and_ticket( self.project.id, self.ticket.ticket_number) commits = pr.get_commits_shas() commits = [TicketCommits.commit_as_dict(self.project, c) for c in commits] # commits = reduce(lambda x, y: x + y, commits) return commits
def _index(self, request): project = CodeDoubanProject.get_by_name(self.proj_name) open_tickets = Ticket.gets_by_proj(project.id, limit=9999) pr_list = [] for t in open_tickets: pullreq = PullRequest.get_by_proj_and_ticket(project.id, t.ticket_number) if pullreq: pr_list.append(pullreq.as_dict()) return pr_list
def _index(self, request): project = CodeDoubanProject.get_by_name(self.proj_name) open_tickets = Ticket.gets_by_proj(project.id, limit=9999) pr_list = [] for t in open_tickets: pullreq = PullRequest.get_by_proj_and_ticket( project.id, t.ticket_number) if pullreq: pr_list.append(pullreq.as_dict()) return pr_list
def __init__(self, project_id, ticket_id): self.project_id = project_id self.ticket_id = ticket_id self.ticket = Ticket.get_by_projectid_and_ticketnumber( self.project_id, self.ticket_id) if not self.ticket: raise NotFoundError('pull') self.pullreq = PullRequest.get_by_proj_and_ticket( self.project_id, self.ticket.ticket_number)
def __init__(self, proj_name, ticket_id): self.proj_name = proj_name self.ticket_id = ticket_id self.project = CodeDoubanProject.get_by_name(proj_name) self.ticket = Ticket.get_by_projectid_and_ticketnumber( self.project.id, self.ticket_id) self.pullreq = PullRequest.get_by_proj_and_ticket( self.project.id, self.ticket_id) try: self.all_commits = self.pullreq.commits except Exception: self.all_commits = self.pullreq.get_merged_commits()
def __init__(self, proj_name, ticket_id): self.proj_name = proj_name self.ticket_id = ticket_id self.project = CodeDoubanProject.get_by_name(proj_name) self.ticket = Ticket.get_by_projectid_and_ticketnumber( self.project.id, self.ticket_id) self.pullreq = PullRequest.get_by_proj_and_ticket( self.project.id, self.ticket_id) try: self.all_commits = self.pullreq.commits except Exception: self.all_commits = self.pullreq.get_merged_commits()
def commits(self, request): if not self.ticket: raise TraversalError() pr = PullRequest.get_by_proj_and_ticket(self.project.id, self.ticket.ticket_number) commits = pr.get_commits_shas() commits = [ TicketCommits.commit_as_dict(self.project, c) for c in commits ] # commits = reduce(lambda x, y: x + y, commits) return commits
def __init__(self, project_id, ticket_id): self.project_id = project_id self.ticket_id = ticket_id self.ticket = Ticket.get_by_projectid_and_ticketnumber(self.project_id, self.ticket_id) if not self.ticket: raise NotFoundError('pull') self.pullreq = PullRequest.get_by_proj_and_ticket( self.project_id, self.ticket.ticket_number)
def close(self, request): user = request.user if user: ticket = self.ticket pullreq = PullRequest.get_by_proj_and_ticket( self.project.id, self.ticket.ticket_number) comment = ticket.add_comment('close pr', user.name) error = close_pull(self.ticket, pullreq, user, 'close pr', comment, request) if error: raise NoPushPermissionError(error) return {'ok': True} raise UnauthorizedError
def open_parent_pulls(self): from vilya.models.ticket import Ticket from vilya.models.pull import PullRequest pulls = [] parent = self.get_forked_from() if parent: pulls = [PullRequest.get_by_proj_and_ticket(parent.id, t.ticket_id) for t in Ticket.gets_by_proj(parent.id, limit=9999)] pulls = [p for p in pulls if p and p.from_proj and p.from_proj.id == self.id] return pulls
def merge(self, request): user = request.user if user: pullreq = PullRequest.get_by_proj_and_ticket( self.project.id, self.ticket.ticket_number) if pullreq.merged: return {'ok': True} error = merge_pull(self.ticket, pullreq, user, '', request) if error: raise NoPushPermissionError(error) else: return {'ok': True} raise UnauthorizedError
def open_network_pulls(self): from vilya.models.ticket import Ticket from vilya.models.pull import PullRequest pulls = [] projects = self.get_fork_network() for project in projects: ps = [PullRequest.get_by_proj_and_ticket(project.id, t.ticket_id) for t in Ticket.gets_by_proj(project.id, limit=9999)] pulls.extend([p for p in ps if p and p.from_proj and p.from_proj.id == self.id]) return pulls + self.open_pulls
def open_parent_pulls(self): from vilya.models.ticket import Ticket from vilya.models.pull import PullRequest pulls = [] parent = self.get_forked_from() if parent: pulls = [PullRequest.get_by_proj_and_ticket(parent.id, t.ticket_id) for t in Ticket.gets_by_proj(parent.id, limit=9999)] pulls = [p for p in pulls if p and p.from_proj and p.from_proj.id == self.id] return pulls
def open_network_pulls(self): from vilya.models.ticket import Ticket from vilya.models.pull import PullRequest pulls = [] projects = self.get_fork_network() for project in projects: ps = [PullRequest.get_by_proj_and_ticket(project.id, t.ticket_id) for t in Ticket.gets_by_proj(project.id, limit=9999)] pulls.extend([p for p in ps if p and p.from_proj and p.from_proj.id == self.id]) return pulls + self.open_pulls
def gen_telchar_data(data): ticket_id = data.get('ticket_id') ticket = Ticket.get(ticket_id) pullreq = PullRequest.get_by_proj_and_ticket( ticket.project.id, ticket.ticket_id) fork_from = pullreq.from_proj.fork_from fork_from = pullreq.from_proj.get(fork_from).url if fork_from else None return { 'ticket_id': ticket.ticket_id, 'fork_from': fork_from, 'url': pullreq.from_proj.url, 'to_sha': pullreq.to_sha, 'from_sha': pullreq.from_sha }
def merge(self, request): user = request.user if user: pullreq = PullRequest.get_by_proj_and_ticket( self.project.id, self.ticket.ticket_number) if pullreq.merged: return {'ok': True} error = merge_pull(self.ticket, pullreq, user, '', request) if error: raise NoPushPermissionError(error) else: return {'ok': True} raise UnauthorizedError
def close(self, request): user = request.user if user: ticket = self.ticket pullreq = PullRequest.get_by_proj_and_ticket( self.project.id, self.ticket.ticket_number) comment = ticket.add_comment('close pr', user.name) error = close_pull(self.ticket, pullreq, user, 'close pr', comment, request) if error: raise NoPushPermissionError(error) return {'ok': True} raise UnauthorizedError
def gen_telchar_data(data): ticket_id = data.get('ticket_id') ticket = Ticket.get(ticket_id) pullreq = PullRequest.get_by_proj_and_ticket(ticket.project.id, ticket.ticket_id) fork_from = pullreq.from_proj.fork_from fork_from = pullreq.from_proj.get(fork_from).url if fork_from else None return { 'ticket_id': ticket.ticket_id, 'fork_from': fork_from, 'url': pullreq.from_proj.url, 'to_sha': pullreq.to_sha, 'from_sha': pullreq.from_sha }
def _get_pr_by_project_and_ticket(project, ticket): pull = PullRequest.get_by_proj_and_ticket(project.id, ticket.ticket_id) _from_project = _get_project_by_name(str(pull.from_proj)) if _from_project: _from_project['branch'] = pull.from_branch _to_project = _get_project_by_name(str(pull.to_proj)) if _to_project: _to_project['branch'] = pull.to_branch commits = pull.commits commit = [_format_commit_object_data(c) for c in commits] pr = dict( id=ticket.ticket_id, name=ticket.title, from_project=_from_project, to_project=_to_project, commit=commit, ) return pr
def _index(self, request): project = self.project whitespace = request.get_form_var('whitespace', 'on') is_diff = request.get_form_var('diff') ignore = False if whitespace == 'on' else True pr = PullRequest.get_by_proj_and_ticket(self.project.id, self.ticket.ticket_number) pr_dict = pr.as_dict() if is_diff: diff = pr.get_diff(ignore_space=ignore, rename_detection=True) raw_diff = diff.raw_diff try: del raw_diff['diff'] except KeyError: pass pr_dict['diff'] = raw_diff if request.user: pr_dict['can_push'] = project.has_push_perm(request.user.name) return pr_dict
def _index(self, request): project = self.project whitespace = request.get_form_var('whitespace', 'on') is_diff = request.get_form_var('diff') ignore = False if whitespace == 'on' else True pr = PullRequest.get_by_proj_and_ticket( self.project.id, self.ticket.ticket_number) pr_dict = pr.as_dict() if is_diff: diff = pr.get_diff(ignore_space=ignore, rename_detection=True) raw_diff = diff.raw_diff try: del raw_diff['diff'] except KeyError: pass pr_dict['diff'] = raw_diff if request.user: pr_dict['can_push'] = project.has_push_perm(request.user.name) return pr_dict
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
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
def _q_lookup(self, request, pullid): if request.get_path().find('newpull') > 0: return request.redirect(request.get_path().replace( 'newpull', 'pull')) if pullid.count('.') == 1: pullid, diff_type = pullid.split('.') pr = PullRequest.get_by_proj_and_ticket(self.project.id, pullid) resp = request.response resp.set_header("Content-Type", "text/plain") if diff_type == 'patch' and pr: text = pr.get_format_patch() return text.encode('utf-8') elif diff_type == 'diff' and pr: text = pr.get_diff_tree() return text else: raise TraversalError if pullid.isdigit(): ticket = Ticket.get_by_projectid_and_ticketnumber( self.project.id, pullid) if ticket: return TicketUI(self.proj_name, pullid) raise TraversalError
def _q_lookup(self, request, pullid): if request.get_path().find('newpull') > 0: return request.redirect(request.get_path().replace( 'newpull', 'pull')) if pullid.count('.') == 1: pullid, diff_type = pullid.split('.') pr = PullRequest.get_by_proj_and_ticket(self.project.id, pullid) resp = request.response resp.set_header("Content-Type", "text/plain") if diff_type == 'patch' and pr: text = pr.get_format_patch() return text.encode('utf-8') elif diff_type == 'diff' and pr: text = pr.get_diff_tree() return text else: raise TraversalError if pullid.isdigit(): ticket = Ticket.get_by_projectid_and_ticketnumber( self.project.id, pullid) if ticket: return TicketUI(self.proj_name, pullid) raise TraversalError
def get_ticket_info(ticket): info = PullRequest.get_by_proj_and_ticket(ticket.project_id, ticket.ticket_number).as_dict() return info
def get_ticket_info(ticket): info = PullRequest.get_by_proj_and_ticket(ticket.project_id, ticket.ticket_number).as_dict() return info