Example #1
0
 def add(cls, ticket_id, content, path, position,
         old, new, from_ref, author, new_path=None):
     # FIXME: mysql里的content是废的啊,是历史原因么?
     line_mark = str(old) + '|' + str(new)
     id = store.execute("insert into codedouban_ticket_codereview "
                        "(ticket_id, content, path, position, line_mark, "
                        "from_ref, author, new_path) "
                        "values (%s, %s, %s, %s, %s, %s, %s, %s)",
                        (ticket_id, content, path, position, line_mark,
                         from_ref, author, new_path))
     if not id:
         store.rollback()
         raise Exception("Unable to add")
     store.commit()
     bdb.set(BDB_TICKET_LINECOMMENT_CONTENT_KEY % id, content)
     comment = cls.get(id)
     ticket = Ticket.get(ticket_id)
     # TODO: 重构feed之后取消signal发送
     codereview_signal.send(comment, content=content,
                            ticket=Ticket.get(ticket_id),
                            author=author, comment=comment)
     dispatch('codereview', data={
              'comment': comment,
              'ticket': ticket,
              'sender': author,
              })
     return comment
Example #2
0
 def add(
     cls,
     title,
     description,
     creator,
     number=None,
     team=None,
     project=None,
     assignee=None,
     closer=None,
     created_at=None,
     updated_at=None,
     closed_at=None,
 ):
     issue = Issue.add(
         title, description, creator, assignee=assignee, closer=closer, type=cls.target_type, target_id=project
     )
     if issue and project:
         number = PICounter.incr(project, number)
         store.execute(
             "insert into project_issues (project_id, issue_id, number) " "values (%s, %s, %s) ",
             (project, issue.id, number),
         )
         store.commit()
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N % (project, creator, "open"))
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N % (project, creator, "closed"))
         cls._clean_cache(project)
         return Issue.get_cached_issue(issue.id)
Example #3
0
 def add(cls,
         title,
         description,
         creator,
         number=None,
         team=None,
         project=None,
         assignee=None,
         closer=None,
         created_at=None,
         updated_at=None,
         closed_at=None):
     issue = Issue.add(title,
                       description,
                       creator,
                       assignee=assignee,
                       closer=closer,
                       type=cls.target_type,
                       target_id=project)
     if issue and project:
         number = PICounter.incr(project, number)
         store.execute(
             'insert into project_issues (project_id, issue_id, number) '
             'values (%s, %s, %s) ', (project, issue.id, number))
         store.commit()
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N %
                   (project, creator, 'open'))
         mc.delete(MC_KEY_PROJECT_ISSUE_CREATOR_N %
                   (project, creator, 'closed'))
         cls._clean_cache(project)
         return Issue.get_cached_issue(issue.id)
Example #4
0
def delete(comment_id):
    n = store.execute(
        "delete from codedouban_comments "
        "where comment_id = %s", (comment_id, ))
    if n:
        store.commit()
        return True
Example #5
0
 def update_summary(self, summary):
     store.execute("update codedouban_projects "
                   "set summary=%s "
                   "where project_id=%s",
                   (summary, self.id))
     store.commit()
     self.clear_mc(self.id)
Example #6
0
 def delete(self):
     n = store.execute("delete from codedouban_linecomments_v2 "
                       "where id = %s", (self.id,))
     if n:
         store.commit()
         return True
     return False
Example #7
0
def main():
    rs = store.execute("select id, type "
                       "from issues "
                       "where type='project'")
    for r in rs:
        id, _ = r
        rs1 = store.execute("select id, project_id, issue_id "
                            "from project_issues "
                            "where issue_id=%s",
                            id)
        if rs1 and rs1[0]:
            _, target_id, _ = rs1[0]
            store.execute("update issues "
                          "set target_id=%s "
                          "where id=%s",
                          (target_id, id))
            store.commit()

    rs = store.execute("select id, type "
                       "from issues "
                       "where type='team'")
    for r in rs:
        id, _ = r
        rs1 = store.execute("select id, team_id, issue_id "
                            "from team_issues "
                            "where issue_id=%s",
                            id)
        if rs1 and rs1[0]:
            _, target_id, _ = rs1[0]
            store.execute("update issues "
                          "set target_id=%s "
                          "where id=%s",
                          (target_id, id))
            store.commit()
Example #8
0
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)
Example #9
0
 def add(cls, name, followed_user_name):
     time = datetime.now()
     store.execute('insert into follow_relationship '
                   '(user_name, followed_user_name, time) '
                   'values (%s, %s, %s)',
                   (name, followed_user_name, time))
     store.commit()
Example #10
0
 def add(cls, name, followed_user_name):
     time = datetime.now()
     store.execute(
         'insert into follow_relationship '
         '(user_name, followed_user_name, time) '
         'values (%s, %s, %s)', (name, followed_user_name, time))
     store.commit()
Example #11
0
 def add(cls, description, owner_id, is_public, gist_names=[],
         gist_contents=[], fork_from=None):
     now = datetime.now()
     if fork_from:
         name = cls.get(fork_from).name
         id = store.execute(
             "insert into gists "
             "(`name`, `description`, `owner_id`, `created_at`, `fork_from`) "  # noqa
             "values (%s, %s, %s, %s, %s)",
             (name, description, owner_id, now, fork_from))
         store.commit()
         gist = cls.get(id)
         fork_from = cls.get(fork_from)
         fork_from.fork_repo(gist)
         gist_forked_signal.send(gist, gist_id=gist.id)
     else:
         name = cls._get_name(names=gist_names)
         id = store.execute(
             "insert into gists "
             "(`name`, `description`, `owner_id`, `is_public`, `created_at`) "  # noqa
             "values (%s, %s, %s, %s, %s)",
             (name, description, owner_id, is_public, now))
         store.commit()
         gist = cls.get(id)
         gist.create_repo()
         gist._commit_all_files(gist_names, gist_contents, create=True)
         gist_created_signal.send(gist, gist_id=gist.id)
     return gist
Example #12
0
 def add(cls,
         title,
         description,
         creator,
         assignee=None,
         closer=None,
         created_at=None,
         updated_at=None,
         closed_at=None,
         type='default',
         target_id=0):
     time = datetime.now()
     issue_id = store.execute(
         'insert into issues (title, creator_id, '
         'assignee_id, closer_id, created_at, updated_at, type, target_id) '
         'values (%s, %s, %s, %s, NULL, NULL, %s, %s)',
         (title, creator, assignee, closer, type, target_id))
     store.commit()
     mc.delete(MC_KEY_ISSUE % issue_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % creator)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % assignee)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (type, target_id))
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % issue_id, description)
     issue = cls(issue_id, title, creator, assignee, closer, time, time)
     issue.add_participant(creator)
     return issue
Example #13
0
 def revoke(self):
     now = datetime.now()
     store.execute(
         "update api_token set expire_time=%s, refresh_expire_time=%s "
         "where id=%s", (now, now, self.id))
     store.commit()
     self.expire_time = self.refresh_expire_time = now
Example #14
0
 def add(cls,
         title,
         description,
         creator,
         number=None,
         team=None,
         project=None,
         assignee=None,
         closer=None,
         created_at=None,
         updated_at=None,
         closed_at=None):
     issue = Issue.add(title,
                       description,
                       creator,
                       assignee=assignee,
                       closer=closer,
                       type=cls.target_type,
                       target_id=team)
     if issue and team:
         number = TICounter.incr(team, number)
         team_issue_id = store.execute(
             'insert into team_issues (team_id, issue_id, number) '
             'values (%s, %s, %s)', (team, issue.id, number))
         store.commit()
         return cls(team_issue_id, team, issue.id, number, title, creator,
                    assignee, closer, issue.created_at, issue.updated_at)
Example #15
0
 def update_summary(self, summary):
     store.execute("update codedouban_projects "
                   "set summary=%s "
                   "where project_id=%s",
                   (summary, self.id))
     store.commit()
     self.clear_mc(self.id)
Example #16
0
 def add(cls, gist_id, user_id):
     id = store.execute("insert into gist_stars (`gist_id`, `user_id`)"
                        "values (%s, %s)", (gist_id, user_id))
     store.commit()
     gs = cls.get(id)
     gist_starred_signal.send(gs, gist_id=gist_id, author=user_id)
     return True
Example #17
0
def main():
    rs = store.execute("select id, type "
                       "from issues "
                       "where type='project'")
    for r in rs:
        id, _ = r
        rs1 = store.execute(
            "select id, project_id, issue_id "
            "from project_issues "
            "where issue_id=%s", id)
        if rs1 and rs1[0]:
            _, target_id, _ = rs1[0]
            store.execute("update issues "
                          "set target_id=%s "
                          "where id=%s", (target_id, id))
            store.commit()

    rs = store.execute("select id, type " "from issues " "where type='team'")
    for r in rs:
        id, _ = r
        rs1 = store.execute(
            "select id, team_id, issue_id "
            "from team_issues "
            "where issue_id=%s", id)
        if rs1 and rs1[0]:
            _, target_id, _ = rs1[0]
            store.execute("update issues "
                          "set target_id=%s "
                          "where id=%s", (target_id, id))
            store.commit()
Example #18
0
 def delete(cls, name):
     rs = store.execute("delete from chat_rooms "
                        "where name=%s", (name,))
     if rs:
         store.commit()
         return True
     return False
Example #19
0
 def update_product(self, product):
     store.execute("update codedouban_projects "
                   "set product=%s "
                   "where project_id=%s",
                   (product, self.id))
     store.commit()
     self.clear_mc(self.id)
Example #20
0
 def add(cls,
         description,
         owner_id,
         is_public,
         gist_names=[],
         gist_contents=[],
         fork_from=None):
     now = datetime.now()
     if fork_from:
         name = cls.get(fork_from).name
         id = store.execute(
             "insert into gists "
             "(`name`, `description`, `owner_id`, `created_at`, `fork_from`) "  # noqa
             "values (%s, %s, %s, %s, %s)",
             (name, description, owner_id, now, fork_from))
         store.commit()
         gist = cls.get(id)
         fork_from = cls.get(fork_from)
         fork_from.fork_repo(gist)
         gist_forked_signal.send(gist, gist_id=gist.id)
     else:
         name = cls._get_name(names=gist_names)
         id = store.execute(
             "insert into gists "
             "(`name`, `description`, `owner_id`, `is_public`, `created_at`) "  # noqa
             "values (%s, %s, %s, %s, %s)",
             (name, description, owner_id, is_public, now))
         store.commit()
         gist = cls.get(id)
         gist.create_repo()
         gist._commit_all_files(gist_names, gist_contents, create=True)
         gist_created_signal.send(gist, gist_id=gist.id)
     return gist
Example #21
0
 def delete(self):
     n = store.execute(
         "delete from tag_names "
         "where id=%s", (self.id,))
     if n:
         store.commit()
         return True
Example #22
0
 def update_intern_banned(self, banned):
     store.execute("update codedouban_projects "
                   "set intern_banned=%s "
                   "where project_id=%s",
                   (banned, self.id))
     store.commit()
     self.clear_mc(self.id)
Example #23
0
 def update_intern_banned(self, banned):
     store.execute("update codedouban_projects "
                   "set intern_banned=%s "
                   "where project_id=%s",
                   (banned, self.id))
     store.commit()
     self.clear_mc(self.id)
Example #24
0
 def update(self, title='', description=''):
     store.execute(
         "update codedouban_ticket set title=%s, description=%s "
         "where id=%s", (title, description, self.id))
     store.commit()
     mc.delete(MCKEY_TICKET % self.id)
     bdb.set(BDB_TICKET_DESCRIPTION_KEY % self.id, description)
Example #25
0
 def delete(self):
     shutil.rmtree(self.git_real_path, ignore_errors=True)
     store.execute("delete from gists where id=%s", (self.id, ))
     store.execute("delete from gist_stars where gist_id=%s", (self.id, ))
     store.execute("delete from gist_comments where gist_id=%s",
                   (self.id, ))
     store.commit()
Example #26
0
 def add(cls, url, project_id):
     hook_id = store.execute("insert into codedouban_hooks "
                             "(project_id, url) values "
                             "(%s, %s)",
                             (project_id, url))
     store.commit()
     return cls(hook_id, url, project_id)
Example #27
0
 def update_product(self, product):
     store.execute("update codedouban_projects "
                   "set product=%s "
                   "where project_id=%s",
                   (product, self.id))
     store.commit()
     self.clear_mc(self.id)
Example #28
0
 def add(cls, issue_id, user_id):
     time = datetime.now()
     participant_id = store.execute(
         "insert into issue_participants "
         "(issue_id, user_id, created_at) values (%s, %s, NULL)",
         (issue_id, user_id))
     store.commit()
     return cls(participant_id, issue_id, user_id, time)
Example #29
0
 def add(cls, user_id, email):
     email_id = store.execute(
         'insert into codedouban_useremails (user_id, email) '
         'values (%s, %s)', (user_id, email))
     store.commit()
     ret = cls(email_id, user_id, email)
     ret._flush()
     return ret
Example #30
0
 def delete(self):
     bdb.delete(BDB_ISSUE_COMMENT_CONTENT_KEY % self.id)
     n = store.execute("delete from issue_comments "
                       "where id=%s", (self.id,))
     if n:
         store.commit()
         mc.delete(MC_KEY_ISSUE_COMMENTS_COUNT % self.issue_id)
         return True
Example #31
0
 def update_can_push(self, can_push):
     push = 1 if can_push else 0
     store.execute("update codedouban_projects "
                   "set can_push=%s "
                   "where project_id=%s",
                   (push, self.id))
     store.commit()
     self.clear_mc(self.id)
Example #32
0
 def delete(self):
     store.execute('delete from issues where id=%s', (self.id,))
     store.commit()
     mc.delete(MC_KEY_ISSUE % self.id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % self.creator_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % self.assignee_id)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (type, self.target_id))
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.id, '')
Example #33
0
 def add_committer(cls, proj_id, user_id):
     try:
         store.execute("insert into codedouban_committers "
                       "(project_id, user_id) values (%s, %s)",
                       (proj_id, user_id))
     except IntegrityError:
         return None
     store.commit()
Example #34
0
 def add(cls, user_id, key):
     fingerprint = generate_fingerprint(key)
     title = generate_title(key)
     id = store.execute(
         'insert into ssh_keys (user_id, `key`, fingerprint, title) '
         'values (%s, %s, %s, %s)', (user_id, key, fingerprint, title))
     store.commit()
     return cls(id, user_id, key, fingerprint, title)
Example #35
0
 def delete(self):
     store.execute('delete from issues where id=%s', (self.id, ))
     store.commit()
     mc.delete(MC_KEY_ISSUE % self.id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % self.creator_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % self.assignee_id)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (type, self.target_id))
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.id, '')
Example #36
0
 def update(self, title, description):
     store.execute("update issues "
                   "set title=%s, updated_at=null "
                   "where id=%s", (title, self.issue_id))
     store.commit()
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.issue_id, description)
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
Example #37
0
 def delete(cls, issue_id, user_id):
     n = store.execute(
         "delete from issue_upvotes "
         "where issue_id = %s and user_id = %s ", (issue_id, user_id))
     if n:
         store.commit()
         mc.delete(MC_KEY_ISSUE_VOTES_COUNT % issue_id)
         return True
Example #38
0
 def add_committer(cls, proj_id, user_id):
     try:
         store.execute("insert into codedouban_committers "
                       "(project_id, user_id) values (%s, %s)",
                       (proj_id, user_id))
     except IntegrityError:
         return None
     store.commit()
Example #39
0
 def delete(self):
     n = store.execute(
         "delete from codedouban_linecomments_v2 "
         "where id = %s", (self.id, ))
     if n:
         store.commit()
         return True
     return False
Example #40
0
 def delete(self):
     n = store.execute(
         "delete from tags "
         "where id=%s", self.id)
     self._clean_cache()
     if n:
         store.commit()
         return True
Example #41
0
 def delete(self):
     bdb.delete(BDB_ISSUE_COMMENT_CONTENT_KEY % self.id)
     n = store.execute("delete from issue_comments "
                       "where id=%s", (self.id,))
     if n:
         store.commit()
         mc.delete(MC_KEY_ISSUE_COMMENTS_COUNT % self.issue_id)
         return True
Example #42
0
 def add(cls, issue_id, user_id):
     time = datetime.now()
     participant_id = store.execute(
         "insert into issue_participants "
         "(issue_id, user_id, created_at) values (%s, %s, NULL)",
         (issue_id, user_id))
     store.commit()
     return cls(participant_id, issue_id, user_id, time)
Example #43
0
 def update_can_push(self, can_push):
     push = 1 if can_push else 0
     store.execute("update codedouban_projects "
                   "set can_push=%s "
                   "where project_id=%s",
                   (push, self.id))
     store.commit()
     self.clear_mc(self.id)
Example #44
0
 def add(cls, user_id, email):
     email_id = store.execute(
         'insert into codedouban_useremails (user_id, email) '
         'values (%s, %s)', (user_id, email))
     store.commit()
     ret = cls(email_id, user_id, email)
     ret._flush()
     return ret
Example #45
0
 def add(cls, user_id, key):
     fingerprint = generate_fingerprint(key)
     title = generate_title(key)
     id = store.execute(
         "insert into ssh_keys (user_id, `key`, fingerprint, title) " "values (%s, %s, %s, %s)",
         (user_id, key, fingerprint, title),
     )
     store.commit()
     return cls(id, user_id, key, fingerprint, title)
Example #46
0
 def open(self, operator):
     opened_time = datetime.now()
     store.execute("update codedouban_ticket set closed=null where id=%s",
                   (self.id,))
     store.commit()
     mc.delete(MCKEY_TICKET % self.id)
     self.close_by = None
     self.add_participant(operator)
     TicketNode.add_open(self.id, operator, opened_time)
Example #47
0
 def add(cls, name, summary):
     b = cls.get_by_name(name)
     if b:
         return b
     params = (name, summary)
     id = store.execute(
         "insert into badge(name, summary) values(%s, %s)", params)
     store.commit()
     return cls(id, name, summary)
Example #48
0
 def update(self, description, gist_names=[], gist_contents=[],
            gist_oids=[]):
     name = self._get_name(gist_names)
     store.execute(
         "update gists set name=%s, description=%s, updated_at=%s where id=%s",  # noqa
         (name, description, datetime.now(), self.id))
     store.commit()
     self._commit_all_files(gist_names, gist_contents, gist_oids)
     gist_updated_signal.send(self, gist_id=self.id)
Example #49
0
 def update(self, title, description):
     store.execute(
         "update issues "
         "set title=%s, updated_at=null "
         "where id=%s", (title, self.issue_id))
     store.commit()
     bdb.set(BDB_ISSUE_DESCRIPTION_KEY % self.issue_id, description)
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
Example #50
0
 def assign(self, user_id):
     old_id = self.assignee_id
     store.execute("update issues "
                   "set assignee_id=%s "
                   "where id=%s", (user_id, self.issue_id))
     store.commit()
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % old_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % user_id)
Example #51
0
 def open(self, operator):
     opened_time = datetime.now()
     store.execute("update codedouban_ticket set closed=null where id=%s",
                   (self.id, ))
     store.commit()
     mc.delete(MCKEY_TICKET % self.id)
     self.close_by = None
     self.add_participant(operator)
     TicketNode.add_open(self.id, operator, opened_time)
Example #52
0
def _add(name, owner):
    room_id = store.execute("insert into chat_rooms"
                            "(name, author) values(%s, %s)",
                            (name, owner))
    if not room_id:
        store.rollback()
        raise Exception("Unable to insert new room")
    store.commit()
    return room_id
Example #53
0
 def transfer_to_top(self, user=None):
     new_user = user if user else self.owner_id
     sql = ("update codedouban_projects set project_name=%s, "
            "git_path=%s, trac_conf=%s, owner_id=%s "
            "where owner_id=%s and project_id=%s")
     store.execute(sql, (self.realname, self.realname, self.realname,
                         new_user, self.owner_id, self.id))
     store.commit()
     self.clear_mc(self.id)
Example #54
0
 def transfer_to_top(self, user=None):
     new_user = user if user else self.owner_id
     sql = ("update codedouban_projects set project_name=%s, "
            "git_path=%s, trac_conf=%s, owner_id=%s "
            "where owner_id=%s and project_id=%s")
     store.execute(sql, (self.realname, self.realname, self.realname,
                         new_user, self.owner_id, self.id))
     store.commit()
     self.clear_mc(self.id)
Example #55
0
 def open(self):
     store.execute("update issues "
                   "set closer_id=null, closed_at=null "
                   "where id=%s", (self.issue_id,))
     store.commit()
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_IDS_BY_CREATOR_ID % self.creator_id)
     mc.delete(MC_KEY_ISSUES_DATA_BY_TARGET % (self.type, self.target_id))
     self.closer_id = None
Example #56
0
 def assign(self, user_id):
     old_id = self.assignee_id
     store.execute("update issues "
                   "set assignee_id=%s "
                   "where id=%s", (user_id, self.issue_id))
     store.commit()
     self.clear_cache()
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % old_id)
     mc.delete(MC_KEY_ISSUES_IDS_BY_ASSIGNEE_ID % user_id)