def add(repository, provider): repo_bits = repository.split('/', 2) assert len( repo_bits ) == 3, 'repository not in valid format: {provider}/{owner}/{name}' repo = Repository.query.unrestricted_unsafe().filter( Repository.provider == RepositoryProvider(repo_bits[0]), Repository.owner_name == repo_bits[1], Repository.name == repo_bits[2], ).first() assert repo hook = Hook( repository_id=repo.id, provider=provider, ) db.session.add(hook) db.session.commit() click.echo('Hook created:') click.echo('-> id = {}'.format(str(hook.id))) click.echo('-> token = {}'.format( urlsafe_b64encode(hook.token).decode('utf-8'))) click.echo('-> provider = {}'.format(hook.provider)) click.echo('-> base_path = /hooks/{}/{}'.format(str(hook.id), hook.get_signature()))
def add(repository_url, provider): repo = Repository.query.unrestricted_unsafe().filter( Repository.url == repository_url, ).first() assert repo hook = Hook( repository_id=repo.id, provider=provider, ) db.session.add(hook) db.session.commit() click.echo('Hook created:') click.echo('-> id = {}'.format(str(hook.id))) click.echo('-> token = {}'.format( urlsafe_b64encode(hook.token).decode('utf-8'))) click.echo('-> provider = {}'.format(hook.provider)) click.echo('-> base_path = /hooks/{}/{}'.format(str(hook.id), hook.get_signature()))