def test_comment(self): issue = Issue(self.tracker) issue.save() c = Comment(issue) c.save() assert type(issue.comment(c.id)) is Comment assert issue.comment(c.id).fields == c.fields
def interpret(message, tracker): """ Look for an issue and/or comment id in the commit message and return the appropriate object. """ message = message[0].lower() + message[1:] last13 = message[-13:] last6 = message[-6:] if looks_hashy(last13[:6]) and looks_hashy(last13[7:]): issue_id = last13[:6] comment_id = last13[7:] try: issue = Issue(tracker, issue_id) redacted = message[:-13] return redacted, Comment(issue, comment_id) except BadReference: pass elif looks_hashy(last6): try: issue = Issue(tracker, last6) redacted = message[:-6] return redacted, Issue(tracker, last6) except BadReference: pass return message, None
def open(id, redirect_after=True): """ Open an issue. :param id: issue id :param redirect_after: return a redirect. This happens by default, but turning it off may be desirable for async requests. """ tracker, config = setup() issue = tracker.issue(id) if issue: issue.status = 'open' comment = Comment(issue) comment.event = True comment.event_data = 'opened' comment.author = config.user comment.save() issue.save() tracker.autocommit('Re-opened issue %s/%s' % (issue.id[:6], comment.id[:6]), config.user) if redirect_after: return redirect(url_for('issues.view', id=issue.id)) else: return True return False
def view(id): """ Render the issue view to display information about a single issue. :param id: id of the issue to view. """ tracker, config = setup() issue = tracker.issue(id) if request.method == 'POST': comment = Comment(issue) comment.content = request.form['content'] comment.author['name'] = config.user['name'] comment.author['email'] = config.user['email'] comment.save() if issue.save(): # ping the issue (updated = now) tracker.autocommit(message='Commented on issue %s/%s' % \ (issue.id[:6], comment.id[:6]), author=config.user) else: flash('There was an error saving your comment.') return redirect(url_for('issues.view', id=issue.id)) else: issue.updated = relative_time(issue.updated) issue.created = relative_time(issue.created) issue.content = markdown_to_html(issue.content) comments = issue.comments() header = 'Viewing Issue <span class="fancy-monospace">%s</span>' \ % issue.id[:6] if comments: map_attr(comments, 'timestamp', relative_time) map_attr(comments, 'content', markdown_to_html) return render_template('issue.html', issue=issue, comments=comments, selected='issues', config=config, header=header, tracker=tracker)
def test_comments(self): issue = Issue(self.tracker) issue.save() # Make some comments comments = [Comment(issue) for i in range(20)] for c in comments: c.save() assert type(issue.comments()) is list assert len(issue.comments()) == 20 assert len(issue.comments(n=15)) == 15
def comment(args): """Comment on an issue.""" t = args['tracker'] i = t.issue(args['issue']) if not i: print 'No such issue' return c = Comment(i) config = UserConfig() # set the author info c.author['name'] = config.user['name'] c.author['email'] = config.user['email'] editor = args['editor'] if args['editor'] else config.core['editor'] template = Template('comment.hpr') path = template.open(editor) fields = template.parse(path) c.content = fields['content'] if c.save() and i.save(): # commit the changes if config.core['autocommit']: t.autocommit(message='Commented on issue %s' % i.id[:6], author=config.user) print 'Posted comment %s on issue %s' % (c.id[:3], i.id[:6])
def comment(self, sha): return Comment(self, sha)
def comments(self, n=None): comments = [Comment(self, sha) for sha in self._get_comments()] comments.sort(key=lambda x: x.timestamp) if n: return comments[:n] return comments