Exemplo n.º 1
0
    def for_request(cls, env, req, create=False):
        """
        Return a **single** subscription for a HTTP request.
        """
        rm = RepositoryManager(env)

        dict_ = {
            'user': req.authname,
            'type': req.args.get('realm'),
            'path': '',
            'rev': '',
            'repos': '',
        }
        path = req.args.get('path') or ''

        if dict_['type'] == 'attachment':
            dict_['path'] = path

        if dict_['type'] == 'changeset':
            parts = [p for p in path.split('/') if p]
            dict_['rev'] = parts[0]
            dict_['repos'] = parts[1]

        if dict_['type'] == 'browser':
            reponame, repos, path = rm.get_repository_by_path(path)
            dict_['path'] = '/' if len(path) == 0 else path
            dict_['rev'] = req.args.get('rev') or ''
            dict_['repos'] = reponame

        return cls.from_dict(env, dict_, create=create)
Exemplo n.º 2
0
    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'):
            rm = RepositoryManager(env)
            reponame, repos, path = rm.get_repository_by_path(comment.path)
            if comment.type == 'browser':
                sub['path'] = path
            else:
                sub['path'] = ''
            sub['repos'] = reponame or '(default)'
            try:
                _cs = repos.get_changeset(comment.revision)
            except NoSuchChangeset:
                # Invalid changeset
                return None
            else:
                sub['rev'] = _cs.rev

        return cls.from_dict(env, sub)
Exemplo n.º 3
0
def _process_changeset_view(self, request):
    request.perm.require('CHANGESET_VIEW')

    new = request.args.get('new')
    new_path = request.args.get('new_path')
    old = request.args.get('old')
    repository_name = request.args.get('reponame')

    # -- support for the revision log ''View changes'' form,
    #    where we need to give the path and revision at the same time
    if old and '@' in old:
        old, old_path = old.split('@', 1)
    if new and '@' in new:
        new, new_path = new.split('@', 1)

    manager = RepositoryManager(self.env)

    if repository_name:
        repository = manager.get_repository(repository_name)
    else:
        repository_name, repository, new_path = manager.get_repository_by_path(new_path)

    repository_url = repository.params.get('url', '')

    if _valid_github_request(request) and re.match(r'^https?://(?:www\.)?github\.com/', repository_url):
        url = repository_url.rstrip('/') + '/'

        if old:
            url += 'compare/' + old + '...' + new
        else:
            url += 'commit/' + new

        request.redirect(url)
    else:
        return _old_process_changeset_view(self, request)
Exemplo n.º 4
0
def _process_browser_view(self, request):
    request.perm.require('BROWSER_VIEW')

    preselected = request.args.get('preselected')
    if preselected and (preselected + '/').startswith(request.href.browser() + '/'):
        request.redirect(preselected)

    elif request.path_info.startswith('/browser') and _valid_github_request(request):
        path = request.args.get('path', '/')
        rev = request.args.get('rev', '')
        if rev.lower() in ('', 'head'):
            rev = 'master'

        manager = RepositoryManager(self.env)
        repository_name, repository, path = manager.get_repository_by_path(path)
        repository_url = repository.params.get('url', '')

        if re.match(r'^https?://(?:www\.)?github\.com/', repository_url):
            url = repository_url.rstrip('/') + '/blob/' + rev + '/' + path
            request.redirect(url)
        else:
            return _old_process_browser_view(self, request)

    else:
        return _old_process_browser_view(self, request)
    def for_request(cls, env, req, create=False):
        """
        Return a **single** subscription for a HTTP request.
        """
        rm = RepositoryManager(env)

        dict_ = {
            'user': req.authname,
            'type': req.args.get('realm'),
            'path': '',
            'rev': '',
            'repos': '',
        }
        path = req.args.get('path') or ''

        if dict_['type'] == 'attachment':
            dict_['path'] = path

        if dict_['type'] == 'changeset':
            parts = [p for p in path.split('/') if p]
            dict_['rev'] = parts[0]
            dict_['repos'] = parts[1]

        if dict_['type'] == 'browser':
            reponame, repos, path = rm.get_repository_by_path(path)
            dict_['path'] = '/' if len(path) == 0 else path
            dict_['rev'] = req.args.get('rev') or ''
            dict_['repos'] = reponame

        return cls.from_dict(env, dict_, create=create)
    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'):
            rm = RepositoryManager(env)
            reponame, repos, path = rm.get_repository_by_path(comment.path)
            if comment.type == 'browser':
                sub['path'] = path
            else:
                sub['path'] = ''
            sub['repos'] = reponame or '(default)'
            try:
                _cs = repos.get_changeset(comment.revision)
            except NoSuchChangeset:
                # Invalid changeset
                return None
            else:
                sub['rev'] = _cs.rev

        return cls.from_dict(env, sub)
Exemplo n.º 7
0
    def for_comment(cls, env, comment, notify=None):
        """
        Return all subscriptions for a comment.
        """
        args = {}
        if comment.type == 'attachment':
            args['type'] = comment.type
            args['path'] = comment.path.split(':')[1]

        if comment.type == 'changeset':
            args['type'] = comment.type
            args['rev'] = str(comment.revision)

        if comment.type == 'browser':
            rm = RepositoryManager(env)
            reponame, _, path = rm.get_repository_by_path(comment.path)
            args['type'] = ('browser', 'changeset')
            args['path'] = (path, '')
            args['repos'] = reponame
            args['rev'] = (str(comment.revision), '')

        return cls.select(env, args, notify)
    def for_comment(cls, env, comment, notify=None):
        """
        Return all subscriptions for a comment.
        """
        args = {}
        if comment.type == 'attachment':
            args['type'] = comment.type
            args['path'] = comment.path.split(':')[1]

        if comment.type == 'changeset':
            args['type'] = comment.type
            args['rev'] = str(comment.revision)

        if comment.type == 'browser':
            rm = RepositoryManager(env)
            reponame, _, path = rm.get_repository_by_path(comment.path)
            args['type'] = ('browser', 'changeset')
            args['path'] = (path, '')
            args['repos'] = reponame
            args['rev'] = (str(comment.revision), '')

        return cls.select(env, args, notify)