コード例 #1
0
    def _format_sha_link(self, formatter, sha, label):
        # FIXME: this function needs serious rethinking...

        reponame = ''

        context = formatter.context
        while context:
            if context.resource.realm in ('source', 'changeset'):
                reponame = context.resource.parent.id
                break
            context = context.parent

        try:
            repos = RepositoryManager(self.env).get_repository(reponame)

            if not repos:
                raise Exception("Repository '%s' not found" % reponame)

            sha = repos.normalize_rev(sha) # in case it was abbreviated
            changeset = repos.get_changeset(sha)
            return tag.a(label, class_='changeset',
                         title=shorten_line(changeset.message),
                         href=formatter.href.changeset(sha, repos.reponame))
        except Exception as e:
            return tag.a(label, class_='missing changeset',
                         title=to_unicode(e), rel='nofollow')
コード例 #2
0
ファイル: git_fs.py プロジェクト: sapo/trac-git-plugin
    def _format_sha_link(self, formatter, sha, label):
        # FIXME: this function needs serious rethinking...

        reponame = ''

        context = formatter.context
        while context:
            if context.resource.realm in ('source', 'changeset'):
                reponame = context.resource.parent.id
                break
            context = context.parent

        repos = RepositoryManager(self.env).get_all_repositories()

        for r in repos:
            try:
                testrepo = RepositoryManager(self.env).get_repository(r)
                testrepo.get_changeset(testrepo.normalize_rev(sha))
                reponame = testrepo.reponame
            except Exception, e:
                self.log.debug("%s not found in repo: %s" % (sha, r))
コード例 #3
0
ファイル: revision_links.py プロジェクト: dafrito/trac-mirror
 def _format_revision_link(self, formatter, ns, reponame, rev, label,
                           fullmatch=None):
     rev, params, fragment = formatter.split_link(rev)
     try:
         repos = RepositoryManager(self.env).get_repository(reponame)
         if repos:
             changeset = repos.get_changeset(rev)
             return tag.a(label, class_="changeset",
                          title=shorten_line(changeset.message),
                          href=(formatter.href.changeset(rev) +
                                params + fragment))
     except NoSuchChangeset:
         pass
     return tag.a(label, class_="missing changeset", rel="nofollow",
                  href=formatter.href.changeset(rev))
コード例 #4
0
 def _format_revision_link(self, formatter, ns, reponame, rev, label,
                           fullmatch=None):
     rev, params, fragment = formatter.split_link(rev)
     try:
         repos = RepositoryManager(self.env).get_repository(reponame)
         if repos:
             changeset = repos.get_changeset(rev)
             return tag.a(label, class_="changeset",
                          title=shorten_line(changeset.message),
                          href=(formatter.href.changeset(rev) +
                                params + fragment))
     except NoSuchChangeset:
         pass
     return tag.a(label, class_="missing changeset", rel="nofollow",
                  href=formatter.href.changeset(rev))
コード例 #5
0
        def sha_link(sha, label=None):
            # sha is assumed to be a non-abbreviated 40-chars sha id
            try:
                reponame = context.resource.parent.id
                repos = RepositoryManager(self.env).get_repository(reponame)
                cset = repos.get_changeset(sha)
                if label is None:
                    label = repos.display_rev(sha)

                return tag.a(label, class_='changeset',
                             title=shorten_line(cset.message),
                             href=context.href.changeset(sha, repos.reponame))

            except Exception as e:
                return tag.a(sha, class_='missing changeset',
                             title=to_unicode(e), rel='nofollow')
コード例 #6
0
    def expand_macro(self, formatter, name, content, args={}):
        reponame = args.get('repository') or ''
        rev_str = args.get('revision')
        repos = RepositoryManager(self.env).get_repository(reponame)
        rev = None
        try:
            changeset = repos.get_changeset(repos.normalize_rev(rev_str))
            message = changeset.message
            rev = repos.db_rev(changeset.rev)
            resource = repos.resource

            # 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}}}'

        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:
            ctxt = formatter.context
            return tag.div(format_to_html(self.env,
                                          ctxt('changeset',
                                               rev,
                                               parent=resource),
                                          message,
                                          escape_newlines=True),
                           class_='message')
        else:
            return tag.pre(message, class_='message')