-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add empty data model events from the spec
Add all remaining events from the spec, with limitations: - empty data model (no extra fields in the subject) - no event specific test cases yet Apart from that, the events code is complete and the factory is updated to include all events, but commented out, so that we can only produce events that are ready. Signed-off-by: Andrea Frittoli <andrea.frittoli@gmail.com>
- Loading branch information
Showing
34 changed files
with
3,706 additions
and
69 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <subject> <predicate> | ||
# | ||
# 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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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{}, | ||
} | ||
} |
Oops, something went wrong.