def expand_macro(self, formatter, name, content, args={}): reponame = args.get('repository') or '' rev = args.get('revision') repos = RepositoryManager(self.env).get_repository(reponame) try: changeset = repos.get_changeset(rev) message = changeset.message rev = changeset.rev resource = repos.resource except Exception: message = content resource = Resource('repository', reponame) if formatter.context.resource.realm == 'ticket': ticket_re = CommitTicketUpdater.ticket_re if not any( int(tkt_id) == int(formatter.context.resource.id) for tkt_id in ticket_re.findall(message)): return tag.p( "(The changeset message doesn't reference this " "ticket)", class_='hint') if ChangesetModule(self.env).wiki_format_messages: return tag.div(format_to_html(self.env, formatter.context.child( 'changeset', rev, parent=resource), message, escape_newlines=True), class_='message') else: return tag.pre(message, class_='message')
def expand_macro(self, formatter, name, content, args=None): args = args or {} reponame = args.get('repository') or '' rev = args.get('revision') repos = RepositoryManager(self.env).get_repository(reponame) try: changeset = repos.get_changeset(rev) message = changeset.message rev = changeset.rev resource = repos.resource except Exception: message = content resource = Resource('repository', reponame) if formatter.context.resource.realm == 'ticket': ticket_re = CommitTicketUpdater.ticket_re if not any(int(tkt_id) == int(formatter.context.resource.id) for tkt_id in ticket_re.findall(message)): return tag.p(_("(The changeset message doesn't reference this " "ticket)"), class_='hint') if ChangesetModule(self.env).wiki_format_messages: return tag.div(format_to_html(self.env, formatter.context.child('changeset', rev, parent=resource), message, escape_newlines=True), class_='message') else: return tag.pre(message, class_='message')
def from_comment(cls, env, comment, user=None, notify=True): """ Creates a subscription from a Comment object. """ sub = { 'user': user or comment.author, 'type': comment.type, 'notify': notify, } # Munge attachments if comment.type == 'attachment': sub['path'] = comment.path.split(':')[1] sub['repos'] = '' sub['rev'] = '' # Munge changesets and browser if comment.type in ('changeset', 'browser'): if comment.type == 'browser': sub['path'] = comment.path else: sub['path'] = '' repo = RepositoryManager(env).get_repository(None) try: sub['repos'] = repo.reponame try: _cs = repo.get_changeset(comment.revision) sub['rev'] = _cs.rev except NoSuchChangeset: # Invalid changeset return None finally: repo.close() return cls._from_dict(env, sub)
def expand_macro(self, formatter, name, content, args=None): # pylint: disable=too-many-function-args args = args or {} reponame = args.get('repository') or '' rev = args.get('revision') # pylint: disable=no-member repos = RepositoryManager(self.env).get_repository(reponame) try: changeset = repos.get_changeset(rev) message = changeset.message rev = changeset.rev resource = repos.resource except Exception: # pylint: disable=broad-except message = content resource = Resource('repository', reponame) if ChangesetModule(self.env).wiki_format_messages: return tag.div(format_to_html(self.env, formatter.context.child( 'changeset', rev, parent=resource), message, escape_newlines=True), class_='message') else: return tag.pre(message, class_='message')
def expand_macro(self, formatter, name, content, args={}): reponame = args.get("repository") or "" rev = args.get("revision") repos = RepositoryManager(self.env).get_repository(reponame) try: changeset = repos.get_changeset(rev) message = changeset.message rev = changeset.rev resource = repos.resource except Exception: message = content resource = Resource("repository", reponame) if formatter.context.resource.realm == "ticket": ticket_re = CommitTicketUpdater.ticket_re if not any(int(tkt_id) == int(formatter.context.resource.id) for tkt_id in ticket_re.findall(message)): return tag.p("(The changeset message doesn't reference this " "ticket)", class_="hint") if ChangesetModule(self.env).wiki_format_messages: return tag.div( format_to_html( self.env, formatter.context.child("changeset", rev, parent=resource), message, escape_newlines=True ), class_="message", ) else: return tag.pre(message, class_="message")
def expand_macro(self, formatter, name, content, args={}): reponame = args.get('repository') or '' rev = args.get('revision') repos = RepositoryManager(self.env).get_repository(reponame) try: changeset = repos.get_changeset(rev) message = changeset.message # add review status to commit message ( review = CodeReview(self.env, reponame, rev) status = review.encode(review.status) message += '\n\n{{{#!html \n' message += '<div class="codereviewstatus">' message += ' <div class="system-message %s">' % status.lower() message += ' <p>Code review status: ' message += ' <span>%s</span>' % review.status message += ' </p>' message += ' </div>' message += '</div>' message += '\n}}}' rev = changeset.rev resource = repos.resource except Exception, e: message = content resource = Resource('repository', reponame)
def expand_macro(self, formatter, name, content, args={}): reponame = args.get('repository') or '' rev = args.get('revision') repos = RepositoryManager(self.env).get_repository(reponame) try: changeset = repos.get_changeset(rev) message = changeset.message # add review status to commit message ( review = CodeReview(self.env, reponame, rev) status = review.encode(review.status) message += '\n\n{{{#!html \n' message += '<div class="codereviewstatus">' message += ' <div class="system-message %s">' % status.lower() message += ' <p>Code review status: ' message += ' <span>%s</span>' % review.status message += ' </p>' message += ' </div>' message += '</div>' message += '\n}}}' rev = changeset.rev resource = repos.resource except Exception, e: message = content resource = Resource('repository', reponame)
def from_comment(cls, env, comment, user=None, notify=True): """ Creates a subscription from a Comment object. """ sub = { 'user': user or comment.author, 'type': comment.type, 'notify': notify, } # Munge attachments if comment.type == 'attachment': sub['path'] = comment.path.split(':')[1] sub['repos'] = '' sub['rev'] = '' # Munge changesets and browser if comment.type in ('changeset', 'browser'): if comment.type == 'browser': sub['path'] = comment.path else: sub['path'] = '' repo = RepositoryManager(env).get_repository(None) try: sub['repos'] = repo.reponame try: _cs = repo.get_changeset(comment.revision) sub['rev'] = _cs.rev except NoSuchChangeset: # Invalid changeset return None finally: repo.close() return cls._from_dict(env, sub)
def expand_macro(self, formatter, name, content, args=None): # pylint: disable=too-many-function-args args = args or {} reponame = args.get('repository') or '' rev = args.get('revision') # pylint: disable=no-member repos = RepositoryManager(self.env).get_repository(reponame) try: changeset = repos.get_changeset(rev) message = changeset.message rev = changeset.rev resource = repos.resource except Exception: # pylint: disable=broad-except message = content resource = Resource('repository', reponame) config = self.ticket_replace_section fields = {} for key, value in config.options(): idx = key.rfind('.') if idx >= 0: prefix, attribute = key[:idx], key[idx + 1:] field = fields.setdefault(prefix, {}) field[attribute] = config.get(key) else: fields[key] = {'': value} for prefix, field in fields.iteritems(): if not all(k in field for k in ['pattern', 'replace']): self.log.warn( "Ignoring [%s] %s, missing .pattern or .replace" % (self.ticket_replace_section_name, key)) continue subst = {'repository': reponame, 'revision': rev} pattern = field['pattern'].replace('$(', '%(') % subst replace = field['replace'].replace('$(', '%(') % subst message = re.sub(pattern, replace, message) if ChangesetModule(self.env).wiki_format_messages: message = '\n'.join( map(lambda line: "> " + line, message.split('\n'))) return tag.div(format_to_html(self.env, formatter.context.child( 'changeset', rev, parent=resource), message, escape_newlines=True), class_='message') else: return tag.pre(message, class_='message')
def _update_tickets(self, req, review): """Updates the tickets referenced by the given review's changeset with a comment of field changes. Field changes and command execution may occur if specified in trac.ini and the review's changeset is the last one of the ticket.""" status = review.encode(review.status).lower() summary = review.summaries[-1] # build comment if summary['status']: comment = "Code review set to %(status)s" % summary else: comment = "Code review comment" summary['_ref'] = review.changeset if review.repo: summary['_ref'] += '/' + review.repo comment += " for [%(_ref)s]:\n\n%(summary)s" % summary # find and update tickets # TODO: handle when there's no explicitly named repo repo = RepositoryManager(self.env).get_repository(review.repo) changeset = repo.get_changeset(review.changeset) ticket_re = CommitTicketUpdater.ticket_re tickets = ticket_re.findall(changeset.message) invoked = False for ticket in tickets: tkt = Ticket(self.env, ticket) # determine ticket changes changes = {} if self._is_complete(ticket, tkt, review, failed_ok=True): changes = self._get_ticket_changes(tkt, status) # update ticket if there's a review summary or ticket changes if summary['summary'] or changes: for field,value in changes.items(): tkt[field] = value tkt.save_changes(author=summary['reviewer'], comment=comment) # check to invoke command if not invoked and self._is_complete(ticket, tkt, review): self._execute_command(status) invoked = True return tickets
def _update_tickets(self, req, review): """Updates the tickets referenced by the given review's changeset with a comment of field changes. Field changes and command execution may occur if specified in trac.ini and the review's changeset is the last one of the ticket.""" status = review.encode(review.status).lower() summary = review.summaries[-1] # build comment if summary['status']: comment = "Code review set to %(status)s" % summary else: comment = "Code review comment" summary['_ref'] = review.changeset if review.repo: summary['_ref'] += '/' + review.repo comment += " for [%(_ref)s]:\n\n%(summary)s" % summary # find and update tickets # TODO: handle when there's no explicitly named repo repo = RepositoryManager(self.env).get_repository(review.repo) changeset = repo.get_changeset(review.changeset) ticket_re = CommitTicketUpdater.ticket_re tickets = ticket_re.findall(changeset.message) invoked = False for ticket in tickets: tkt = Ticket(self.env, ticket) # determine ticket changes changes = {} if self._is_complete(ticket, tkt, review, failed_ok=True): changes = self._get_ticket_changes(tkt, status) # update ticket if there's a review summary or ticket changes if summary['summary'] or changes: for field, value in changes.items(): tkt[field] = value tkt.save_changes(author=summary['reviewer'], comment=comment) # check to invoke command if not invoked and self._is_complete(ticket, tkt, review): self._execute_command(status) invoked = True return tickets
def expand_macro(self, formatter, name, content, args={}): if args: reponame = args.get('repository', '') rev = args.get('revision') else: if ',' in content: reponame = '' rev = 0 for c in [x.strip() for x in content.split(',')]: if c.isnumeric(): rev = c else: reponame = c else: rev = content.strip() reponame = '' repos = RepositoryManager(self.env).get_repository(reponame) if repos: changeset = repos.get_changeset(rev) message = changeset.message rev = changeset.rev else: message = content if formatter.context.resource.realm == 'ticket': ticket_re = CommitTicketUpdater.ticket_re if not any(int(tkt_id) == formatter.context.resource.id for tkt_id in ticket_re.findall(message)): return tag.div(tag.p(_("(The changeset message doesn't " "reference this ticket)"), class_='hint'), class_='commitmessage') if ChangesetModule(self.env).wiki_format_messages: return tag.div(format_to_html(self.env, formatter.context('changeset', rev, parent=repos.resource), message, escape_newlines=True), class_='commitmessage') else: return tag.pre(message, class_='commitmessage')