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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ event = cdevents.new_pipelinerun_queued_event(
context_timestamp=datetime.datetime.now(),
subject_id="myPipelineRun1",
custom_data={"hello_message": "hi!"},
subject_source="subjectSource",
custom_data_content_type="application/json",
pipeline_name="myPipeline",
url="https://example.com/myPipeline",
Expand Down
37 changes: 20 additions & 17 deletions src/cdevents/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
"""Events under dev.cdevents.artifact."""
from dataclasses import dataclass, field
from datetime import datetime
import datetime
from typing import Dict, Union

from cdevents.cdevent import SPEC_VERSION, CDEvent
from cdevents.context import Context
from cdevents.subject import Subject
from pydanticEvent import parsedEvent


@dataclass
Expand Down Expand Up @@ -85,28 +87,28 @@ def new_artifact_packaged_event(
custom_data: Union[str, Dict, None],
custom_data_content_type: str,
) -> ArtifactPackagedEvent:
input_data = parsedEvent(context_id= context_id, context_source = context_source, context_timestamp = context_timestamp, subject_id = subject_id, subject_source = subject_source,
change=change, custom_data = custom_data, custom_data_content_type = custom_data_content_type)
"""Creates a new artifact packaged CDEvent."""
context = Context(
type=ArtifactPackagedEvent.CDEVENT_TYPE,
version=SPEC_VERSION,
id=context_id,
source=context_source,
timestamp=context_timestamp,
id=input_data.context_id,
source=input_data.context_source,
timestamp=input_data.context_timestamp,
)

content = ArtifactPackagedSubjectContent(change=change)
subject = ArtifactPackagedSubject(id=subject_id, source=subject_source, content=content)
content = ArtifactPackagedSubjectContent(change=input_data.change)
subject = ArtifactPackagedSubject(id=input_data.subject_id, source=input_data.subject_source, content=content)

event = ArtifactPackagedEvent(
context=context,
subject=subject,
custom_data=custom_data,
custom_data_content_type=custom_data_content_type,
custom_data=input_data.custom_data,
custom_data_content_type=input_data.custom_data_content_type,
)

return event


# endregion ArtifactPackagedEvent

# region ArtifactPublishedEvent
Expand All @@ -131,25 +133,26 @@ def new_artifact_published_event(
custom_data: Union[str, Dict, None],
custom_data_content_type: str,
) -> ArtifactPublishedEvent:
input_data = parsedEvent(context_id= context_id, context_source = context_source, context_timestamp = context_timestamp, subject_id = subject_id, subject_source = subject_source,
custom_data = custom_data, custom_data_content_type = custom_data_content_type)
"""Creates a new artifact published CDEvent."""
context = Context(
type=ArtifactPublishedEvent.CDEVENT_TYPE,
version=SPEC_VERSION,
id=context_id,
source=context_source,
timestamp=context_timestamp,
id=input_data.context_id,
source=input_data.context_source,
timestamp=input_data.context_timestamp,
)

subject = ArtifactPublishedSubject(id=subject_id, source=subject_source)
subject = ArtifactPublishedSubject(id=input_data.subject_id, source=input_data.subject_source)

event = ArtifactPublishedEvent(
context=context,
subject=subject,
custom_data=custom_data,
custom_data_content_type=custom_data_content_type,
custom_data=input_data.custom_data,
custom_data_content_type=input_data.custom_data_content_type,
)

return event


# endregion ArtifactPublishedEvent
# endregion ArtifactPublishedEvent
38 changes: 21 additions & 17 deletions src/cdevents/branch.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@
"""Events under dev.cdevents.branch."""
from dataclasses import dataclass, field
from datetime import datetime
import datetime
from typing import Dict, Optional, Union

from cdevents.cdevent import SPEC_VERSION, CDEvent
from cdevents.context import Context
from cdevents.subject import Subject
from pydanticEvent import parsedEvent


@dataclass
Expand Down Expand Up @@ -64,28 +66,29 @@ def new_branch_created_event(
custom_data: Union[str, Dict, None],
custom_data_content_type: str,
) -> BranchCreatedEvent:
input_data = parsedEvent(context_id= context_id, context_source = context_source, context_timestamp = context_timestamp, subject_id = subject_id, subject_source = subject_source,
repository=repository, custom_data = custom_data, custom_data_content_type = custom_data_content_type)
"""Creates a new branch created CDEvent."""
context = Context(
type=BranchCreatedEvent.CDEVENT_TYPE,
version=SPEC_VERSION,
id=context_id,
source=context_source,
timestamp=context_timestamp,
id=input_data.context_id,
source=input_data.context_source,
timestamp=input_data.context_timestamp,
)

content = BranchSubjectContent(repository=repository)
subject = BranchSubject(id=subject_id, source=subject_source, content=content)
content = BranchSubjectContent(repository=input_data.repository)
subject = BranchSubject(id=input_data.subject_id, source=input_data.subject_source, content=content)

event = BranchCreatedEvent(
context=context,
subject=subject,
custom_data=custom_data,
custom_data_content_type=custom_data_content_type,
custom_data=input_data.custom_data,
custom_data_content_type=input_data.custom_data_content_type,
)

return event


# endregion BranchCreatedEvent


Expand All @@ -112,26 +115,27 @@ def new_branch_deleted_event(
custom_data: Union[str, Dict, None],
custom_data_content_type: str,
) -> BranchDeletedEvent:
input_data = parsedEvent(context_id= context_id, context_source = context_source, context_timestamp = context_timestamp, subject_id = subject_id, subject_source = subject_source,
repository=repository, custom_data = custom_data, custom_data_content_type = custom_data_content_type)
"""Creates a new branch deleted CDEvent."""
context = Context(
type=BranchDeletedEvent.CDEVENT_TYPE,
version=SPEC_VERSION,
id=context_id,
source=context_source,
timestamp=context_timestamp,
id=input_data.context_id,
source=input_data.context_source,
timestamp=input_data.context_timestamp,
)

content = BranchSubjectContent(repository=repository)
subject = BranchSubject(id=subject_id, source=subject_source, content=content)
content = BranchSubjectContent(repository=input_data.repository)
subject = BranchSubject(id=input_data.subject_id, source=input_data.subject_source, content=content)

event = BranchDeletedEvent(
context=context,
subject=subject,
custom_data=custom_data,
custom_data_content_type=custom_data_content_type,
custom_data=input_data.custom_data,
custom_data_content_type=input_data.custom_data_content_type,
)

return event


# endregion BranchDeletedEvent
# endregion BranchDeletedEvent
72 changes: 34 additions & 38 deletions src/cdevents/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@
from dataclasses import dataclass, field
from datetime import datetime
from typing import Dict, Union
import datetime

from cdevents.cdevent import SPEC_VERSION, CDEvent
from cdevents.context import Context
from cdevents.subject import Subject

from pydanticEvent import parsedEvent

@dataclass
class BuildFinishedSubjectContent:
Expand All @@ -36,10 +37,10 @@ class BuildSubject(Subject):
"""Subject for build-related events."""

type: str = field(default="build", init=False)

content: Union[Dict, BuildFinishedSubjectContent] = field(default_factory=dict, init=False)



@dataclass
class BuildFinishedSubject(BuildSubject):
"""Subject for artifact-related messages."""
Expand All @@ -60,7 +61,6 @@ class BuildQueuedEvent(CDEvent):
subject: BuildSubject
"""Build subject."""


def new_build_queued_event(
context_id: str,
context_source: str,
Expand All @@ -70,32 +70,31 @@ def new_build_queued_event(
custom_data: Union[str, Dict, None],
custom_data_content_type: str,
) -> BuildQueuedEvent:
input_data = parsedEvent(context_id= context_id, context_source = context_source, context_timestamp = context_timestamp, subject_id = subject_id, subject_source = subject_source,
custom_data = custom_data, custom_data_content_type = custom_data_content_type)
"""Creates a new build queued CDEvent."""
context = Context(
type=BuildQueuedEvent.CDEVENT_TYPE,
version=SPEC_VERSION,
id=context_id,
source=context_source,
timestamp=context_timestamp,
type=BuildQueuedEvent.CDEVENT_TYPE,
version=SPEC_VERSION,
id=input_data.context_id,
source=input_data.context_source,
timestamp=input_data.context_timestamp,
)

subject = BuildSubject(id=subject_id, source=subject_source)
subject = BuildSubject(id=input_data.subject_id, source=input_data.subject_source)

event = BuildQueuedEvent(
context=context,
subject=subject,
custom_data=custom_data,
custom_data_content_type=custom_data_content_type,
custom_data=input_data.custom_data,
custom_data_content_type=input_data.custom_data_content_type
)

return event


# endregion BuildQueuedEvent

# region BuildStartedEvent


@dataclass
class BuildStartedEvent(CDEvent):
"""Build started event."""
Expand All @@ -113,34 +112,33 @@ def new_build_started_event(
subject_id: str,
subject_source: str,
custom_data: Union[str, Dict, None],
custom_data_content_type: str,
custom_data_content_type: str
) -> BuildStartedEvent:
input_data = parsedEvent(context_id= context_id, context_source = context_source, context_timestamp = context_timestamp, subject_id = subject_id, subject_source = subject_source,
custom_data = custom_data, custom_data_content_type = custom_data_content_type)
"""Creates a new build started CDEvent."""
context = Context(
type=BuildStartedEvent.CDEVENT_TYPE,
version=SPEC_VERSION,
id=context_id,
source=context_source,
timestamp=context_timestamp,
id=input_data.context_id,
source=input_data.context_source,
timestamp=input_data.context_timestamp
)

subject = BuildSubject(id=subject_id, source=subject_source)
subject = BuildSubject(id=input_data.subject_id, source=input_data.subject_source)

event = BuildStartedEvent(
context=context,
subject=subject,
custom_data=custom_data,
custom_data_content_type=custom_data_content_type,
custom_data=input_data.custom_data,
custom_data_content_type=input_data.custom_data_content_type
)

return event


# endregion BuildStartedEvent

# region BuildFinishedEvent


@dataclass
class BuildFinishedEvent(CDEvent):
"""Build finished event."""
Expand All @@ -150,7 +148,6 @@ class BuildFinishedEvent(CDEvent):
subject: BuildSubject
"""Build subject."""


def new_build_finished_event(
context_id: str,
context_source: str,
Expand All @@ -159,28 +156,27 @@ def new_build_finished_event(
subject_source: str,
artifact_id: str,
custom_data: Union[str, Dict, None],
custom_data_content_type: str,
custom_data_content_type: str
) -> BuildFinishedEvent:
input_data = parsedEvent(context_id = context_id, context_source = context_source, context_timestamp = context_timestamp, subject_id = subject_id, subject_source = subject_source,
custom_data = custom_data, custom_data_content_type = custom_data_content_type, artifact_id=artifact_id)
"""Creates a new build finished CDEvent."""
context = Context(
type=BuildFinishedEvent.CDEVENT_TYPE,
version=SPEC_VERSION,
id=context_id,
source=context_source,
timestamp=context_timestamp,
id=input_data.context_id,
source=input_data.context_source,
timestamp=input_data.context_timestamp,
)

content = BuildFinishedSubjectContent(artifact_id=artifact_id)
subject = BuildFinishedSubject(id=subject_id, source=subject_source, content=content)
content = BuildFinishedSubjectContent(artifact_id=input_data.artifact_id)
subject = BuildFinishedSubject(id=input_data.subject_id, source=input_data.subject_source, content=content)

event = BuildFinishedEvent(
context=context,
subject=subject,
custom_data=custom_data,
custom_data_content_type=custom_data_content_type,
custom_data=input_data.custom_data,
custom_data_content_type=input_data.custom_data_content_type,
)

return event


# endregion BuildFinishedEvent
# endregion BuildFinishedEvent
5 changes: 3 additions & 2 deletions src/cdevents/cdevent.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,12 @@
# SPDX-License-Identifier: Apache-2.0
"""CDEvents base types."""
from dataclasses import dataclass
from typing import Dict, TypeVar, Union
from typing import Dict, TypeVar, Union, Any

from cdevents.context import Context
from cdevents.subject import Subject


SPEC_VERSION = "0.1.0"


Expand All @@ -37,4 +38,4 @@ class CDEvent:
"""Custom data for event."""

custom_data_content_type: str
"""Type identifier for custom data."""
"""Type identifier for custom data."""
Loading