示例#1
0
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()))
示例#2
0
 def make_hook(self, data):
     if self.context.get('hook'):
         hook = self.context['hook']
         for key, value in data.items():
             setattr(hook, key, value)
     else:
         hook = Hook(**data)
     return hook
示例#3
0
 def make_hook(self, data, **kwargs):
     if self.context.get("hook"):
         hook = self.context["hook"]
         for key, value in data.items():
             setattr(hook, key, value)
     else:
         hook = Hook(**data)
     return hook
示例#4
0
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()))
示例#5
0
 def make_hook(self, data):
     return Hook(**data)