def add_pull(ticket, pullreq, user): from dispatches import dispatch from vilya.libs.text import get_mentions_from_text from vilya.libs.signals import pullrequest_signal from vilya.models.user import get_author_by_email from vilya.models.user import User from vilya.models.trello.core import process_trello_notify reporter = user.username commits = pullreq.commits # TODO: refactory is! auto number how to? shas = [p.sha for p in commits] ticket_len = Ticket.get_count_by_proj_id(ticket.project_id) if ticket_len == 0: # 检查是否创建过新PR,若未创建过则以旧PR号为基准累加 max_ticket_id = PullRequest.get_max_ticket_id(ticket.project_id) if max_ticket_id >= 0: ticket = Ticket.add(ticket.project_id, ticket.title, ticket.description, ticket.author, max_ticket_id + 1) else: ticket = Ticket.add(ticket.project_id, ticket.title, ticket.description, ticket.author) else: ticket = Ticket.add(ticket.project_id, ticket.title, ticket.description, ticket.author) pullreq = pullreq.insert(ticket.ticket_number) if shas: ticket.add_commits(','.join(shas), reporter) noti_receivers = [committer.name for committer in CodeDoubanProject.get_committers_by_project(pullreq.to_proj.id)] # noqa noti_receivers = noti_receivers + [pullreq.to_proj.owner.name] get_commit_author = lambda u: get_author_by_email(u.email.encode('utf-8')) commit_authors = {get_commit_author(c.author) for c in commits} commit_authors = {a for a in commit_authors if a} noti_receivers.extend(commit_authors) # diffs, author_by_file, authors = pullreq.get_diffs(with_blame=True) # FIXME: diffs没用到? # diffs = pullreq.get_diffs() # blame代码变更的原作者, 也加到at users at_users = get_mentions_from_text(ticket.description) # at_users.extend(authors) at_users.append(pullreq.to_proj.owner_id) at_users = set(at_users) # FIXME: invited_users is used on page /hub/my_pull_requests/ invited_users = [User(u).add_invited_pull_request(ticket.id) for u in at_users] ProjectOwnLRUCounter(user.username).use(pullreq.to_proj.id) ProjectWatchLRUCounter(user.username).use(pullreq.to_proj.id) # TODO: 重构Feed之后取消这个信号的发送 pullrequest_signal.send(user.username, extra_receivers=noti_receivers, pullreq=pullreq, comment=ticket.description, ticket_id=ticket.ticket_id, ticket=ticket, status="unmerge", new_version=True) dispatch('pullreq', data=dict(sender=user.username, content=ticket.description, ticket=ticket, status='unmerge', new_version=True, extra_receivers=noti_receivers)) dispatch('pr_actions', data=dict(type='pr_opened', hooks=pullreq.to_proj.hooks, author=user, title=ticket.title, body=ticket.description, ticket=ticket, pullreq=pullreq)) # FIXME: move to dispatch process_trello_notify(user, ticket) return pullreq
def add_pull(ticket, pullreq, user): from dispatches import dispatch from vilya.libs.text import get_mentions_from_text from vilya.libs.signals import pullrequest_signal from vilya.models.user import get_author_by_email from vilya.models.user import User from vilya.models.trello.core import process_trello_notify reporter = user.username commits = pullreq.commits # TODO: refactory is! auto number how to? shas = [p.sha for p in commits] ticket_len = Ticket.get_count_by_proj_id(ticket.project_id) if ticket_len == 0: # 检查是否创建过新PR,若未创建过则以旧PR号为基准累加 max_ticket_id = PullRequest.get_max_ticket_id(ticket.project_id) if max_ticket_id >= 0: ticket = Ticket.add(ticket.project_id, ticket.title, ticket.description, ticket.author, max_ticket_id + 1) else: ticket = Ticket.add(ticket.project_id, ticket.title, ticket.description, ticket.author) else: ticket = Ticket.add(ticket.project_id, ticket.title, ticket.description, ticket.author) pullreq = pullreq.insert(ticket.ticket_number) if shas: ticket.add_commits(','.join(shas), reporter) noti_receivers = [ committer.name for committer in CodeDoubanProject.get_committers_by_project(pullreq.to_proj.id) ] # noqa noti_receivers = noti_receivers + [pullreq.to_proj.owner.name] get_commit_author = lambda u: get_author_by_email(u.email.encode('utf-8')) commit_authors = {get_commit_author(c.author) for c in commits} commit_authors = {a for a in commit_authors if a} noti_receivers.extend(commit_authors) # diffs, author_by_file, authors = pullreq.get_diffs(with_blame=True) # FIXME: diffs没用到? # diffs = pullreq.get_diffs() # blame代码变更的原作者, 也加到at users at_users = get_mentions_from_text(ticket.description) # at_users.extend(authors) at_users.append(pullreq.to_proj.owner_id) at_users = set(at_users) # FIXME: invited_users is used on page /hub/my_pull_requests/ invited_users = [ User(u).add_invited_pull_request(ticket.id) for u in at_users ] ProjectOwnLRUCounter(user.username).use(pullreq.to_proj.id) ProjectWatchLRUCounter(user.username).use(pullreq.to_proj.id) # TODO: 重构Feed之后取消这个信号的发送 pullrequest_signal.send(user.username, extra_receivers=noti_receivers, pullreq=pullreq, comment=ticket.description, ticket_id=ticket.ticket_id, ticket=ticket, status="unmerge", new_version=True) dispatch('pullreq', data=dict(sender=user.username, content=ticket.description, ticket=ticket, status='unmerge', new_version=True, extra_receivers=noti_receivers)) dispatch('pr_actions', data=dict(type='pr_opened', hooks=pullreq.to_proj.hooks, author=user, title=ticket.title, body=ticket.description, ticket=ticket, pullreq=pullreq)) # FIXME: move to dispatch process_trello_notify(user, ticket) return pullreq