Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ dmypy.json
.pyre/

# VS Code
.vscode
.vscode
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ repos:
hooks:
- id: pydocstyle
args: [--convention=google]
exclude: "tests"

- repo: https://github.com/pre-commit/mirrors-mypy
rev: v0.812
Expand Down
6 changes: 3 additions & 3 deletions cli/cdevents/cli/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,11 @@

import click
import yaml

from cdevents.cli.constants import LOGGING_CONFIGURATION_FILE

from cdevents.cli.artifact import packaged, published
from cdevents.cli.branch import created as branch_created
from cdevents.cli.branch import deleted as branch_deleted
from cdevents.cli.build import finished, queued, started
from cdevents.cli.constants import LOGGING_CONFIGURATION_FILE
from cdevents.cli.env import created as env_created
from cdevents.cli.env import deleted as env_deleted
from cdevents.cli.env import modified as env_modified
Expand Down Expand Up @@ -84,10 +82,12 @@ def pipelinerun():
pipelinerun.add_command(pipe_finished)
pipelinerun.add_command(pipe_queued)


@click.group(help=add_disclaimer_text("""Commands Repository related CloudEvent."""))
def repository():
"""Click group for command 'repository'."""


repository.add_command(repo_created)
repository.add_command(repo_modified)
repository.add_command(repo_deleted)
Expand Down
9 changes: 6 additions & 3 deletions cli/cdevents/cli/artifact.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Module for cli artifact commands."""
from __future__ import annotations

from typing import List
import click

from cdevents.cli.utils import add_disclaimer_text, print_function_args
import click
from cdevents.cli.cdevents_command import CDeventsCommand

from cdevents.cli.utils import add_disclaimer_text, print_function_args
from cdevents.core.artifact import ArtifactPackagedEvent, ArtifactPublishedEvent


# pylint: disable=unused-argument
def common_artifact_options(function):
"""Decorator for common cli options for artifact."""
Expand Down Expand Up @@ -52,6 +53,7 @@ def packaged(
version: str = None,
data: List[str] = None,
):
"""Creates an ArtifactPackaged CDEvent."""
print_function_args()
artifact_event = ArtifactPackagedEvent(id=id, name=name, version=version, data=data)
cdevents_command = CDeventsCommand()
Expand All @@ -66,6 +68,7 @@ def published(
version: str = None,
data: List[str] = None,
):
"""Creates an ArtifactPublished CDEvent."""
print_function_args()
artifact_event = ArtifactPublishedEvent(id=id, name=name, version=version, data=data)
cdevents_command = CDeventsCommand()
Expand Down
9 changes: 6 additions & 3 deletions cli/cdevents/cli/branch.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
"""Module for cli branch commands."""
from __future__ import annotations

from typing import List
import click

from cdevents.cli.utils import add_disclaimer_text, print_function_args
import click
from cdevents.cli.cdevents_command import CDeventsCommand

from cdevents.cli.utils import add_disclaimer_text, print_function_args
from cdevents.core.branch import BranchCreatedEvent, BranchDeletedEvent


# pylint: disable=unused-argument
def common_branch_options(function):
"""Decorator for common cli options for branch."""
Expand Down Expand Up @@ -52,6 +53,7 @@ def created(
repoid: str = None,
data: List[str] = None,
):
"""Creates a BranchCreated CDEvent."""
print_function_args()
branch_event = BranchCreatedEvent(id=id, name=name, repoid=repoid, data=data)
cdevents_command = CDeventsCommand()
Expand All @@ -66,6 +68,7 @@ def deleted(
repoid: str = None,
data: List[str] = None,
):
"""Creates a BranchDeleted CDEvent."""
print_function_args()
branch_event = BranchDeletedEvent(id=id, name=name, repoid=repoid, data=data)
cdevents_command = CDeventsCommand()
Expand Down
12 changes: 9 additions & 3 deletions cli/cdevents/cli/build.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Module for cli build commands."""
from __future__ import annotations

from typing import List
import click

from cdevents.cli.utils import add_disclaimer_text, print_function_args
import click
from cdevents.cli.cdevents_command import CDeventsCommand
from cdevents.cli.utils import add_disclaimer_text, print_function_args
from cdevents.core.build import BuildFinishedEvent, BuildQueuedEvent, BuildStartedEvent

from cdevents.core.build import BuildStartedEvent, BuildQueuedEvent, BuildFinishedEvent

# pylint: disable=unused-argument
def common_build_options(function):
Expand Down Expand Up @@ -53,11 +54,13 @@ def started(
artifact: str = None,
data: List[str] = None,
):
"""Creates a BuildStarted CDEvent."""
print_function_args()
build_event = BuildStartedEvent(id=id, name=name, artifact=artifact, data=data)
cdevents_command = CDeventsCommand()
cdevents_command.run(build_event)


@click.command(help=add_disclaimer_text("Build Finished CloudEvent."))
@common_build_options
def finished(
Expand All @@ -66,11 +69,13 @@ def finished(
artifact: str = None,
data: List[str] = None,
):
"""Creates a BuildFinished CDEvent."""
print_function_args()
build_event = BuildQueuedEvent(id=id, name=name, artifact=artifact, data=data)
cdevents_command = CDeventsCommand()
cdevents_command.run(build_event)


@click.command(help=add_disclaimer_text("PipelineRun Queued CloudEvent."))
@common_build_options
def queued(
Expand All @@ -79,6 +84,7 @@ def queued(
artifact: str = None,
data: List[str] = None,
):
"""Creates a BuildQueued CDEvent."""
print_function_args()
build_event = BuildFinishedEvent(id=id, name=name, artifact=artifact, data=data)
cdevents_command = CDeventsCommand()
Expand Down
14 changes: 6 additions & 8 deletions cli/cdevents/cli/cdevents_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
import logging
from abc import ABC

from cloudevents.http import CloudEvent

from cdevents.cli.configuration_handler import (
ConfigurationHandler,
new_default_configuration_handler,
)
from cdevents.core.event_sender import EventSender

from cdevents.cli.configuration_handler import ConfigurationHandler
from cdevents.cli.configuration_handler import new_default_configuration_handler
from cloudevents.http import CloudEvent


class CDeventsCommand(ABC):
Expand All @@ -25,12 +25,10 @@ def __init__(self, config_handler: ConfigurationHandler = None):
self._config_handler = new_default_configuration_handler()

def run(self, event: CloudEvent):
"""run command.
"""
"""Run command."""
e = EventSender(cde_link=self.config_handler.client.host)
e.send(event)


@property
def config_handler(self) -> ConfigurationHandler:
"""Property for configuration handler."""
Expand Down
15 changes: 7 additions & 8 deletions cli/cdevents/cli/configuration_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,20 @@ def get_default_configuration_file() -> str:
"""Returns the default configuration file path."""
return DEFAULT_CONFIGURATION_FILE


def new_default_configuration_handler() -> ConfigurationHandler:
"""Returnes a configuration handler with the default configuration file"""
"""Returns a configuration handler with the default configuration file."""
config_handler: ConfigurationHandler = ConfigurationHandler.create_new(
get_default_configuration_file()
)

return config_handler


def new_configuration_handler_with_override(
client_host, source_name
) -> ConfigurationHandler:
"""Returnes a configuration handler where args override configuration file."""
def new_configuration_handler_with_override(client_host, source_name) -> ConfigurationHandler:
"""Returns a configuration handler where args override configuration file."""
args_as_config = ConfigurationHandler.create_override_config(
client_host=client_host,
source_name=source_name
client_host=client_host, source_name=source_name
)

config_handler: ConfigurationHandler = ConfigurationHandler.create_new(
Expand All @@ -45,7 +43,7 @@ class ConfigurationHandler:
"""Class for providing configuration."""

def __init__(self, configuration: dict):
"""Initializes the configuration.
"""Initializes the configuration.

Args:
configuration (dict): The configuration.
Expand Down Expand Up @@ -117,6 +115,7 @@ def create_new(
class _ClientConfig:
host: str


@dataclass
class _SourceConfig:
name: str
1 change: 0 additions & 1 deletion cli/cdevents/cli/configuration_reader.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from typing import Union

import yaml

from cdevents.cli.utils import DictUtils


Expand Down
16 changes: 13 additions & 3 deletions cli/cdevents/cli/env.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
"""Module for cli environment commands."""
from __future__ import annotations

from typing import List
import click

from cdevents.cli.utils import add_disclaimer_text, print_function_args
import click
from cdevents.cli.cdevents_command import CDeventsCommand
from cdevents.cli.utils import add_disclaimer_text, print_function_args
from cdevents.core.env import (
EnvEventCreatedEvent,
EnvEventDeletedEvent,
EnvEventModifiedEvent,
)

from cdevents.core.env import EnvEventCreatedEvent, EnvEventModifiedEvent, EnvEventDeletedEvent

# pylint: disable=unused-argument
def common_env_options(function):
Expand Down Expand Up @@ -52,11 +57,13 @@ def created(
repo: str = None,
data: List[str] = None,
):
"""Creates an EnvironmentCreated CDEvent."""
print_function_args()
env_event = EnvEventCreatedEvent(id=id, name=name, repo=repo, data=data)
cdevents_command = CDeventsCommand()
cdevents_command.run(env_event)


@click.command(help=add_disclaimer_text("Environment Deleted CloudEvent."))
@common_env_options
def deleted(
Expand All @@ -65,11 +72,13 @@ def deleted(
repo: str = None,
data: List[str] = None,
):
"""Creates an EnvironmentDeleted CDEvent."""
print_function_args()
env_event = EnvEventModifiedEvent(id=id, name=name, repo=repo, data=data)
cdevents_command = CDeventsCommand()
cdevents_command.run(env_event)


@click.command(help=add_disclaimer_text("Environment Modified CloudEvent."))
@common_env_options
def modified(
Expand All @@ -78,6 +87,7 @@ def modified(
repo: str = None,
data: List[str] = None,
):
"""Creates an EnvironmentModified CDEvent."""
print_function_args()
env_event = EnvEventDeletedEvent(id=id, name=name, repo=repo, data=data)
cdevents_command = CDeventsCommand()
Expand Down
29 changes: 21 additions & 8 deletions cli/cdevents/cli/pipelinerun.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
"""Module for cli pipelinerun commands."""
from __future__ import annotations

from typing import List
import click

from cdevents.cli.utils import add_disclaimer_text, print_function_args
import click
from cdevents.cli.cdevents_command import CDeventsCommand
from cdevents.cli.utils import add_disclaimer_text, print_function_args
from cdevents.core.pipelinerun import (
PipelinerunFinishedEvent,
PipelinerunQueuedEvent,
PipelinerunStartedEvent,
)

from cdevents.core.pipelinerun import PipelinerunStartedEvent, PipelinerunFinishedEvent, PipelinerunQueuedEvent

# pylint: disable=unused-argument
def common_pipelinerun_options(function):
Expand Down Expand Up @@ -68,11 +73,15 @@ def started(
errors: str = None,
data: List[str] = None,
):
"""Creates a PipelineRunStarted CDEvent."""
print_function_args()
pipelinerun_event = PipelinerunStartedEvent(id=id, name=name, status=status, url=url, errors=errors, data=data)
pipelinerun_event = PipelinerunStartedEvent(
id=id, name=name, status=status, url=url, errors=errors, data=data
)
cdevents_command = CDeventsCommand()
cdevents_command.run(pipelinerun_event)


@click.command(help=add_disclaimer_text("PipelineRun Finished CloudEvent."))
@common_pipelinerun_options
def finished(
Expand All @@ -83,8 +92,11 @@ def finished(
errors: str = None,
data: List[str] = None,
):
"""Creates a PipelineRunFinished CDEvent."""
print_function_args()
pipelinerun_event = PipelinerunFinishedEvent(id=id, name=name, status=status, url=url, errors=errors, data=data)
pipelinerun_event = PipelinerunFinishedEvent(
id=id, name=name, status=status, url=url, errors=errors, data=data
)
cdevents_command = CDeventsCommand()
cdevents_command.run(pipelinerun_event)

Expand All @@ -99,9 +111,10 @@ def queued(
errors: str = None,
data: List[str] = None,
):
"""Creates a PipelineRunQueued CDEvent."""
print_function_args()
pipelinerun_event = PipelinerunQueuedEvent(id=id, name=name, status=status, url=url, errors=errors, data=data)
pipelinerun_event = PipelinerunQueuedEvent(
id=id, name=name, status=status, url=url, errors=errors, data=data
)
cdevents_command = CDeventsCommand()
cdevents_command.run(pipelinerun_event)


Loading