def contribution_detail(self, request): req_date = request.get_form_var("date") if req_date: try: req_date = dateutil.parser.parse(req_date).astimezone(dateutil.tz.tzoffset("EST", 8 * 3600)) except ValueError as e: return "" contributions = UserContributions.get_by_date(self.name, req_date) owned = contributions.get("owned_tickets") commented = contributions.get("commented_tickets") owned_tickets = filter(None, [Ticket.get(id_) for id_ in owned]) commented_tickets = filter(None, [Ticket.get(comment[0]) for comment in commented]) return st("people_contribution_detail.html", **locals()) return ""
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(cls, target_id, from_sha, to_sha, old_path, new_path, from_oid, to_oid, old_linenum, new_linenum, author, content): # TODO: dispatch 放到 view 里 from vilya.models.ticket import Ticket from vilya.libs.signals import codereview_signal from dispatches import dispatch comment = super(PullLineComment, cls).add(target_id, from_sha, to_sha, old_path, new_path, from_oid, to_oid, old_linenum, new_linenum, author, content) ticket = Ticket.get(target_id) # TODO: 重构feed之后取消signal发送 if ticket: codereview_signal.send(comment, content=content, ticket=ticket, author=author, comment=comment) dispatch('codereview', data={ 'comment': comment, 'ticket': ticket, 'sender': author, }) return comment
def contribution_detail(self, request): req_date = request.get_form_var('date') if req_date: try: req_date = dateutil.parser.parse(req_date).astimezone( dateutil.tz.tzoffset('EST', 8 * 3600)) except ValueError as e: return "" contributions = UserContributions.get_by_date(self.name, req_date) owned = contributions.get('owned_tickets') commented = contributions.get('commented_tickets') owned_tickets = filter(None, [Ticket.get(id_) for id_ in owned]) commented_tickets = filter( None, [Ticket.get(comment[0]) for comment in commented]) return st('people_contribution_detail.html', **locals()) return ""
def contribution_detail(self, request): req_date = request.get_form_var('date') if not req_date: return {"error": "No datetime"} try: req_date = dateutil.parser.parse(req_date).astimezone( dateutil.tz.tzoffset('EST', 8 * 3600)) except ValueError: return {"error": "Invalid date"} contributions = UserContributions.get_by_date(self.user.name, req_date) owned = contributions.get('owned_tickets') commented = contributions.get('commented_tickets') pullreqs = [Ticket.get(id_).as_dict() for id_ in owned] participated = [Ticket.get(comment[0]).as_dict() for comment in commented] return {"pull requests": pullreqs, "participated": participated}
def contribution_detail(self, request): req_date = request.get_form_var('date') if not req_date: return {"error": "No datetime"} try: req_date = dateutil.parser.parse(req_date).astimezone( dateutil.tz.tzoffset('EST', 8 * 3600)) except ValueError: return {"error": "Invalid date"} contributions = UserContributions.get_by_date(self.user.name, req_date) owned = contributions.get('owned_tickets') commented = contributions.get('commented_tickets') pullreqs = [Ticket.get(id_).as_dict() for id_ in owned] participated = [ Ticket.get(comment[0]).as_dict() for comment in commented ] return {"pull requests": pullreqs, "participated": participated}
def _clean_closed_tickets(self): from vilya.models.ticket import Ticket # FIXME should be async function tickets = set(self.get_invited() + self.get_participated()) for ticket_id in tickets: t = Ticket.get(ticket_id) if t and t.project and not t.closed: continue self.remove_invited(ticket_id) self.remove_participated(ticket_id)
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 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
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 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
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
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
def after_create(self, extra_args): from vilya.models.ticket import Ticket comment = self TicketNode.add_comment(comment) content = extra_args bdb.set(BDB_TICKET_COMMENT_CONTENT_KEY % self.id, content) ticket = Ticket.get(self.ticket_id) # TODO: 将Feed全部迁移到新的系统后,取消signal发送 codereview_signal.send(comment, content=content, ticket=ticket, author=self.author, comment=comment) dispatch('codereview', data={ 'comment': comment, 'ticket': ticket, 'sender': self.author, })
def add(cls, target_id, from_sha, to_sha, old_path, new_path, from_oid, to_oid, old_linenum, new_linenum, author, content): # TODO: dispatch 放到 view 里 from vilya.models.ticket import Ticket from vilya.libs.signals import codereview_signal from dispatches import dispatch comment = super(PullLineComment, cls).add( target_id, from_sha, to_sha, old_path, new_path, from_oid, to_oid, old_linenum, new_linenum, author, content) ticket = Ticket.get(target_id) # TODO: 重构feed之后取消signal发送 if ticket: codereview_signal.send(comment, content=content, ticket=ticket, author=author, comment=comment) dispatch('codereview', data={ 'comment': comment, 'ticket': ticket, 'sender': author, }) return comment
def target(self): from vilya.models.ticket import Ticket return Ticket.get(self.target_id)
def get_participated_pull_requests(self, is_closed=False): from vilya.models.ticket import Ticket return [ Ticket.get(ticket_id) for ticket_id in UserPullRequests( self.username).get_participated(is_closed) ]
def get_participated_pull_requests(self, is_closed=False): from vilya.models.ticket import Ticket return [Ticket.get(ticket_id) for ticket_id in UserPullRequests( self.username).get_participated(is_closed)]
def _q_lookup(request, uid): if uid.isdigit(): ticket = Ticket.get(uid) if ticket: return TicketUI(ticket) raise TraversalError