diff --git a/hack/add-event.sh b/hack/add-event.sh new file mode 100755 index 0000000..15eefc1 --- /dev/null +++ b/hack/add-event.sh @@ -0,0 +1,145 @@ +#!/usr/bin/env bash + +# This script can be used to add a new event with empty data model +# based on the subject and predicate names + +# Usage: +# ./add-event.sh +# +# Both subect and predicate should be give in camelcase + +BASE_DIR="$( cd "$( dirname "$0" )/.." >/dev/null 2>&1 && pwd )" + +set -e + +SUBJECT=$1 +PREDICATE=$2 +SUBJECT_LOWER_CAMEL=${SUBJECT,} +SUBJECT_UPPER_CAMEL=${SUBJECT^} +SUBJECT_LOWER=${SUBJECT,,} +PREDICATE_LOWER_CAMEL=${PREDICATE,} +PREDICATE_UPPER_CAMEL=${PREDICATE^} +PREDICATE_LOWER=${PREDICATE,,} + +cat > "${BASE_DIR}/pkg/api/${SUBJECT_LOWER}${PREDICATE_LOWER}.go" << EOF +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL} event + ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}EventV1 CDEventType = "dev.cdevents.${SUBJECT_LOWER}.${PREDICATE_LOWER}.v1" +) + +type ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}SubjectContent struct {} + +type ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Subject struct { + SubjectBase + Content ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}SubjectContent \`json:"content"\` +} + +func (sc ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Subject) GetEventType() CDEventType { + return ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}EventV1 +} + +func (sc ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Subject) GetSubjectType() SubjectType { + return ${SUBJECT_UPPER_CAMEL}SubjectType +} + +type ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event struct { + Context Context \`json:"context"\` + Subject ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Subject \`json:"subject"\` +} + +// CDEventsReader implementation + +func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetType() CDEventType { + return ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}EventV1 +} + +func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetId() string { + return e.Context.Id +} + +func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetSource() string { + return e.Context.Source +} + +func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetSubjectId() string { + return e.Subject.Id +} + +func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) SetId(id string) { + e.Context.Id = id +} + +func (e *${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func new${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event() CDEvent { + return &${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Event{ + Context: Context{ + Type: ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}EventV1, + Version: CDEventsSpecVersion, + }, + Subject: ${SUBJECT_UPPER_CAMEL}${PREDICATE_UPPER_CAMEL}Subject{}, + } +} +EOF + +echo "Created ${BASE_DIR}/pkg/api/${SUBJECT_LOWER}${PREDICATE_LOWER}.go" \ No newline at end of file diff --git a/hack/add-events.sh b/hack/add-events.sh new file mode 100755 index 0000000..fae8a67 --- /dev/null +++ b/hack/add-events.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env bash + +BASE_DIR="$( cd "$( dirname "$0" )" >/dev/null 2>&1 && pwd )" +cd $BASE_DIR + +./add-event.sh repository created +./add-event.sh repository modified +./add-event.sh repository deleted +./add-event.sh branch created +./add-event.sh branch deleted +./add-event.sh change created +./add-event.sh change updated +./add-event.sh change reviewed +./add-event.sh change merged +./add-event.sh change abandoned +./add-event.sh build started +./add-event.sh build queued +./add-event.sh build finished +./add-event.sh testCase started +./add-event.sh testCase queued +./add-event.sh testCase finished +./add-event.sh testSuite started +./add-event.sh testSuite queued +./add-event.sh testSuite finished +./add-event.sh artifact packaged +./add-event.sh artifact published +./add-event.sh environment created +./add-event.sh environment modified +./add-event.sh environment deleted +./add-event.sh service deployed +./add-event.sh service upgraded +./add-event.sh service rolledback +./add-event.sh service removed +./add-event.sh service published \ No newline at end of file diff --git a/pkg/api/artifactpackaged.go b/pkg/api/artifactpackaged.go new file mode 100644 index 0000000..db5b559 --- /dev/null +++ b/pkg/api/artifactpackaged.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ArtifactPackaged event + ArtifactPackagedEventV1 CDEventType = "dev.cdevents.artifact.packaged.v1" +) + +type ArtifactPackagedSubjectContent struct{} + +type ArtifactPackagedSubject struct { + SubjectBase + Content ArtifactPackagedSubjectContent `json:"content"` +} + +func (sc ArtifactPackagedSubject) GetEventType() CDEventType { + return ArtifactPackagedEventV1 +} + +func (sc ArtifactPackagedSubject) GetSubjectType() SubjectType { + return ArtifactSubjectType +} + +type ArtifactPackagedEvent struct { + Context Context `json:"context"` + Subject ArtifactPackagedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ArtifactPackagedEvent) GetType() CDEventType { + return ArtifactPackagedEventV1 +} + +func (e ArtifactPackagedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ArtifactPackagedEvent) GetId() string { + return e.Context.Id +} + +func (e ArtifactPackagedEvent) GetSource() string { + return e.Context.Source +} + +func (e ArtifactPackagedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ArtifactPackagedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ArtifactPackagedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ArtifactPackagedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ArtifactPackagedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ArtifactPackagedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ArtifactPackagedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ArtifactPackagedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ArtifactPackagedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newArtifactPackagedEvent() CDEvent { + return &ArtifactPackagedEvent{ + Context: Context{ + Type: ArtifactPackagedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ArtifactPackagedSubject{}, + } +} diff --git a/pkg/api/artifactpublished.go b/pkg/api/artifactpublished.go new file mode 100644 index 0000000..59d4e18 --- /dev/null +++ b/pkg/api/artifactpublished.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ArtifactPublished event + ArtifactPublishedEventV1 CDEventType = "dev.cdevents.artifact.published.v1" +) + +type ArtifactPublishedSubjectContent struct{} + +type ArtifactPublishedSubject struct { + SubjectBase + Content ArtifactPublishedSubjectContent `json:"content"` +} + +func (sc ArtifactPublishedSubject) GetEventType() CDEventType { + return ArtifactPublishedEventV1 +} + +func (sc ArtifactPublishedSubject) GetSubjectType() SubjectType { + return ArtifactSubjectType +} + +type ArtifactPublishedEvent struct { + Context Context `json:"context"` + Subject ArtifactPublishedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ArtifactPublishedEvent) GetType() CDEventType { + return ArtifactPublishedEventV1 +} + +func (e ArtifactPublishedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ArtifactPublishedEvent) GetId() string { + return e.Context.Id +} + +func (e ArtifactPublishedEvent) GetSource() string { + return e.Context.Source +} + +func (e ArtifactPublishedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ArtifactPublishedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ArtifactPublishedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ArtifactPublishedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ArtifactPublishedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ArtifactPublishedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ArtifactPublishedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ArtifactPublishedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ArtifactPublishedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newArtifactPublishedEvent() CDEvent { + return &ArtifactPublishedEvent{ + Context: Context{ + Type: ArtifactPublishedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ArtifactPublishedSubject{}, + } +} diff --git a/pkg/api/branchcreated.go b/pkg/api/branchcreated.go new file mode 100644 index 0000000..f1c8568 --- /dev/null +++ b/pkg/api/branchcreated.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // BranchCreated event + BranchCreatedEventV1 CDEventType = "dev.cdevents.branch.created.v1" +) + +type BranchCreatedSubjectContent struct{} + +type BranchCreatedSubject struct { + SubjectBase + Content BranchCreatedSubjectContent `json:"content"` +} + +func (sc BranchCreatedSubject) GetEventType() CDEventType { + return BranchCreatedEventV1 +} + +func (sc BranchCreatedSubject) GetSubjectType() SubjectType { + return BranchSubjectType +} + +type BranchCreatedEvent struct { + Context Context `json:"context"` + Subject BranchCreatedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e BranchCreatedEvent) GetType() CDEventType { + return BranchCreatedEventV1 +} + +func (e BranchCreatedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e BranchCreatedEvent) GetId() string { + return e.Context.Id +} + +func (e BranchCreatedEvent) GetSource() string { + return e.Context.Source +} + +func (e BranchCreatedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e BranchCreatedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e BranchCreatedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e BranchCreatedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *BranchCreatedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *BranchCreatedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *BranchCreatedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *BranchCreatedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *BranchCreatedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newBranchCreatedEvent() CDEvent { + return &BranchCreatedEvent{ + Context: Context{ + Type: BranchCreatedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: BranchCreatedSubject{}, + } +} diff --git a/pkg/api/branchdeleted.go b/pkg/api/branchdeleted.go new file mode 100644 index 0000000..a6431f8 --- /dev/null +++ b/pkg/api/branchdeleted.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // BranchDeleted event + BranchDeletedEventV1 CDEventType = "dev.cdevents.branch.deleted.v1" +) + +type BranchDeletedSubjectContent struct{} + +type BranchDeletedSubject struct { + SubjectBase + Content BranchDeletedSubjectContent `json:"content"` +} + +func (sc BranchDeletedSubject) GetEventType() CDEventType { + return BranchDeletedEventV1 +} + +func (sc BranchDeletedSubject) GetSubjectType() SubjectType { + return BranchSubjectType +} + +type BranchDeletedEvent struct { + Context Context `json:"context"` + Subject BranchDeletedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e BranchDeletedEvent) GetType() CDEventType { + return BranchDeletedEventV1 +} + +func (e BranchDeletedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e BranchDeletedEvent) GetId() string { + return e.Context.Id +} + +func (e BranchDeletedEvent) GetSource() string { + return e.Context.Source +} + +func (e BranchDeletedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e BranchDeletedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e BranchDeletedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e BranchDeletedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *BranchDeletedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *BranchDeletedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *BranchDeletedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *BranchDeletedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *BranchDeletedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newBranchDeletedEvent() CDEvent { + return &BranchDeletedEvent{ + Context: Context{ + Type: BranchDeletedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: BranchDeletedSubject{}, + } +} diff --git a/pkg/api/buildfinished.go b/pkg/api/buildfinished.go new file mode 100644 index 0000000..47ba5e0 --- /dev/null +++ b/pkg/api/buildfinished.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // BuildFinished event + BuildFinishedEventV1 CDEventType = "dev.cdevents.build.finished.v1" +) + +type BuildFinishedSubjectContent struct{} + +type BuildFinishedSubject struct { + SubjectBase + Content BuildFinishedSubjectContent `json:"content"` +} + +func (sc BuildFinishedSubject) GetEventType() CDEventType { + return BuildFinishedEventV1 +} + +func (sc BuildFinishedSubject) GetSubjectType() SubjectType { + return BuildSubjectType +} + +type BuildFinishedEvent struct { + Context Context `json:"context"` + Subject BuildFinishedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e BuildFinishedEvent) GetType() CDEventType { + return BuildFinishedEventV1 +} + +func (e BuildFinishedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e BuildFinishedEvent) GetId() string { + return e.Context.Id +} + +func (e BuildFinishedEvent) GetSource() string { + return e.Context.Source +} + +func (e BuildFinishedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e BuildFinishedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e BuildFinishedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e BuildFinishedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *BuildFinishedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *BuildFinishedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *BuildFinishedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *BuildFinishedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *BuildFinishedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newBuildFinishedEvent() CDEvent { + return &BuildFinishedEvent{ + Context: Context{ + Type: BuildFinishedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: BuildFinishedSubject{}, + } +} diff --git a/pkg/api/buildqueued.go b/pkg/api/buildqueued.go new file mode 100644 index 0000000..41b9378 --- /dev/null +++ b/pkg/api/buildqueued.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // BuildQueued event + BuildQueuedEventV1 CDEventType = "dev.cdevents.build.queued.v1" +) + +type BuildQueuedSubjectContent struct{} + +type BuildQueuedSubject struct { + SubjectBase + Content BuildQueuedSubjectContent `json:"content"` +} + +func (sc BuildQueuedSubject) GetEventType() CDEventType { + return BuildQueuedEventV1 +} + +func (sc BuildQueuedSubject) GetSubjectType() SubjectType { + return BuildSubjectType +} + +type BuildQueuedEvent struct { + Context Context `json:"context"` + Subject BuildQueuedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e BuildQueuedEvent) GetType() CDEventType { + return BuildQueuedEventV1 +} + +func (e BuildQueuedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e BuildQueuedEvent) GetId() string { + return e.Context.Id +} + +func (e BuildQueuedEvent) GetSource() string { + return e.Context.Source +} + +func (e BuildQueuedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e BuildQueuedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e BuildQueuedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e BuildQueuedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *BuildQueuedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *BuildQueuedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *BuildQueuedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *BuildQueuedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *BuildQueuedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newBuildQueuedEvent() CDEvent { + return &BuildQueuedEvent{ + Context: Context{ + Type: BuildQueuedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: BuildQueuedSubject{}, + } +} diff --git a/pkg/api/buildstarted.go b/pkg/api/buildstarted.go new file mode 100644 index 0000000..2f49e9b --- /dev/null +++ b/pkg/api/buildstarted.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // BuildStarted event + BuildStartedEventV1 CDEventType = "dev.cdevents.build.started.v1" +) + +type BuildStartedSubjectContent struct{} + +type BuildStartedSubject struct { + SubjectBase + Content BuildStartedSubjectContent `json:"content"` +} + +func (sc BuildStartedSubject) GetEventType() CDEventType { + return BuildStartedEventV1 +} + +func (sc BuildStartedSubject) GetSubjectType() SubjectType { + return BuildSubjectType +} + +type BuildStartedEvent struct { + Context Context `json:"context"` + Subject BuildStartedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e BuildStartedEvent) GetType() CDEventType { + return BuildStartedEventV1 +} + +func (e BuildStartedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e BuildStartedEvent) GetId() string { + return e.Context.Id +} + +func (e BuildStartedEvent) GetSource() string { + return e.Context.Source +} + +func (e BuildStartedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e BuildStartedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e BuildStartedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e BuildStartedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *BuildStartedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *BuildStartedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *BuildStartedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *BuildStartedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *BuildStartedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newBuildStartedEvent() CDEvent { + return &BuildStartedEvent{ + Context: Context{ + Type: BuildStartedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: BuildStartedSubject{}, + } +} diff --git a/pkg/api/changeabandoned.go b/pkg/api/changeabandoned.go new file mode 100644 index 0000000..1be5dac --- /dev/null +++ b/pkg/api/changeabandoned.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ChangeAbandoned event + ChangeAbandonedEventV1 CDEventType = "dev.cdevents.change.abandoned.v1" +) + +type ChangeAbandonedSubjectContent struct{} + +type ChangeAbandonedSubject struct { + SubjectBase + Content ChangeAbandonedSubjectContent `json:"content"` +} + +func (sc ChangeAbandonedSubject) GetEventType() CDEventType { + return ChangeAbandonedEventV1 +} + +func (sc ChangeAbandonedSubject) GetSubjectType() SubjectType { + return ChangeSubjectType +} + +type ChangeAbandonedEvent struct { + Context Context `json:"context"` + Subject ChangeAbandonedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ChangeAbandonedEvent) GetType() CDEventType { + return ChangeAbandonedEventV1 +} + +func (e ChangeAbandonedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ChangeAbandonedEvent) GetId() string { + return e.Context.Id +} + +func (e ChangeAbandonedEvent) GetSource() string { + return e.Context.Source +} + +func (e ChangeAbandonedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ChangeAbandonedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ChangeAbandonedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ChangeAbandonedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ChangeAbandonedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ChangeAbandonedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ChangeAbandonedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ChangeAbandonedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ChangeAbandonedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newChangeAbandonedEvent() CDEvent { + return &ChangeAbandonedEvent{ + Context: Context{ + Type: ChangeAbandonedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ChangeAbandonedSubject{}, + } +} diff --git a/pkg/api/changecreated.go b/pkg/api/changecreated.go new file mode 100644 index 0000000..aa75244 --- /dev/null +++ b/pkg/api/changecreated.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ChangeCreated event + ChangeCreatedEventV1 CDEventType = "dev.cdevents.change.created.v1" +) + +type ChangeCreatedSubjectContent struct{} + +type ChangeCreatedSubject struct { + SubjectBase + Content ChangeCreatedSubjectContent `json:"content"` +} + +func (sc ChangeCreatedSubject) GetEventType() CDEventType { + return ChangeCreatedEventV1 +} + +func (sc ChangeCreatedSubject) GetSubjectType() SubjectType { + return ChangeSubjectType +} + +type ChangeCreatedEvent struct { + Context Context `json:"context"` + Subject ChangeCreatedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ChangeCreatedEvent) GetType() CDEventType { + return ChangeCreatedEventV1 +} + +func (e ChangeCreatedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ChangeCreatedEvent) GetId() string { + return e.Context.Id +} + +func (e ChangeCreatedEvent) GetSource() string { + return e.Context.Source +} + +func (e ChangeCreatedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ChangeCreatedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ChangeCreatedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ChangeCreatedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ChangeCreatedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ChangeCreatedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ChangeCreatedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ChangeCreatedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ChangeCreatedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newChangeCreatedEvent() CDEvent { + return &ChangeCreatedEvent{ + Context: Context{ + Type: ChangeCreatedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ChangeCreatedSubject{}, + } +} diff --git a/pkg/api/changemerged.go b/pkg/api/changemerged.go new file mode 100644 index 0000000..9ededaf --- /dev/null +++ b/pkg/api/changemerged.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ChangeMerged event + ChangeMergedEventV1 CDEventType = "dev.cdevents.change.merged.v1" +) + +type ChangeMergedSubjectContent struct{} + +type ChangeMergedSubject struct { + SubjectBase + Content ChangeMergedSubjectContent `json:"content"` +} + +func (sc ChangeMergedSubject) GetEventType() CDEventType { + return ChangeMergedEventV1 +} + +func (sc ChangeMergedSubject) GetSubjectType() SubjectType { + return ChangeSubjectType +} + +type ChangeMergedEvent struct { + Context Context `json:"context"` + Subject ChangeMergedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ChangeMergedEvent) GetType() CDEventType { + return ChangeMergedEventV1 +} + +func (e ChangeMergedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ChangeMergedEvent) GetId() string { + return e.Context.Id +} + +func (e ChangeMergedEvent) GetSource() string { + return e.Context.Source +} + +func (e ChangeMergedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ChangeMergedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ChangeMergedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ChangeMergedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ChangeMergedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ChangeMergedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ChangeMergedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ChangeMergedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ChangeMergedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newChangeMergedEvent() CDEvent { + return &ChangeMergedEvent{ + Context: Context{ + Type: ChangeMergedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ChangeMergedSubject{}, + } +} diff --git a/pkg/api/changereviewed.go b/pkg/api/changereviewed.go new file mode 100644 index 0000000..cb34329 --- /dev/null +++ b/pkg/api/changereviewed.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ChangeReviewed event + ChangeReviewedEventV1 CDEventType = "dev.cdevents.change.reviewed.v1" +) + +type ChangeReviewedSubjectContent struct{} + +type ChangeReviewedSubject struct { + SubjectBase + Content ChangeReviewedSubjectContent `json:"content"` +} + +func (sc ChangeReviewedSubject) GetEventType() CDEventType { + return ChangeReviewedEventV1 +} + +func (sc ChangeReviewedSubject) GetSubjectType() SubjectType { + return ChangeSubjectType +} + +type ChangeReviewedEvent struct { + Context Context `json:"context"` + Subject ChangeReviewedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ChangeReviewedEvent) GetType() CDEventType { + return ChangeReviewedEventV1 +} + +func (e ChangeReviewedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ChangeReviewedEvent) GetId() string { + return e.Context.Id +} + +func (e ChangeReviewedEvent) GetSource() string { + return e.Context.Source +} + +func (e ChangeReviewedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ChangeReviewedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ChangeReviewedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ChangeReviewedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ChangeReviewedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ChangeReviewedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ChangeReviewedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ChangeReviewedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ChangeReviewedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newChangeReviewedEvent() CDEvent { + return &ChangeReviewedEvent{ + Context: Context{ + Type: ChangeReviewedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ChangeReviewedSubject{}, + } +} diff --git a/pkg/api/changeupdated.go b/pkg/api/changeupdated.go new file mode 100644 index 0000000..2f07e5e --- /dev/null +++ b/pkg/api/changeupdated.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ChangeUpdated event + ChangeUpdatedEventV1 CDEventType = "dev.cdevents.change.updated.v1" +) + +type ChangeUpdatedSubjectContent struct{} + +type ChangeUpdatedSubject struct { + SubjectBase + Content ChangeUpdatedSubjectContent `json:"content"` +} + +func (sc ChangeUpdatedSubject) GetEventType() CDEventType { + return ChangeUpdatedEventV1 +} + +func (sc ChangeUpdatedSubject) GetSubjectType() SubjectType { + return ChangeSubjectType +} + +type ChangeUpdatedEvent struct { + Context Context `json:"context"` + Subject ChangeUpdatedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ChangeUpdatedEvent) GetType() CDEventType { + return ChangeUpdatedEventV1 +} + +func (e ChangeUpdatedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ChangeUpdatedEvent) GetId() string { + return e.Context.Id +} + +func (e ChangeUpdatedEvent) GetSource() string { + return e.Context.Source +} + +func (e ChangeUpdatedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ChangeUpdatedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ChangeUpdatedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ChangeUpdatedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ChangeUpdatedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ChangeUpdatedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ChangeUpdatedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ChangeUpdatedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ChangeUpdatedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newChangeUpdatedEvent() CDEvent { + return &ChangeUpdatedEvent{ + Context: Context{ + Type: ChangeUpdatedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ChangeUpdatedSubject{}, + } +} diff --git a/pkg/api/core.go b/pkg/api/core.go deleted file mode 100644 index 4d821de..0000000 --- a/pkg/api/core.go +++ /dev/null @@ -1,25 +0,0 @@ -/* -Copyright 2022 The CDEvents Authors - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. - -SPDX-License-Identifier: Apache-2.0 -*/ - -package api - -const ( - // Subject Types - PipelineRunSubjectType SubjectType = "pipelineRun" - TaskRunSubjectType SubjectType = "taskRun" -) diff --git a/pkg/api/environmentcreated.go b/pkg/api/environmentcreated.go new file mode 100644 index 0000000..7b85743 --- /dev/null +++ b/pkg/api/environmentcreated.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // EnvironmentCreated event + EnvironmentCreatedEventV1 CDEventType = "dev.cdevents.environment.created.v1" +) + +type EnvironmentCreatedSubjectContent struct{} + +type EnvironmentCreatedSubject struct { + SubjectBase + Content EnvironmentCreatedSubjectContent `json:"content"` +} + +func (sc EnvironmentCreatedSubject) GetEventType() CDEventType { + return EnvironmentCreatedEventV1 +} + +func (sc EnvironmentCreatedSubject) GetSubjectType() SubjectType { + return EnvironmentSubjectType +} + +type EnvironmentCreatedEvent struct { + Context Context `json:"context"` + Subject EnvironmentCreatedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e EnvironmentCreatedEvent) GetType() CDEventType { + return EnvironmentCreatedEventV1 +} + +func (e EnvironmentCreatedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e EnvironmentCreatedEvent) GetId() string { + return e.Context.Id +} + +func (e EnvironmentCreatedEvent) GetSource() string { + return e.Context.Source +} + +func (e EnvironmentCreatedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e EnvironmentCreatedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e EnvironmentCreatedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e EnvironmentCreatedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *EnvironmentCreatedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *EnvironmentCreatedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *EnvironmentCreatedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *EnvironmentCreatedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *EnvironmentCreatedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newEnvironmentCreatedEvent() CDEvent { + return &EnvironmentCreatedEvent{ + Context: Context{ + Type: EnvironmentCreatedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: EnvironmentCreatedSubject{}, + } +} diff --git a/pkg/api/environmentdeleted.go b/pkg/api/environmentdeleted.go new file mode 100644 index 0000000..4b772dc --- /dev/null +++ b/pkg/api/environmentdeleted.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // EnvironmentDeleted event + EnvironmentDeletedEventV1 CDEventType = "dev.cdevents.environment.deleted.v1" +) + +type EnvironmentDeletedSubjectContent struct{} + +type EnvironmentDeletedSubject struct { + SubjectBase + Content EnvironmentDeletedSubjectContent `json:"content"` +} + +func (sc EnvironmentDeletedSubject) GetEventType() CDEventType { + return EnvironmentDeletedEventV1 +} + +func (sc EnvironmentDeletedSubject) GetSubjectType() SubjectType { + return EnvironmentSubjectType +} + +type EnvironmentDeletedEvent struct { + Context Context `json:"context"` + Subject EnvironmentDeletedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e EnvironmentDeletedEvent) GetType() CDEventType { + return EnvironmentDeletedEventV1 +} + +func (e EnvironmentDeletedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e EnvironmentDeletedEvent) GetId() string { + return e.Context.Id +} + +func (e EnvironmentDeletedEvent) GetSource() string { + return e.Context.Source +} + +func (e EnvironmentDeletedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e EnvironmentDeletedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e EnvironmentDeletedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e EnvironmentDeletedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *EnvironmentDeletedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *EnvironmentDeletedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *EnvironmentDeletedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *EnvironmentDeletedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *EnvironmentDeletedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newEnvironmentDeletedEvent() CDEvent { + return &EnvironmentDeletedEvent{ + Context: Context{ + Type: EnvironmentDeletedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: EnvironmentDeletedSubject{}, + } +} diff --git a/pkg/api/environmentmodified.go b/pkg/api/environmentmodified.go new file mode 100644 index 0000000..fffcd38 --- /dev/null +++ b/pkg/api/environmentmodified.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // EnvironmentModified event + EnvironmentModifiedEventV1 CDEventType = "dev.cdevents.environment.modified.v1" +) + +type EnvironmentModifiedSubjectContent struct{} + +type EnvironmentModifiedSubject struct { + SubjectBase + Content EnvironmentModifiedSubjectContent `json:"content"` +} + +func (sc EnvironmentModifiedSubject) GetEventType() CDEventType { + return EnvironmentModifiedEventV1 +} + +func (sc EnvironmentModifiedSubject) GetSubjectType() SubjectType { + return EnvironmentSubjectType +} + +type EnvironmentModifiedEvent struct { + Context Context `json:"context"` + Subject EnvironmentModifiedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e EnvironmentModifiedEvent) GetType() CDEventType { + return EnvironmentModifiedEventV1 +} + +func (e EnvironmentModifiedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e EnvironmentModifiedEvent) GetId() string { + return e.Context.Id +} + +func (e EnvironmentModifiedEvent) GetSource() string { + return e.Context.Source +} + +func (e EnvironmentModifiedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e EnvironmentModifiedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e EnvironmentModifiedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e EnvironmentModifiedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *EnvironmentModifiedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *EnvironmentModifiedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *EnvironmentModifiedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *EnvironmentModifiedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *EnvironmentModifiedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newEnvironmentModifiedEvent() CDEvent { + return &EnvironmentModifiedEvent{ + Context: Context{ + Type: EnvironmentModifiedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: EnvironmentModifiedSubject{}, + } +} diff --git a/pkg/api/factory.go b/pkg/api/factory.go index 48d5724..190e59e 100644 --- a/pkg/api/factory.go +++ b/pkg/api/factory.go @@ -55,6 +55,93 @@ func NewCDEvent(eventType CDEventType) (CDEvent, error) { case TaskRunFinishedEventV1: e := newTaskRunFinishedEvent() return initCDEvent(e) + // case RepositoryCreatedEventV1: + // e := newRepositoryCreatedEvent() + // return initCDEvent(e) + // case RepositoryModifiedEventV1: + // e := newRepositoryModifiedEvent() + // return initCDEvent(e) + // case RepositoryDeletedEventV1: + // e := newRepositoryDeletedEvent() + // return initCDEvent(e) + // case BranchCreatedEventV1: + // e := newBranchCreatedEvent() + // return initCDEvent(e) + // case BranchDeletedEventV1: + // e := newBranchDeletedEvent() + // return initCDEvent(e) + // case ChangeCreatedEventV1: + // e := newChangeCreatedEvent() + // return initCDEvent(e) + // case ChangeUpdatedEventV1: + // e := newChangeUpdatedEvent() + // return initCDEvent(e) + // case ChangeReviewedEventV1: + // e := newChangeReviewedEvent() + // return initCDEvent(e) + // case ChangeMergedEventV1: + // e := newChangeMergedEvent() + // return initCDEvent(e) + // case ChangeAbandonedEventV1: + // e := newChangeAbandonedEvent() + // return initCDEvent(e) + // case BuildQueuedEventV1: + // e := newBuildQueuedEvent() + // return initCDEvent(e) + // case BuildStartedEventV1: + // e := newBuildStartedEvent() + // return initCDEvent(e) + // case BuildFinishedEventV1: + // e := newBuildFinishedEvent() + // return initCDEvent(e) + // case TestCaseQueuedEventV1: + // e := newTestCaseQueuedEvent() + // return initCDEvent(e) + // case TestCaseStartedEventV1: + // e := newTestCaseStartedEvent() + // return initCDEvent(e) + // case TestCaseFinishedEventV1: + // e := newTestCaseFinishedEvent() + // return initCDEvent(e) + // case TestSuiteQueuedEventV1: + // e := newTestSuiteQueuedEvent() + // return initCDEvent(e) + // case TestSuiteStartedEventV1: + // e := newTestSuiteStartedEvent() + // return initCDEvent(e) + // case TestSuiteFinishedEventV1: + // e := newTestSuiteFinishedEvent() + // return initCDEvent(e) + // case ArtifactPackagedEventV1: + // e := newArtifactPackagedEvent() + // return initCDEvent(e) + // case ArtifactPublishedEventV1: + // e := newArtifactPublishedEvent() + // return initCDEvent(e) + // case EnvironmentCreatedEventV1: + // e := newEnvironmentCreatedEvent() + // return initCDEvent(e) + // case EnvironmentModifiedEventV1: + // e := newEnvironmentModifiedEvent() + // return initCDEvent(e) + // case EnvironmentDeletedEventV1: + // e := newEnvironmentDeletedEvent() + // return initCDEvent(e) + // case ServiceDeployedEventV1: + // e := newServiceDeployedEvent() + // return initCDEvent(e) + // case ServiceUpgradedEventV1: + // e := newServiceUpgradedEvent() + // return initCDEvent(e) + // case ServiceRolledbackEventV1: + // e := newServiceRolledbackEvent() + // return initCDEvent(e) + // case ServiceRemovedEventV1: + // e := newServiceRemovedEvent() + // return initCDEvent(e) + // case ServicePublishedEventV1: + // e := newServicePublishedEvent() + // return initCDEvent(e) default: return nil, fmt.Errorf("event %v not supported", eventType) } diff --git a/pkg/api/repositorycreated.go b/pkg/api/repositorycreated.go new file mode 100644 index 0000000..cda9964 --- /dev/null +++ b/pkg/api/repositorycreated.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // RepositoryCreated event + RepositoryCreatedEventV1 CDEventType = "dev.cdevents.repository.created.v1" +) + +type RepositoryCreatedSubjectContent struct{} + +type RepositoryCreatedSubject struct { + SubjectBase + Content RepositoryCreatedSubjectContent `json:"content"` +} + +func (sc RepositoryCreatedSubject) GetEventType() CDEventType { + return RepositoryCreatedEventV1 +} + +func (sc RepositoryCreatedSubject) GetSubjectType() SubjectType { + return RepositorySubjectType +} + +type RepositoryCreatedEvent struct { + Context Context `json:"context"` + Subject RepositoryCreatedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e RepositoryCreatedEvent) GetType() CDEventType { + return RepositoryCreatedEventV1 +} + +func (e RepositoryCreatedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e RepositoryCreatedEvent) GetId() string { + return e.Context.Id +} + +func (e RepositoryCreatedEvent) GetSource() string { + return e.Context.Source +} + +func (e RepositoryCreatedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e RepositoryCreatedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e RepositoryCreatedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e RepositoryCreatedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *RepositoryCreatedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *RepositoryCreatedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *RepositoryCreatedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *RepositoryCreatedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *RepositoryCreatedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newRepositoryCreatedEvent() CDEvent { + return &RepositoryCreatedEvent{ + Context: Context{ + Type: RepositoryCreatedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: RepositoryCreatedSubject{}, + } +} diff --git a/pkg/api/repositorydeleted.go b/pkg/api/repositorydeleted.go new file mode 100644 index 0000000..e81121e --- /dev/null +++ b/pkg/api/repositorydeleted.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // RepositoryDeleted event + RepositoryDeletedEventV1 CDEventType = "dev.cdevents.repository.deleted.v1" +) + +type RepositoryDeletedSubjectContent struct{} + +type RepositoryDeletedSubject struct { + SubjectBase + Content RepositoryDeletedSubjectContent `json:"content"` +} + +func (sc RepositoryDeletedSubject) GetEventType() CDEventType { + return RepositoryDeletedEventV1 +} + +func (sc RepositoryDeletedSubject) GetSubjectType() SubjectType { + return RepositorySubjectType +} + +type RepositoryDeletedEvent struct { + Context Context `json:"context"` + Subject RepositoryDeletedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e RepositoryDeletedEvent) GetType() CDEventType { + return RepositoryDeletedEventV1 +} + +func (e RepositoryDeletedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e RepositoryDeletedEvent) GetId() string { + return e.Context.Id +} + +func (e RepositoryDeletedEvent) GetSource() string { + return e.Context.Source +} + +func (e RepositoryDeletedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e RepositoryDeletedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e RepositoryDeletedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e RepositoryDeletedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *RepositoryDeletedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *RepositoryDeletedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *RepositoryDeletedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *RepositoryDeletedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *RepositoryDeletedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newRepositoryDeletedEvent() CDEvent { + return &RepositoryDeletedEvent{ + Context: Context{ + Type: RepositoryDeletedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: RepositoryDeletedSubject{}, + } +} diff --git a/pkg/api/repositorymodified.go b/pkg/api/repositorymodified.go new file mode 100644 index 0000000..b62dc8a --- /dev/null +++ b/pkg/api/repositorymodified.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // RepositoryModified event + RepositoryModifiedEventV1 CDEventType = "dev.cdevents.repository.modified.v1" +) + +type RepositoryModifiedSubjectContent struct{} + +type RepositoryModifiedSubject struct { + SubjectBase + Content RepositoryModifiedSubjectContent `json:"content"` +} + +func (sc RepositoryModifiedSubject) GetEventType() CDEventType { + return RepositoryModifiedEventV1 +} + +func (sc RepositoryModifiedSubject) GetSubjectType() SubjectType { + return RepositorySubjectType +} + +type RepositoryModifiedEvent struct { + Context Context `json:"context"` + Subject RepositoryModifiedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e RepositoryModifiedEvent) GetType() CDEventType { + return RepositoryModifiedEventV1 +} + +func (e RepositoryModifiedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e RepositoryModifiedEvent) GetId() string { + return e.Context.Id +} + +func (e RepositoryModifiedEvent) GetSource() string { + return e.Context.Source +} + +func (e RepositoryModifiedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e RepositoryModifiedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e RepositoryModifiedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e RepositoryModifiedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *RepositoryModifiedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *RepositoryModifiedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *RepositoryModifiedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *RepositoryModifiedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *RepositoryModifiedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newRepositoryModifiedEvent() CDEvent { + return &RepositoryModifiedEvent{ + Context: Context{ + Type: RepositoryModifiedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: RepositoryModifiedSubject{}, + } +} diff --git a/pkg/api/servicedeployed.go b/pkg/api/servicedeployed.go new file mode 100644 index 0000000..dab575c --- /dev/null +++ b/pkg/api/servicedeployed.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ServiceDeployed event + ServiceDeployedEventV1 CDEventType = "dev.cdevents.service.deployed.v1" +) + +type ServiceDeployedSubjectContent struct{} + +type ServiceDeployedSubject struct { + SubjectBase + Content ServiceDeployedSubjectContent `json:"content"` +} + +func (sc ServiceDeployedSubject) GetEventType() CDEventType { + return ServiceDeployedEventV1 +} + +func (sc ServiceDeployedSubject) GetSubjectType() SubjectType { + return ServiceSubjectType +} + +type ServiceDeployedEvent struct { + Context Context `json:"context"` + Subject ServiceDeployedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ServiceDeployedEvent) GetType() CDEventType { + return ServiceDeployedEventV1 +} + +func (e ServiceDeployedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ServiceDeployedEvent) GetId() string { + return e.Context.Id +} + +func (e ServiceDeployedEvent) GetSource() string { + return e.Context.Source +} + +func (e ServiceDeployedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ServiceDeployedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ServiceDeployedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ServiceDeployedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ServiceDeployedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ServiceDeployedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ServiceDeployedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ServiceDeployedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ServiceDeployedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newServiceDeployedEvent() CDEvent { + return &ServiceDeployedEvent{ + Context: Context{ + Type: ServiceDeployedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ServiceDeployedSubject{}, + } +} diff --git a/pkg/api/servicepublished.go b/pkg/api/servicepublished.go new file mode 100644 index 0000000..c36682e --- /dev/null +++ b/pkg/api/servicepublished.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ServicePublished event + ServicePublishedEventV1 CDEventType = "dev.cdevents.service.published.v1" +) + +type ServicePublishedSubjectContent struct{} + +type ServicePublishedSubject struct { + SubjectBase + Content ServicePublishedSubjectContent `json:"content"` +} + +func (sc ServicePublishedSubject) GetEventType() CDEventType { + return ServicePublishedEventV1 +} + +func (sc ServicePublishedSubject) GetSubjectType() SubjectType { + return ServiceSubjectType +} + +type ServicePublishedEvent struct { + Context Context `json:"context"` + Subject ServicePublishedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ServicePublishedEvent) GetType() CDEventType { + return ServicePublishedEventV1 +} + +func (e ServicePublishedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ServicePublishedEvent) GetId() string { + return e.Context.Id +} + +func (e ServicePublishedEvent) GetSource() string { + return e.Context.Source +} + +func (e ServicePublishedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ServicePublishedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ServicePublishedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ServicePublishedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ServicePublishedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ServicePublishedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ServicePublishedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ServicePublishedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ServicePublishedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newServicePublishedEvent() CDEvent { + return &ServicePublishedEvent{ + Context: Context{ + Type: ServicePublishedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ServicePublishedSubject{}, + } +} diff --git a/pkg/api/serviceremoved.go b/pkg/api/serviceremoved.go new file mode 100644 index 0000000..23f1840 --- /dev/null +++ b/pkg/api/serviceremoved.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ServiceRemoved event + ServiceRemovedEventV1 CDEventType = "dev.cdevents.service.removed.v1" +) + +type ServiceRemovedSubjectContent struct{} + +type ServiceRemovedSubject struct { + SubjectBase + Content ServiceRemovedSubjectContent `json:"content"` +} + +func (sc ServiceRemovedSubject) GetEventType() CDEventType { + return ServiceRemovedEventV1 +} + +func (sc ServiceRemovedSubject) GetSubjectType() SubjectType { + return ServiceSubjectType +} + +type ServiceRemovedEvent struct { + Context Context `json:"context"` + Subject ServiceRemovedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ServiceRemovedEvent) GetType() CDEventType { + return ServiceRemovedEventV1 +} + +func (e ServiceRemovedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ServiceRemovedEvent) GetId() string { + return e.Context.Id +} + +func (e ServiceRemovedEvent) GetSource() string { + return e.Context.Source +} + +func (e ServiceRemovedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ServiceRemovedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ServiceRemovedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ServiceRemovedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ServiceRemovedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ServiceRemovedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ServiceRemovedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ServiceRemovedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ServiceRemovedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newServiceRemovedEvent() CDEvent { + return &ServiceRemovedEvent{ + Context: Context{ + Type: ServiceRemovedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ServiceRemovedSubject{}, + } +} diff --git a/pkg/api/servicerolledback.go b/pkg/api/servicerolledback.go new file mode 100644 index 0000000..1359adb --- /dev/null +++ b/pkg/api/servicerolledback.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ServiceRolledback event + ServiceRolledbackEventV1 CDEventType = "dev.cdevents.service.rolledback.v1" +) + +type ServiceRolledbackSubjectContent struct{} + +type ServiceRolledbackSubject struct { + SubjectBase + Content ServiceRolledbackSubjectContent `json:"content"` +} + +func (sc ServiceRolledbackSubject) GetEventType() CDEventType { + return ServiceRolledbackEventV1 +} + +func (sc ServiceRolledbackSubject) GetSubjectType() SubjectType { + return ServiceSubjectType +} + +type ServiceRolledbackEvent struct { + Context Context `json:"context"` + Subject ServiceRolledbackSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ServiceRolledbackEvent) GetType() CDEventType { + return ServiceRolledbackEventV1 +} + +func (e ServiceRolledbackEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ServiceRolledbackEvent) GetId() string { + return e.Context.Id +} + +func (e ServiceRolledbackEvent) GetSource() string { + return e.Context.Source +} + +func (e ServiceRolledbackEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ServiceRolledbackEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ServiceRolledbackEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ServiceRolledbackEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ServiceRolledbackEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ServiceRolledbackEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ServiceRolledbackEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ServiceRolledbackEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ServiceRolledbackEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newServiceRolledbackEvent() CDEvent { + return &ServiceRolledbackEvent{ + Context: Context{ + Type: ServiceRolledbackEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ServiceRolledbackSubject{}, + } +} diff --git a/pkg/api/serviceupgraded.go b/pkg/api/serviceupgraded.go new file mode 100644 index 0000000..b680f48 --- /dev/null +++ b/pkg/api/serviceupgraded.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // ServiceUpgraded event + ServiceUpgradedEventV1 CDEventType = "dev.cdevents.service.upgraded.v1" +) + +type ServiceUpgradedSubjectContent struct{} + +type ServiceUpgradedSubject struct { + SubjectBase + Content ServiceUpgradedSubjectContent `json:"content"` +} + +func (sc ServiceUpgradedSubject) GetEventType() CDEventType { + return ServiceUpgradedEventV1 +} + +func (sc ServiceUpgradedSubject) GetSubjectType() SubjectType { + return ServiceSubjectType +} + +type ServiceUpgradedEvent struct { + Context Context `json:"context"` + Subject ServiceUpgradedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e ServiceUpgradedEvent) GetType() CDEventType { + return ServiceUpgradedEventV1 +} + +func (e ServiceUpgradedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e ServiceUpgradedEvent) GetId() string { + return e.Context.Id +} + +func (e ServiceUpgradedEvent) GetSource() string { + return e.Context.Source +} + +func (e ServiceUpgradedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e ServiceUpgradedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e ServiceUpgradedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e ServiceUpgradedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *ServiceUpgradedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *ServiceUpgradedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *ServiceUpgradedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *ServiceUpgradedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *ServiceUpgradedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newServiceUpgradedEvent() CDEvent { + return &ServiceUpgradedEvent{ + Context: Context{ + Type: ServiceUpgradedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: ServiceUpgradedSubject{}, + } +} diff --git a/pkg/api/testcasefinished.go b/pkg/api/testcasefinished.go new file mode 100644 index 0000000..1e1fb7d --- /dev/null +++ b/pkg/api/testcasefinished.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // TestCaseFinished event + TestCaseFinishedEventV1 CDEventType = "dev.cdevents.testcase.finished.v1" +) + +type TestCaseFinishedSubjectContent struct{} + +type TestCaseFinishedSubject struct { + SubjectBase + Content TestCaseFinishedSubjectContent `json:"content"` +} + +func (sc TestCaseFinishedSubject) GetEventType() CDEventType { + return TestCaseFinishedEventV1 +} + +func (sc TestCaseFinishedSubject) GetSubjectType() SubjectType { + return TestCaseSubjectType +} + +type TestCaseFinishedEvent struct { + Context Context `json:"context"` + Subject TestCaseFinishedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e TestCaseFinishedEvent) GetType() CDEventType { + return TestCaseFinishedEventV1 +} + +func (e TestCaseFinishedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestCaseFinishedEvent) GetId() string { + return e.Context.Id +} + +func (e TestCaseFinishedEvent) GetSource() string { + return e.Context.Source +} + +func (e TestCaseFinishedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestCaseFinishedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestCaseFinishedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestCaseFinishedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *TestCaseFinishedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *TestCaseFinishedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestCaseFinishedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestCaseFinishedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestCaseFinishedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newTestCaseFinishedEvent() CDEvent { + return &TestCaseFinishedEvent{ + Context: Context{ + Type: TestCaseFinishedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: TestCaseFinishedSubject{}, + } +} diff --git a/pkg/api/testcasequeued.go b/pkg/api/testcasequeued.go new file mode 100644 index 0000000..71e6098 --- /dev/null +++ b/pkg/api/testcasequeued.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // TestCaseQueued event + TestCaseQueuedEventV1 CDEventType = "dev.cdevents.testcase.queued.v1" +) + +type TestCaseQueuedSubjectContent struct{} + +type TestCaseQueuedSubject struct { + SubjectBase + Content TestCaseQueuedSubjectContent `json:"content"` +} + +func (sc TestCaseQueuedSubject) GetEventType() CDEventType { + return TestCaseQueuedEventV1 +} + +func (sc TestCaseQueuedSubject) GetSubjectType() SubjectType { + return TestCaseSubjectType +} + +type TestCaseQueuedEvent struct { + Context Context `json:"context"` + Subject TestCaseQueuedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e TestCaseQueuedEvent) GetType() CDEventType { + return TestCaseQueuedEventV1 +} + +func (e TestCaseQueuedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestCaseQueuedEvent) GetId() string { + return e.Context.Id +} + +func (e TestCaseQueuedEvent) GetSource() string { + return e.Context.Source +} + +func (e TestCaseQueuedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestCaseQueuedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestCaseQueuedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestCaseQueuedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *TestCaseQueuedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *TestCaseQueuedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestCaseQueuedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestCaseQueuedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestCaseQueuedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newTestCaseQueuedEvent() CDEvent { + return &TestCaseQueuedEvent{ + Context: Context{ + Type: TestCaseQueuedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: TestCaseQueuedSubject{}, + } +} diff --git a/pkg/api/testcasestarted.go b/pkg/api/testcasestarted.go new file mode 100644 index 0000000..4d83320 --- /dev/null +++ b/pkg/api/testcasestarted.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // TestCaseStarted event + TestCaseStartedEventV1 CDEventType = "dev.cdevents.testcase.started.v1" +) + +type TestCaseStartedSubjectContent struct{} + +type TestCaseStartedSubject struct { + SubjectBase + Content TestCaseStartedSubjectContent `json:"content"` +} + +func (sc TestCaseStartedSubject) GetEventType() CDEventType { + return TestCaseStartedEventV1 +} + +func (sc TestCaseStartedSubject) GetSubjectType() SubjectType { + return TestCaseSubjectType +} + +type TestCaseStartedEvent struct { + Context Context `json:"context"` + Subject TestCaseStartedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e TestCaseStartedEvent) GetType() CDEventType { + return TestCaseStartedEventV1 +} + +func (e TestCaseStartedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestCaseStartedEvent) GetId() string { + return e.Context.Id +} + +func (e TestCaseStartedEvent) GetSource() string { + return e.Context.Source +} + +func (e TestCaseStartedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestCaseStartedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestCaseStartedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestCaseStartedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *TestCaseStartedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *TestCaseStartedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestCaseStartedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestCaseStartedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestCaseStartedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newTestCaseStartedEvent() CDEvent { + return &TestCaseStartedEvent{ + Context: Context{ + Type: TestCaseStartedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: TestCaseStartedSubject{}, + } +} diff --git a/pkg/api/testsuitefinished.go b/pkg/api/testsuitefinished.go new file mode 100644 index 0000000..3f7e482 --- /dev/null +++ b/pkg/api/testsuitefinished.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // TestSuiteFinished event + TestSuiteFinishedEventV1 CDEventType = "dev.cdevents.testsuite.finished.v1" +) + +type TestSuiteFinishedSubjectContent struct{} + +type TestSuiteFinishedSubject struct { + SubjectBase + Content TestSuiteFinishedSubjectContent `json:"content"` +} + +func (sc TestSuiteFinishedSubject) GetEventType() CDEventType { + return TestSuiteFinishedEventV1 +} + +func (sc TestSuiteFinishedSubject) GetSubjectType() SubjectType { + return TestSuiteSubjectType +} + +type TestSuiteFinishedEvent struct { + Context Context `json:"context"` + Subject TestSuiteFinishedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e TestSuiteFinishedEvent) GetType() CDEventType { + return TestSuiteFinishedEventV1 +} + +func (e TestSuiteFinishedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestSuiteFinishedEvent) GetId() string { + return e.Context.Id +} + +func (e TestSuiteFinishedEvent) GetSource() string { + return e.Context.Source +} + +func (e TestSuiteFinishedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestSuiteFinishedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestSuiteFinishedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestSuiteFinishedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *TestSuiteFinishedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *TestSuiteFinishedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestSuiteFinishedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestSuiteFinishedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestSuiteFinishedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newTestSuiteFinishedEvent() CDEvent { + return &TestSuiteFinishedEvent{ + Context: Context{ + Type: TestSuiteFinishedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: TestSuiteFinishedSubject{}, + } +} diff --git a/pkg/api/testsuitequeued.go b/pkg/api/testsuitequeued.go new file mode 100644 index 0000000..1731c5f --- /dev/null +++ b/pkg/api/testsuitequeued.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // TestSuiteQueued event + TestSuiteQueuedEventV1 CDEventType = "dev.cdevents.testsuite.queued.v1" +) + +type TestSuiteQueuedSubjectContent struct{} + +type TestSuiteQueuedSubject struct { + SubjectBase + Content TestSuiteQueuedSubjectContent `json:"content"` +} + +func (sc TestSuiteQueuedSubject) GetEventType() CDEventType { + return TestSuiteQueuedEventV1 +} + +func (sc TestSuiteQueuedSubject) GetSubjectType() SubjectType { + return TestSuiteSubjectType +} + +type TestSuiteQueuedEvent struct { + Context Context `json:"context"` + Subject TestSuiteQueuedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e TestSuiteQueuedEvent) GetType() CDEventType { + return TestSuiteQueuedEventV1 +} + +func (e TestSuiteQueuedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestSuiteQueuedEvent) GetId() string { + return e.Context.Id +} + +func (e TestSuiteQueuedEvent) GetSource() string { + return e.Context.Source +} + +func (e TestSuiteQueuedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestSuiteQueuedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestSuiteQueuedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestSuiteQueuedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *TestSuiteQueuedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *TestSuiteQueuedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestSuiteQueuedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestSuiteQueuedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestSuiteQueuedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newTestSuiteQueuedEvent() CDEvent { + return &TestSuiteQueuedEvent{ + Context: Context{ + Type: TestSuiteQueuedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: TestSuiteQueuedSubject{}, + } +} diff --git a/pkg/api/testsuitestarted.go b/pkg/api/testsuitestarted.go new file mode 100644 index 0000000..d58be03 --- /dev/null +++ b/pkg/api/testsuitestarted.go @@ -0,0 +1,118 @@ +/* +Copyright 2022 The CDEvents Authors + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. + +SPDX-License-Identifier: Apache-2.0 +*/ + +package api + +import ( + "time" +) + +const ( + // TestSuiteStarted event + TestSuiteStartedEventV1 CDEventType = "dev.cdevents.testsuite.started.v1" +) + +type TestSuiteStartedSubjectContent struct{} + +type TestSuiteStartedSubject struct { + SubjectBase + Content TestSuiteStartedSubjectContent `json:"content"` +} + +func (sc TestSuiteStartedSubject) GetEventType() CDEventType { + return TestSuiteStartedEventV1 +} + +func (sc TestSuiteStartedSubject) GetSubjectType() SubjectType { + return TestSuiteSubjectType +} + +type TestSuiteStartedEvent struct { + Context Context `json:"context"` + Subject TestSuiteStartedSubject `json:"subject"` +} + +// CDEventsReader implementation + +func (e TestSuiteStartedEvent) GetType() CDEventType { + return TestSuiteStartedEventV1 +} + +func (e TestSuiteStartedEvent) GetVersion() string { + return CDEventsSpecVersion +} + +func (e TestSuiteStartedEvent) GetId() string { + return e.Context.Id +} + +func (e TestSuiteStartedEvent) GetSource() string { + return e.Context.Source +} + +func (e TestSuiteStartedEvent) GetTimestamp() time.Time { + return e.Context.Timestamp +} + +func (e TestSuiteStartedEvent) GetSubjectId() string { + return e.Subject.Id +} + +func (e TestSuiteStartedEvent) GetSubjectSource() string { + return e.Subject.Source +} + +func (e TestSuiteStartedEvent) GetSubject() Subject { + return e.Subject +} + +// CDEventsWriter implementation + +func (e *TestSuiteStartedEvent) SetId(id string) { + e.Context.Id = id +} + +func (e *TestSuiteStartedEvent) SetSource(source string) { + e.Context.Source = source + // Default the subject source to the event source + if e.Subject.Source == "" { + e.Subject.Source = source + } +} + +func (e *TestSuiteStartedEvent) SetTimestamp(timestamp time.Time) { + e.Context.Timestamp = timestamp +} + +func (e *TestSuiteStartedEvent) SetSubjectId(subjectId string) { + e.Subject.Id = subjectId +} + +func (e *TestSuiteStartedEvent) SetSubjectSource(subjectSource string) { + e.Subject.Source = subjectSource +} + +func newTestSuiteStartedEvent() CDEvent { + return &TestSuiteStartedEvent{ + Context: Context{ + Type: TestSuiteStartedEventV1, + Version: CDEventsSpecVersion, + }, + Subject: TestSuiteStartedSubject{}, + } +} diff --git a/pkg/api/vocabulary.go b/pkg/api/vocabulary.go index 4759115..6b6a307 100644 --- a/pkg/api/vocabulary.go +++ b/pkg/api/vocabulary.go @@ -19,48 +19,22 @@ SPDX-License-Identifier: Apache-2.0 package api const ( - - // Repository events - RepositoryCreatedEventV1 CDEventType = "dev.cdevents.repository.created.v1" - RepositoryModifiedEventV1 CDEventType = "dev.cdevents.repository.modified.v1" - RepositoryDeletedEventV1 CDEventType = "dev.cdevents.repository.deleted.v1" - - BranchCreatedEventV1 CDEventType = "dev.cdevents.repository.branch.created.v1" - BranchDeletedEventV1 CDEventType = "dev.cdevents.repository.branch.deleted.v1" - - // Change Events - ChangeCreatedEventV1 CDEventType = "dev.cdevents.repository.change.created.v1" - ChangeUpdatedEventV1 CDEventType = "dev.cdevents.repository.change.updated.v1" - ChangeReviewedEventV1 CDEventType = "dev.cdevents.repository.change.reviewed.v1" - ChangeMergedEventV1 CDEventType = "dev.cdevents.repository.change.merged.v1" - ChangeAbandonedEventV1 CDEventType = "dev.cdevents.repository.change.abandoned.v1" - - // Build Events - BuildStartedEventV1 CDEventType = "dev.cdevents.build.started.v1" - BuildQueuedEventV1 CDEventType = "dev.cdevents.build.queued.v1" - BuildFinishedEventV1 CDEventType = "dev.cdevents.build.finished.v1" - - // Test Events - TestCaseStartedEventV1 CDEventType = "dev.cdevents.test.case.started.v1" - TestCaseQueuedEventV1 CDEventType = "dev.cdevents.test.case.queued.v1" - TestCaseFinishedEventV1 CDEventType = "dev.cdevents.test.case.finished.v1" - - TestSuiteStartedEventV1 CDEventType = "dev.cdevents.test.suite.started.v1" - TestSuiteQueuedEventV1 CDEventType = "dev.cdevents.test.suite.queued.v1" - TestSuiteFinishedEventV1 CDEventType = "dev.cdevents.test.suite.finished.v1" - - // Artifact Events - ArtifactPackagedEventV1 CDEventType = "dev.cdevents.artifact.packaged.v1" - ArtifactPublishedEventV1 CDEventType = "dev.cdevents.artifact.published.v1" - - // Environment Events - EnvironmentCreatedEventV1 CDEventType = "dev.cdevents.environment.created.v1" - EnvironmentModifiedEventV1 CDEventType = "dev.cdevents.environment.modified.v1" - EnvironmentDeletedEventV1 CDEventType = "dev.cdevents.environment.deleted.v1" - - // Service Events - ServiceDeployedEventV1 CDEventType = "dev.cdevents.service.deployed.v1" - ServiceUpgradedEventV1 CDEventType = "dev.cdevents.service.upgraded.v1" - ServiceRolledbackEventV1 CDEventType = "dev.cdevents.service.rolledback.v1" - ServiceRemovedEventV1 CDEventType = "dev.cdevents.service.removed.v1" + // Core Subject Types + PipelineRunSubjectType SubjectType = "pipelineRun" + TaskRunSubjectType SubjectType = "taskRun" + + // SCM Subject Types + RepositorySubjectType SubjectType = "repository" + BranchSubjectType SubjectType = "branch" + ChangeSubjectType SubjectType = "change" + + // CI Subject Types + BuildSubjectType SubjectType = "build" + TestCaseSubjectType SubjectType = "testCase" + TestSuiteSubjectType SubjectType = "testSuite" + ArtifactSubjectType SubjectType = "artifact" + + // CD Subject Types + EnvironmentSubjectType SubjectType = "environment" + ServiceSubjectType SubjectType = "service" )