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
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)
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)
def delete(comment_id): n = store.execute( "delete from codedouban_comments " "where comment_id = %s", (comment_id, )) if n: store.commit() return True
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)
def delete(self): n = store.execute("delete from codedouban_linecomments_v2 " "where id = %s", (self.id,)) if n: store.commit() return True return False
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()
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, 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()
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()
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
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
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
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)
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
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()
def delete(cls, name): rs = store.execute("delete from chat_rooms " "where name=%s", (name,)) if rs: store.commit() return True return False
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)
def delete(self): n = store.execute( "delete from tag_names " "where id=%s", (self.id,)) if n: store.commit() return True
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)
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)
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()
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)
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)
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
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
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)
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, '')
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()
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)
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, '')
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))
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
def delete(self): n = store.execute( "delete from codedouban_linecomments_v2 " "where id = %s", (self.id, )) if n: store.commit() return True return False
def delete(self): n = store.execute( "delete from tags " "where id=%s", self.id) self._clean_cache() if n: store.commit() return True
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)
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)
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)
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)
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))
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)
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)
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
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)
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