Esempio n. 1
0
    def add_hook(self, save=True):

        if self.user_settings:
            connect = GitHub.from_settings(self.user_settings)
            secret = utils.make_hook_secret()
            hook = connect.add_hook(
                self.user, self.repo,
                'web',
                {
                    'url': urlparse.urljoin(
                        hook_domain,
                        os.path.join(
                            self.owner.api_url, 'github', 'hook/'
                        )
                    ),
                    'content_type': github_settings.HOOK_CONTENT_TYPE,
                    'secret': secret,
                }
            )

            if hook:
                self.hook_id = hook.id
                self.hook_secret = secret
                if save:
                    self.save()
Esempio n. 2
0
    def add_hook(self, save=True):

        if self.user_settings:
            connect = GitHub.from_settings(self.user_settings)
            secret = utils.make_hook_secret()
            hook = connect.add_hook(
                self.user, self.repo,
                'web',
                {
                    'url': urlparse.urljoin(
                        hook_domain,
                        os.path.join(
                            self.owner.api_url, 'github', 'hook/'
                        )
                    ),
                    'content_type': github_settings.HOOK_CONTENT_TYPE,
                    'secret': secret,
                }
            )

            if hook:
                self.hook_id = hook.id
                self.hook_secret = secret
                if save:
                    self.save()
def add_hook_to_old_node_settings(document, account):
    connect = GitHubClient(external_account=account)
    secret = make_hook_secret()
    hook = None
    try:
        hook = connect.add_hook(
            document['user'], document['repo'],
            'web',
            {
                'url': urlparse.urljoin(
                    HOOK_DOMAIN,
                    os.path.join(
                        Node.load(document['owner']).api_url, 'github', 'hook/'
                    )
                ),
                'content_type': github_settings.HOOK_CONTENT_TYPE,
                'secret': secret,
            },
            events=github_settings.HOOK_EVENTS,
        )
    except ApiError:
        pass
    if hook:
        database['addongithubnodesettings'].find_and_modify(
            {'_id': document['_id']},
            {
                '$set': {
                    'hook_id': hook.id,
                    'hook_secret': secret
                }
            }
        )
Esempio n. 4
0
def update_hook(node_settings):
    """Discard the existing webhook for a GitHub node add-on and create a new
    one.

    """
    logger.warn('Updating GitHub hook on node {0}'.format(
        node_settings.owner._id))

    connection = GitHub.from_settings(node_settings.user_settings)
    repo = connection.repo(node_settings.user, node_settings.repo)
    hook = repo.hook(node_settings.hook_id)

    if hook is None:
        logger.warn('Hook {0} not found'.format(node_settings.hook_id))
        return

    secret = utils.make_hook_secret()

    config = hook.config
    config['content_type'] = github_settings.HOOK_CONTENT_TYPE
    config['secret'] = secret

    hook.edit(config=config)

    node_settings.hook_secret = secret
    node_settings.save()
def add_hook_to_old_node_settings(document, account):
    connect = GitHubClient(external_account=account)
    secret = make_hook_secret()
    hook = None
    try:
        hook = connect.add_hook(
            document['user'],
            document['repo'],
            'web',
            {
                'url':
                urlparse.urljoin(
                    HOOK_DOMAIN,
                    os.path.join(
                        Node.load(document['owner']).api_url, 'github',
                        'hook/')),
                'content_type':
                github_settings.HOOK_CONTENT_TYPE,
                'secret':
                secret,
            },
            events=github_settings.HOOK_EVENTS,
        )
    except ApiError:
        pass
    if hook:
        database['addongithubnodesettings'].find_and_modify(
            {'_id': document['_id']},
            {'$set': {
                'hook_id': hook.id,
                'hook_secret': secret
            }})
Esempio n. 6
0
def update_hook(node_settings):
    """Discard the existing webhook for a GitHub node add-on and create a new
    one.

    """
    logger.warn(
        'Updating GitHub hook on node {0}'.format(
            node_settings.owner._id
        )
    )

    connection = GitHub.from_settings(node_settings.user_settings)
    repo = connection.repo(node_settings.user, node_settings.repo)
    hook = repo.hook(node_settings.hook_id)

    if hook is None:
        logger.warn('Hook {0} not found'.format(node_settings.hook_id))
        return

    secret = utils.make_hook_secret()

    config = hook.config
    config['content_type'] = github_settings.HOOK_CONTENT_TYPE
    config['secret'] = secret

    hook.edit(config=config)

    node_settings.hook_secret = secret
    node_settings.save()
Esempio n. 7
0
    def add_hook(self, save=True):

        if self.user_settings:
            connect = GitHub.from_settings(self.user_settings)
            secret = utils.make_hook_secret()
            hook = connect.add_hook(
                self.user,
                self.repo,
                "web",
                {
                    "url": urlparse.urljoin(hook_domain, os.path.join(self.owner.api_url, "github", "hook/")),
                    "content_type": github_settings.HOOK_CONTENT_TYPE,
                    "secret": secret,
                },
            )

            if hook:
                self.hook_id = hook.id
                self.hook_secret = secret
                if save:
                    self.save()