def _index(self, request): user = self.user yours = user.get_user_submit_pull_requests() participated = user.get_participated_pull_requests() invited = user.get_invited_pull_requests() yours_list = [PullRequest.get_by_ticket(ticket).as_dict() for ticket in yours] participated_list = [PullRequest.get_by_ticket(ticket).as_dict() for ticket in participated] invited_list = [PullRequest.get_by_ticket(ticket).as_dict() for ticket in invited] yours_list = filter(lambda t: t, yours_list) participated = filter(lambda t: t, participated) invited_list = filter(lambda t: t, invited_list) rs = [] if yours_list: rs.append({'section': 'Yours', 'pulls': yours_list}) if participated_list: rs.append({'section': 'Participated', 'pulls': participated_list}) if invited_list: rs.append({'section': 'Invited', 'pulls': invited_list}) return rs
def _index(self, request): user = self.user yours = user.get_user_submit_pull_requests() participated = user.get_participated_pull_requests() invited = user.get_invited_pull_requests() yours_list = [ PullRequest.get_by_ticket(ticket).as_dict() for ticket in yours ] participated_list = [ PullRequest.get_by_ticket(ticket).as_dict() for ticket in participated ] invited_list = [ PullRequest.get_by_ticket(ticket).as_dict() for ticket in invited ] yours_list = filter(lambda t: t, yours_list) participated = filter(lambda t: t, participated) invited_list = filter(lambda t: t, invited_list) rs = [] if yours_list: rs.append({'section': 'Yours', 'pulls': yours_list}) if participated_list: rs.append({'section': 'Participated', 'pulls': participated_list}) if invited_list: rs.append({'section': 'Invited', 'pulls': invited_list}) return rs
def main(): rs = store.execute("select id " "from codedouban_ticket") for r in rs: id, = r ticket = Ticket.get(id) # update merge pullreq = PullRequest.get_by_ticket(ticket) author = pullreq.merge_by or pullreq.to_proj.owner_id time = pullreq.merge_time ticket_id = ticket.id id = 0 if not get_node(author, TICKET_NODE_TYPE_MERGE, id, ticket_id, time) and time: print id, author, time, ticket_id store.execute("insert into ticket_nodes " "(author, type, type_id, ticket_id, created_at) " "value (%s, %s, %s, %s, %s)", (author, TICKET_NODE_TYPE_MERGE, id, ticket_id, time)) store.commit() # update close author = ticket.close_by or ticket.author time = ticket.closed ticket_id = ticket.id id = 0 if not get_node(author, TICKET_NODE_TYPE_CLOSE, id, ticket_id, time) and time: print id, author, time, ticket_id store.execute("insert into ticket_nodes " "(author, type, type_id, ticket_id, created_at) " "value (%s, %s, %s, %s, %s)", (author, TICKET_NODE_TYPE_CLOSE, id, ticket_id, time)) store.commit() print "update %s close & merge pulls" % len(rs)
def add_code_review_action(sender, **kw): data = format_code_review_info(sender, **kw) ticket = kw['ticket'] author = kw['author'] pullreq = PullRequest.get_by_ticket(ticket) feeds = get_related_feeds(author, pullreq.to_proj) for feed in feeds: feed.add_action(data)
def add_code_review_action(sender, **kw): data = format_code_review_info(sender, **kw) ticket = kw['ticket'] author = kw['author'] pullreq = PullRequest.get_by_ticket(ticket) feeds = get_related_feeds(author, pullreq.to_proj) for feed in feeds: feed.add_action(data)
def __init__(self, data): NotificationDispatcher.__init__(self, data) self._sender = data.get('sender') self._comment = data.get('comment') self._content = self._comment.content if self._comment else data.get('content', '') self._ticket = data.get('ticket') self._pullreq = PullRequest.get_by_ticket(self._ticket) self._target = self._pullreq.to_proj self._is_ticketcomment = isinstance(self._comment, TicketComment)
def _latest_update_branch(project, ref, user): if user: get_pr = user.get_user_submit_pull_requests latest_tickets = get_pr(limit=5, is_closed=False) + get_pr(limit=5, is_closed=True) latest_tickets = filter(None, [PullRequest.get_by_ticket(t) for t in latest_tickets if t.project]) has_pr_branches = [t.from_ref for t in latest_tickets] else: has_pr_branches = [] latest_update_branches = filter( lambda b: b[1] != ref and b[1] not in has_pr_branches, project.repo.get_latest_update_branches() ) latest_update_branch = latest_update_branches[0][1] if latest_update_branches else "" return latest_update_branch
def _latest_update_branch(project, ref, user): if user: get_pr = user.get_user_submit_pull_requests latest_tickets = get_pr(limit=5, is_closed=False) + get_pr( limit=5, is_closed=True) latest_tickets = filter(None, [PullRequest.get_by_ticket(t) for t in latest_tickets if t.project]) has_pr_branches = [t.from_ref for t in latest_tickets] else: has_pr_branches = [] latest_update_branches = filter(lambda b: b[1] != ref and b[1] not in has_pr_branches, project.repo.get_latest_update_branches()) latest_update_branch = (latest_update_branches[0][1] if latest_update_branches else '') return latest_update_branch
def add_code_review(self, ticket, author, text, commit_id): ticket_fields = ticket.values from vilya.models.pull import PullRequest pullreq = PullRequest.get_by_ticket(ticket) uid = 'codereview-%s-%s-%s' % (pullreq.to_proj, ticket.id, commit_id) data = dict( date=datetime.now(), url="/%s/pull/%s" % (pullreq.to_proj, ticket.id), ticket=ticket.id, proj="%s:%s" % (pullreq.to_proj, pullreq.to_branch), receiver=ticket_fields['reporter'], author=author, text=text, uid=uid, ) self.add_code_review_data(data)
def add_code_review(self, ticket, author, text, commit_id): ticket_fields = ticket.values from vilya.models.pull import PullRequest pullreq = PullRequest.get_by_ticket(ticket) uid = 'codereview-%s-%s-%s' % (pullreq.to_proj, ticket.id, commit_id) data = dict( date=datetime.now(), url="/%s/pull/%s" % (pullreq.to_proj, ticket.id), ticket=ticket.id, proj="%s:%s" % (pullreq.to_proj, pullreq.to_branch), receiver=ticket_fields['reporter'], author=author, text=text, uid=uid, ) self.add_code_review_data(data)
def format_code_review_info(sender, **kw): from vilya.models.pull import PullRequest comment = kw['comment'] anchor_id = comment.uid ticket = kw['ticket'] author = kw['author'] content = kw['content'] ticket_id = ticket.ticket_id pullreq = PullRequest.get_by_ticket(ticket) uid = 'newcodereview-%s-%s-%s' % (pullreq.to_proj, ticket_id, comment.id) type = 'code_review' data = dict( date=datetime.now(), url="/%s/pull/%s/#%s" % (pullreq.to_proj, ticket_id, anchor_id), ticket=ticket_id, proj="%s:%s" % (pullreq.to_proj, pullreq.to_branch), receiver=ticket.author, author=author, text=content, uid=uid, type=type, ) return data