def format_issue_info(**kw): issue_id = kw['issue_id'] author = kw['author'] content = kw['content'] issue = get_issue_by_issue_id(issue_id) target = issue.target uid = 'issue-%s-%s-%s' % (issue.target_type, target.id, issue.number) text = trunc_utf8(content, 50) state = issue.state type = 'issue' data = dict( date=datetime.now(), url=issue.url, number=issue.number, target_name="%s" % target.name, target_url="%s" % target.url, state=state, receiver=issue.creator_id, title=issue.title, author=author, text=text, uid=uid, type=type, ) return data
def format_issue_comment_info(**kw): from vilya.models.issue_comment import IssueComment issue_id = kw['issue_id'] author = kw['author'] content = kw['content'] comment_id = kw['comment_id'] issue = get_issue_by_issue_id(issue_id) target = issue.target issue_comment = IssueComment.get(comment_id) text = trunc_utf8(content, 50) uid = "issue-comment-%s-%s-%s-%s" % (issue.target_type, target.id, issue.number, issue_comment.number) type = 'issue_comment' data = dict( date=datetime.now(), url="%s#comment-%s" % (issue.url, issue_comment.number), number=issue.number, title=issue.title, target_name="%s" % target.name, target_url="%s" % target.url, receiver=issue.creator_id, author=author, text=text, uid=uid, type=type, ) return data
def format_issue_comment_info(**kw): from models.issue_comment import IssueComment issue_id = kw['issue_id'] author = kw['author'] content = kw['content'] comment_id = kw['comment_id'] issue = get_issue_by_issue_id(issue_id) target = issue.target issue_comment = IssueComment.get(comment_id) text = trunc_utf8(content, 50) uid = "issue-comment-%s-%s-%s-%s" % ( issue.target_type, target.id, issue.number, issue_comment.number) type = 'issue_comment' data = dict( date=datetime.now(), url="%s#comment-%s" % (issue.url, issue_comment.number), number=issue.number, title=issue.title, target_name="%s" % target.name, target_url="%s" % target.url, receiver=issue.creator_id, author=author, text=text, uid=uid, type=type, ) return data
def short_content(self): content = self.content if content: return trunc_utf8(content, 30)
def short_description(self): return trunc_utf8(self.description, 80)
def snippet(self): desc = self.hl_description return trunc_utf8(desc, 300)
def _truncate(cls, s, cnt=80): return trunc_utf8(s, cnt)
def blame_src(self, ref='HEAD', path=''): # Using --porcelain instead of --line-porcelain is more efficient, as # commit info (author, time, summary) is displayed only once # and it is compatible with git 1.7.5 res = self._gyt_repo.blame(ref, path) res = res.splitlines() blame = [] hl_lines = self._blame_src_highlighted_lines(ref, path) rev_data = {} new_block = True for line in res: if new_block: sha, old_no, line_no = line.split()[:3] if sha not in rev_data: rev_data[sha] = {} rev_data[sha]['line_no'] = line_no rev_data[sha]['old_no'] = old_no new_block = False elif line.startswith('author '): _, _, author = line.partition(' ') rev_data[sha]['author'] = author.strip() elif line.startswith('author-time '): _, _, time = line.partition(' ') time = datetime.fromtimestamp(float(time)).strftime('%Y-%m-%d') rev_data[sha]['time'] = time elif line.startswith('author-mail '): _, _, email = line.partition(' ') email = RE_EMAIL.match(email).group('email') rev_data[sha]['email'] = email elif line.startswith('summary '): _, _, summary = line.partition(' ') rev_data[sha]['summary'] = summary.strip() disp_summary = trunc_utf8( summary.encode('utf-8'), 20).decode('utf-8', 'ignore') rev_data[sha]['disp_summary'] = disp_summary elif line.startswith('filename'): _, _, filename = line.partition(' ') rev_data[sha]['filename'] = filename filename = trunc_utf8( filename.strip().encode('utf-8'), 30).decode('utf-8', 'ignore') rev_data[sha]['disp_name'] = filename elif line.startswith('\t'): # Try to get an highlighted line of source code code_line = hl_lines.get(str( line_no), '').replace('\n', '').decode('utf-8', 'ignore') if not code_line: code_line = line[1:] blame.append((sha, rev_data[sha]['author'], rev_data[sha]['email'], rev_data[sha]['time'], rev_data[sha]['disp_summary'], rev_data[sha]['summary'], rev_data[sha]['line_no'], rev_data[sha]['old_no'], rev_data[sha]['filename'], rev_data[sha]['disp_name'], code_line, )) new_block = True return self._blame_src_header(ref), blame
def blame_src(self, ref='HEAD', path=''): # Using --porcelain instead of --line-porcelain is more efficient, as # commit info (author, time, summary) is displayed only once # and it is compatible with git 1.7.5 res = self._gyt_repo.blame(ref, path) res = res.splitlines() blame = [] hl_lines = self._blame_src_highlighted_lines(ref, path) rev_data = {} new_block = True for line in res: if new_block: sha, old_no, line_no = line.split()[:3] if sha not in rev_data: rev_data[sha] = {} rev_data[sha]['line_no'] = line_no rev_data[sha]['old_no'] = old_no new_block = False elif line.startswith('author '): _, _, author = line.partition(' ') rev_data[sha]['author'] = author.strip() elif line.startswith('author-time '): _, _, time = line.partition(' ') time = datetime.fromtimestamp(float(time)).strftime('%Y-%m-%d') rev_data[sha]['time'] = time elif line.startswith('author-mail '): _, _, email = line.partition(' ') email = RE_EMAIL.match(email).group('email') rev_data[sha]['email'] = email elif line.startswith('summary '): _, _, summary = line.partition(' ') rev_data[sha]['summary'] = summary.strip() disp_summary = trunc_utf8(summary.encode('utf-8'), 20).decode('utf-8', 'ignore') rev_data[sha]['disp_summary'] = disp_summary elif line.startswith('filename'): _, _, filename = line.partition(' ') rev_data[sha]['filename'] = filename filename = trunc_utf8(filename.strip().encode('utf-8'), 30).decode('utf-8', 'ignore') rev_data[sha]['disp_name'] = filename elif line.startswith('\t'): # Try to get an highlighted line of source code code_line = hl_lines.get(str(line_no), '').replace('\n', '').decode( 'utf-8', 'ignore') if not code_line: code_line = line[1:] blame.append(( sha, rev_data[sha]['author'], rev_data[sha]['email'], rev_data[sha]['time'], rev_data[sha]['disp_summary'], rev_data[sha]['summary'], rev_data[sha]['line_no'], rev_data[sha]['old_no'], rev_data[sha]['filename'], rev_data[sha]['disp_name'], code_line, )) new_block = True return self._blame_src_header(ref), blame
def short_description(self): if self.description: return trunc_utf8(self.description, 80) return ''