Add new option to package publishing CLI which allows to disable email notiication

This commit is contained in:
Ivan Kravets
2020-05-28 17:06:36 +03:00
parent ae58cc74bd
commit 26ba6e4756
2 changed files with 16 additions and 5 deletions

View File

@ -17,13 +17,15 @@ from platformio.clients.account import AccountClient
from platformio.clients.rest import RESTClient
from platformio.package.spec import PackageType
# pylint: disable=too-many-arguments
class RegistryClient(RESTClient):
def __init__(self):
super(RegistryClient, self).__init__(base_url=__registry_api__)
def publish_package(
self, archive_path, owner=None, released_at=None, private=False
self, archive_path, owner=None, released_at=None, private=False, notify=True
):
account = AccountClient()
if not owner:
@ -34,7 +36,11 @@ class RegistryClient(RESTClient):
response = self.send_request(
"post",
"/v3/package/%s/%s" % (owner, PackageType.from_archive(archive_path)),
params={"private": 1 if private else 0, "released_at": released_at},
params={
"private": 1 if private else 0,
"notify": 1 if notify else 0,
"released_at": released_at,
},
headers={
"Authorization": "Bearer %s" % account.fetch_authentication_token(),
"Content-Type": "application/octet-stream",
@ -46,7 +52,7 @@ class RegistryClient(RESTClient):
)
return response
def unpublish_package( # pylint: disable=redefined-builtin,too-many-arguments
def unpublish_package( # pylint: disable=redefined-builtin
self, type, name, owner=None, version=None, undo=False
):
account = AccountClient()

View File

@ -58,11 +58,16 @@ def package_pack(package):
help="Custom release date and time in the next format (UTC): 2014-06-13 17:08:52",
)
@click.option("--private", is_flag=True, help="Restricted access (not a public)")
def package_publish(package, owner, released_at, private):
@click.option(
"--notify/--no-notify",
default=True,
help="Notify by email when package is processed",
)
def package_publish(package, owner, released_at, private, notify):
p = PackagePacker(package)
archive_path = p.pack()
response = RegistryClient().publish_package(
archive_path, owner, released_at, private
archive_path, owner, released_at, private, notify
)
os.remove(archive_path)
click.secho(response.get("message"), fg="green")