Example #1
0
 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)
Example #2
0
 def open_pulls(self):
     from models.ticket import Ticket
     from 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
Example #3
0
 def clear_pull(cls, name, pull_id):
     project = cls.get_by_name(name)
     if not project:
         return None
     from models.pull import PullRequest
     pull = PullRequest.gets_by(to_project=project.id, ticket_id=pull_id,
                                force_flush=True)
     if pull:
         return True
     return None
Example #4
0
 def open_network_pulls(self):
     from models.ticket import Ticket
     from 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
Example #5
0
 def open_parent_pulls(self):
     from models.ticket import Ticket
     from 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
Example #6
0
    def add_code_review(self, ticket, author, text, commit_id):
        ticket_fields = ticket.values
        from 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)
Example #7
0
def format_code_review_info(sender, **kw):
    from 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
Example #8
0
if p2_id:
    store.execute("delete from pullreq where from_project=%s", p2_id)
store.commit()


def setup2repos(proj1, proj2):
    path = proj1.git_real_path
    with clone(path) as workdir:
        with open(join(workdir, 'origin'), 'w') as f:
            f.write('origin')

    path = proj2.git_real_path
    with clone(path) as workdir:
        with open(join(workdir, 'origin'), 'w') as f:
            f.write('modified')

project = Project.add(
    p1_name, owner_id="testuser", summary="test", product="")
assert project
project_fork = Project.add(
    p2_name, owner_id="testuser", summary="test", product="",
    fork_from=project.id)

setup2repos(project, project_fork)

pullreq1 = PullRequest.open(project_fork, 'master', project, 'master')
ticket1 = Ticket.add(project.id, 'title', 'content', 'testuser')
pullreq1.insert(ticket1.ticket_number)

print "PR has been built at: %s" % (DOMAIN + ticket1.url)