How to use the publish.publishing function in publish

To help you get started, we’ve selected a few publish examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github AuHau / ipfs-publish / tests / unit / test_publishing.py View on Github external
def test_publish_repo_bins(self, mocker):
        mocker.patch.object(git.Repo, 'clone_from')
        mocker.patch.object(shutil, 'rmtree')

        ipfs_client_mock = mocker.Mock(spec=ipfshttpclient.Client)
        ipfs_client_mock.add.return_value = [{'Hash': 'some-hash'}]

        mocker.patch.object(ipfshttpclient, 'connect')
        ipfshttpclient.connect.return_value = ipfs_client_mock

        mocker.patch.object(subprocess, 'run')
        subprocess.run.return_value = subprocess.CompletedProcess(None, 0)

        repo: publishing.GenericRepo = factories.RepoFactory(build_bin='some_cmd', after_publish_bin='some_other_cmd')
        repo.publish_repo()

        assert subprocess.run.call_count == 2
        subprocess.run.assert_called_with(f'some_other_cmd /ipfs/some-hash/', shell=True, capture_output=True)
        subprocess.run.assert_any_call(f'some_cmd ', shell=True, capture_output=True)
github AuHau / ipfs-publish / tests / factories.py View on Github external
model = config_module.Config


class RepoFactory(PublishFactory):
    config = factory.SubFactory(ConfigFactory)
    name = factory.Faker('slug')
    git_repo_url = factory.Faker('url')
    secret = factory.Faker('pystr', min_chars=20, max_chars=20)

    class Meta:
        model = publishing.GenericRepo


class GithubRepoFactory(RepoFactory):
    class Meta:
        model = publishing.GithubRepo
github AuHau / ipfs-publish / tests / unit / test_publishing.py View on Github external
def test_publish_repo_basic(self, mocker):
        mocker.patch.object(git.Repo, 'clone_from')
        mocker.patch.object(shutil, 'rmtree')

        ipfs_client_mock = mocker.Mock(spec=ipfshttpclient.Client)
        ipfs_client_mock.add.return_value = [{'Hash': 'some-hash'}]

        mocker.patch.object(ipfshttpclient, 'connect')
        ipfshttpclient.connect.return_value = ipfs_client_mock

        repo: publishing.GenericRepo = factories.RepoFactory()
        repo.publish_repo()

        ipfs_client_mock.add.assert_called_once_with(mocker.ANY, recursive=True, pin=True)
        ipfs_client_mock.pin.rm.assert_not_called()
        assert repo.last_ipfs_addr == '/ipfs/some-hash/'
github AuHau / ipfs-publish / publish / cli.py View on Github external
def show(ctx, name):
    """
    Displays details for repo with NAME, that is passed as argument.
    """
    config: config_module.Config = ctx.obj['config']
    repo: publishing.GenericRepo = config.repos.get(name)

    if repo is None:
        click.secho('Unknown repo!', fg='red')
        exit(1)

    click.secho(repo.name, fg='green')
    print_attribute('Git URL', repo.git_repo_url)
    print_attribute('Secret', repo.secret)
    print_attribute('IPNS key', repo.ipns_key)
    print_attribute('IPNS lifetime', repo.ipns_lifetime)
    print_attribute('IPNS ttl', repo.ipns_ttl)
    print_attribute('IPNS address', repo.ipns_addr)
    print_attribute('Last IPFS address', repo.last_ipfs_addr)
    print_attribute('Webhook address', f'{repo.webhook_url}')
github AuHau / ipfs-publish / publish / config.py View on Github external
def _load_data(self,
                   data):  # type: (typing.Dict[str, typing.Any]) -> typing.Tuple[dict, typing.Dict[str, publishing.Repo]]
        from publish import publishing

        self._verify_data(data)

        repos: typing.Dict[str, publishing.GenericRepo] = {}
        for value in data.pop('repos', {}).values():
            repo_class = publishing.get_repo_class(value['git_repo_url'])
            repo = repo_class.from_toml_dict(value, self)
            repos[repo.name] = repo

        return data, repos
github AuHau / ipfs-publish / publish / http.py View on Github external
def handler_dispatcher(repo: typing.Union[publishing.GenericRepo, publishing.GithubRepo]) -> 'GenericHandler':
    """
    Dispatch request to proper Handler based on what kind of repo the request is directed to.
    :param repo: Name of the repo
    :return:
    """
    if type(repo) is publishing.GenericRepo:
        return GenericHandler(repo)
    elif type(repo) is publishing.GithubRepo:
        return GithubHandler(repo)
    else:
        raise exceptions.HttpException('Unknown Repo\'s class!')
github AuHau / ipfs-publish / publish / cli.py View on Github external
def add(ctx, **kwargs):
    """
    Command that add new repo into the list of publishing repos. The values can be either specified using
    CLI's options, or using interactive bootstrap.

    If there is HTTP server running, it needs to be restarted in order the changes to be applied.
    """
    config: config_module.Config = ctx.obj['config']

    new_repo = publishing.bootstrap_repo(config, **kwargs)
    config.repos[new_repo.name] = new_repo
    config.save()

    click.secho('\nSuccessfully added new repo!', fg='green')

    webhook_url = click.style(f'{new_repo.webhook_url}', fg='yellow')
    click.echo(f'Use this URL for you webhook: {webhook_url}')

    if isinstance(new_repo, publishing.GithubRepo):
        click.echo(f'Also set this string as your hook\'s Secret: {click.style(new_repo.secret, fg="yellow")}')

    if new_repo.ipns_key is not None:
        click.echo(f'Your IPNS address: {click.style(new_repo.ipns_addr, fg="yellow")}')