11"""build"""
22
3- from enum import Enum
4- from cdevents .core .event import Event
5-
6- class BuildType (Enum ):
7- BuildStartedEventV1 :str = "cd.build.started.v1"
8- BuildQueuedEventV1 :str = "cd.build.queued.v1"
9- BuildFinishedEventV1 :str = "cd.build.finished.v1"
10-
3+ from cdevents .core .event import Event
4+ from cdevents .core .event_type import EventType
115
126class BuildEvent (Event ):
137 """Build Event."""
148
15- def __init__ (self , build_type : BuildType , id : str , name : str , artifact : str , data : dict = {}):
9+ def __init__ (self , ** kwargs ):
1610 """Initializes class.
1711 """
18- self ._event_type = build_type
19- self ._id = id
20- self ._name = name
21- self ._artifact = artifact
22- super ().__init__ (event_type = self ._event_type .value , extensions = self .create_extensions (), data = data )
23-
12+ self ._event_type : EventType = kwargs ['build_type' ]
13+ if 'data' in kwargs :
14+ self ._data :dict = kwargs ['data' ]
15+
16+ if 'id' in kwargs and 'name' in kwargs and 'artifact' in kwargs :
17+ self ._id :str = kwargs ['id' ]
18+ self ._name :str = kwargs ['name' ]
19+ self ._artifact :str = kwargs ['artifact' ]
20+ super ().__init__ (event_type = self ._event_type .value , extensions = self .create_extensions (), data = self ._data )
21+
22+ elif 'extensions' in kwargs :
23+ self ._id = kwargs ['extensions' ].get ('buildid' ),
24+ self ._name = kwargs ['extensions' ].get ('buildname' )
25+ self ._artifact = kwargs ['extensions' ].get ('buildartifactid' )
26+ super ().__init__ (event_type = self ._event_type .value , extensions = self .create_extensions (), attrs = kwargs ['attrs' ], data = self ._data )
27+
2428 def create_extensions (self ) -> dict :
2529 """Create extensions.
2630 """
@@ -32,28 +36,28 @@ def create_extensions(self) -> dict:
3236 return extensions
3337
3438class BuildStartedEvent (BuildEvent ):
35-
36- def __init__ (self , id : str , name : str , artifact : str , data : dict = {} ):
39+ """Build Started Event."""
40+ def __init__ (self , ** kwargs ):
3741 """Initializes class.
3842 """
39- self ._event_type : str = BuildType .BuildStartedEventV1
43+ self ._event_type : str = EventType .BuildStartedEventV1
4044
41- super ().__init__ (build_type = self ._event_type , id = id , name = name , artifact = artifact , data = data )
42-
43- class BuildQueuedEvent (BuildEvent ):
45+ super ().__init__ (build_type = self ._event_type , ** kwargs )
4446
45- def __init__ (self , id : str , name : str , artifact : str , data : dict = {}):
47+ class BuildQueuedEvent (BuildEvent ):
48+ """Build Queued Event."""
49+ def __init__ (self , ** kwargs ):
4650 """Initializes class.
4751 """
48- self ._event_type : str = BuildType .BuildQueuedEventV1
52+ self ._event_type : str = EventType .BuildQueuedEventV1
4953
50- super ().__init__ (build_type = self ._event_type , id = id , name = name , artifact = artifact , data = data )
54+ super ().__init__ (build_type = self ._event_type , ** kwargs )
5155
5256class BuildFinishedEvent (BuildEvent ):
53-
54- def __init__ (self , id : str , name : str , artifact : str , data : dict = {} ):
57+ """Build Finished Event."""
58+ def __init__ (self , ** kwargs ):
5559 """Initializes class.
5660 """
57- self ._event_type : str = BuildType .BuildFinishedEventV1
61+ self ._event_type : str = EventType .BuildFinishedEventV1
5862
59- super ().__init__ (build_type = self ._event_type , id = id , name = name , artifact = artifact , data = data )
63+ super ().__init__ (build_type = self ._event_type , ** kwargs )
0 commit comments