Skip to content

Commit f2a7df2

Browse files
authored
Continuous Integration CDEvents to render as CloudEvent and schema validation (#45)
* continuous integration events impl * linter issues
1 parent c273dfc commit f2a7df2

19 files changed

+2364
-1
lines changed

src/main/java/dev/cdevents/constants/CDEventConstants.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,27 @@ public enum SubjectType {
4040
/**
4141
* Subject type change.
4242
*/
43-
CHANGE("change");
43+
CHANGE("change"),
44+
45+
/**
46+
* Subject type build.
47+
*/
48+
BUILD("build"),
49+
50+
/**
51+
* subject type testCase.
52+
*/
53+
TESTCASE("testCase"),
54+
55+
/**
56+
* subject type testSuite.
57+
*/
58+
TESTSUITE("testSuite"),
59+
60+
/**
61+
* subject type artifact.
62+
*/
63+
ARTIFACT("artifact");
4464

4565
private String subjectType;
4666

Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
package dev.cdevents.events;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import dev.cdevents.constants.CDEventConstants;
5+
import dev.cdevents.models.ArtifactPackagedSubject;
6+
import dev.cdevents.models.CDEvent;
7+
8+
import java.net.URI;
9+
10+
public class ArtifactPackagedCDEvent extends CDEvent {
11+
12+
private static final String CDEVENT_VERSION = "0.1.0";
13+
@JsonProperty(required = true)
14+
private ArtifactPackagedSubject subject;
15+
16+
/**
17+
* Constructor to init CDEvent and set the Subject for {@link ArtifactPackagedCDEvent}.
18+
*/
19+
public ArtifactPackagedCDEvent() {
20+
initCDEvent(currentCDEventType());
21+
setSubject(new ArtifactPackagedSubject(CDEventConstants.SubjectType.ARTIFACT));
22+
}
23+
24+
/**
25+
* @return subject
26+
*/
27+
public ArtifactPackagedSubject getSubject() {
28+
return subject;
29+
}
30+
31+
/**
32+
* @param subject
33+
*/
34+
public void setSubject(ArtifactPackagedSubject subject) {
35+
this.subject = subject;
36+
}
37+
38+
/**
39+
* @return the current CDEvent type
40+
*/
41+
@Override
42+
public String currentCDEventType() {
43+
return CDEventConstants.CDEventTypes.ArtifactPackagedEvent.getEventType().concat(CDEVENT_VERSION);
44+
}
45+
46+
/**
47+
* @return the artifact-packaged-event schema URL
48+
*/
49+
@Override
50+
public String schemaURL() {
51+
return String.format("https://cdevents.dev/%s/schema/artifact-packaged-event", CDEventConstants.CDEVENTS_SPEC_VERSION);
52+
}
53+
54+
/**
55+
* @return the artifact-packaged-event schema Json
56+
*/
57+
@Override
58+
public String eventSchema() {
59+
return "{\n" +
60+
" \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n" +
61+
" \"$id\": \"https://cdevents.dev/0.1.2/schema/artifact-packaged-event\",\n" +
62+
" \"properties\": {\n" +
63+
" \"context\": {\n" +
64+
" \"properties\": {\n" +
65+
" \"version\": {\n" +
66+
" \"type\": \"string\",\n" +
67+
" \"minLength\": 1\n" +
68+
" },\n" +
69+
" \"id\": {\n" +
70+
" \"type\": \"string\",\n" +
71+
" \"minLength\": 1\n" +
72+
" },\n" +
73+
" \"source\": {\n" +
74+
" \"type\": \"string\",\n" +
75+
" \"minLength\": 1\n" +
76+
" },\n" +
77+
" \"type\": {\n" +
78+
" \"type\": \"string\",\n" +
79+
" \"enum\": [\n" +
80+
" \"dev.cdevents.artifact.packaged.0.1.0\"\n" +
81+
" ],\n" +
82+
" \"default\": \"dev.cdevents.artifact.packaged.0.1.0\"\n" +
83+
" },\n" +
84+
" \"timestamp\": {\n" +
85+
" \"type\": \"string\",\n" +
86+
" \"format\": \"date-time\"\n" +
87+
" }\n" +
88+
" },\n" +
89+
" \"additionalProperties\": false,\n" +
90+
" \"type\": \"object\",\n" +
91+
" \"required\": [\n" +
92+
" \"version\",\n" +
93+
" \"id\",\n" +
94+
" \"source\",\n" +
95+
" \"type\",\n" +
96+
" \"timestamp\"\n" +
97+
" ]\n" +
98+
" },\n" +
99+
" \"subject\": {\n" +
100+
" \"properties\": {\n" +
101+
" \"id\": {\n" +
102+
" \"type\": \"string\",\n" +
103+
" \"minLength\": 1\n" +
104+
" },\n" +
105+
" \"source\": {\n" +
106+
" \"type\": \"string\"\n" +
107+
" },\n" +
108+
" \"type\": {\n" +
109+
" \"type\": \"string\",\n" +
110+
" \"minLength\": 1\n" +
111+
" },\n" +
112+
" \"content\": {\n" +
113+
" \"properties\": {\n" +
114+
" \"change\": {\n" +
115+
" \"properties\": {\n" +
116+
" \"id\": {\n" +
117+
" \"type\": \"string\",\n" +
118+
" \"minLength\": 1\n" +
119+
" },\n" +
120+
" \"source\": {\n" +
121+
" \"type\": \"string\"\n" +
122+
" }\n" +
123+
" },\n" +
124+
" \"additionalProperties\": false,\n" +
125+
" \"type\": \"object\",\n" +
126+
" \"required\": [\n" +
127+
" \"id\"\n" +
128+
" ]\n" +
129+
" }\n" +
130+
" },\n" +
131+
" \"additionalProperties\": false,\n" +
132+
" \"type\": \"object\",\n" +
133+
" \"required\": [\n" +
134+
" \"change\"\n" +
135+
" ]\n" +
136+
" }\n" +
137+
" },\n" +
138+
" \"additionalProperties\": false,\n" +
139+
" \"type\": \"object\",\n" +
140+
" \"required\": [\n" +
141+
" \"id\",\n" +
142+
" \"type\",\n" +
143+
" \"content\"\n" +
144+
" ]\n" +
145+
" },\n" +
146+
" \"customData\": {\n" +
147+
" \"oneOf\": [\n" +
148+
" {\n" +
149+
" \"type\": \"object\"\n" +
150+
" },\n" +
151+
" {\n" +
152+
" \"type\": \"string\",\n" +
153+
" \"contentEncoding\": \"base64\"\n" +
154+
" }\n" +
155+
" ]\n" +
156+
" },\n" +
157+
" \"customDataContentType\": {\n" +
158+
" \"type\": \"string\"\n" +
159+
" }\n" +
160+
" },\n" +
161+
" \"additionalProperties\": false,\n" +
162+
" \"type\": \"object\",\n" +
163+
" \"required\": [\n" +
164+
" \"context\",\n" +
165+
" \"subject\"\n" +
166+
" ]\n" +
167+
"}";
168+
}
169+
170+
/**
171+
* @param subjectId
172+
* sets the subject Id
173+
*/
174+
public void setSubjectId(String subjectId) {
175+
getSubject().setId(subjectId);
176+
}
177+
178+
/**
179+
* @param subjectSource
180+
* sets the subject source
181+
*/
182+
public void setSubjectSource(URI subjectSource) {
183+
getSubject().setSource(subjectSource);
184+
}
185+
186+
/**
187+
* @param changeId
188+
* sets The changeId that this artifact belongs to
189+
*/
190+
public void setSubjectChangeId(String changeId) {
191+
getSubject().getContent().getChange().setId(changeId);
192+
193+
}
194+
195+
/**
196+
* @param changeSource
197+
* sets The changeSource that this artifact belongs to
198+
*/
199+
public void setSubjectChangeSource(URI changeSource) {
200+
getSubject().getContent().getChange().setSource(changeSource);
201+
}
202+
203+
}
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
package dev.cdevents.events;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import dev.cdevents.constants.CDEventConstants;
5+
import dev.cdevents.models.ArtifactPublishedSubject;
6+
import dev.cdevents.models.CDEvent;
7+
8+
import java.net.URI;
9+
10+
public class ArtifactPublishedCDEvent extends CDEvent {
11+
12+
private static final String CDEVENT_VERSION = "0.1.0";
13+
@JsonProperty(required = true)
14+
private ArtifactPublishedSubject subject;
15+
16+
/**
17+
* Constructor to init CDEvent and set the Subject for {@link ArtifactPublishedCDEvent}.
18+
*/
19+
public ArtifactPublishedCDEvent() {
20+
initCDEvent(currentCDEventType());
21+
setSubject(new ArtifactPublishedSubject(CDEventConstants.SubjectType.ARTIFACT));
22+
}
23+
24+
/**
25+
* @return subject
26+
*/
27+
public ArtifactPublishedSubject getSubject() {
28+
return subject;
29+
}
30+
31+
/**
32+
* @param subject
33+
*/
34+
public void setSubject(ArtifactPublishedSubject subject) {
35+
this.subject = subject;
36+
}
37+
38+
/**
39+
* @return the current CDEvent type
40+
*/
41+
@Override
42+
public String currentCDEventType() {
43+
return CDEventConstants.CDEventTypes.ArtifactPublishedEvent.getEventType().concat(CDEVENT_VERSION);
44+
}
45+
46+
/**
47+
* @return the artifact-published-event schema URL
48+
*/
49+
@Override
50+
public String schemaURL() {
51+
return String.format("https://cdevents.dev/%s/schema/artifact-published-event", CDEventConstants.CDEVENTS_SPEC_VERSION);
52+
}
53+
54+
/**
55+
* @return the artifact-published-event schema Json
56+
*/
57+
@Override
58+
public String eventSchema() {
59+
return "{\n" +
60+
" \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n" +
61+
" \"$id\": \"https://cdevents.dev/0.1.2/schema/artifact-published-event\",\n" +
62+
" \"properties\": {\n" +
63+
" \"context\": {\n" +
64+
" \"properties\": {\n" +
65+
" \"version\": {\n" +
66+
" \"type\": \"string\",\n" +
67+
" \"minLength\": 1\n" +
68+
" },\n" +
69+
" \"id\": {\n" +
70+
" \"type\": \"string\",\n" +
71+
" \"minLength\": 1\n" +
72+
" },\n" +
73+
" \"source\": {\n" +
74+
" \"type\": \"string\",\n" +
75+
" \"minLength\": 1\n" +
76+
" },\n" +
77+
" \"type\": {\n" +
78+
" \"type\": \"string\",\n" +
79+
" \"enum\": [\n" +
80+
" \"dev.cdevents.artifact.published.0.1.0\"\n" +
81+
" ],\n" +
82+
" \"default\": \"dev.cdevents.artifact.published.0.1.0\"\n" +
83+
" },\n" +
84+
" \"timestamp\": {\n" +
85+
" \"type\": \"string\",\n" +
86+
" \"format\": \"date-time\"\n" +
87+
" }\n" +
88+
" },\n" +
89+
" \"additionalProperties\": false,\n" +
90+
" \"type\": \"object\",\n" +
91+
" \"required\": [\n" +
92+
" \"version\",\n" +
93+
" \"id\",\n" +
94+
" \"source\",\n" +
95+
" \"type\",\n" +
96+
" \"timestamp\"\n" +
97+
" ]\n" +
98+
" },\n" +
99+
" \"subject\": {\n" +
100+
" \"properties\": {\n" +
101+
" \"id\": {\n" +
102+
" \"type\": \"string\",\n" +
103+
" \"minLength\": 1\n" +
104+
" },\n" +
105+
" \"source\": {\n" +
106+
" \"type\": \"string\"\n" +
107+
" },\n" +
108+
" \"type\": {\n" +
109+
" \"type\": \"string\",\n" +
110+
" \"minLength\": 1\n" +
111+
" },\n" +
112+
" \"content\": {\n" +
113+
" \"properties\": {},\n" +
114+
" \"additionalProperties\": false,\n" +
115+
" \"type\": \"object\"\n" +
116+
" }\n" +
117+
" },\n" +
118+
" \"additionalProperties\": false,\n" +
119+
" \"type\": \"object\",\n" +
120+
" \"required\": [\n" +
121+
" \"id\",\n" +
122+
" \"type\",\n" +
123+
" \"content\"\n" +
124+
" ]\n" +
125+
" },\n" +
126+
" \"customData\": {\n" +
127+
" \"oneOf\": [\n" +
128+
" {\n" +
129+
" \"type\": \"object\"\n" +
130+
" },\n" +
131+
" {\n" +
132+
" \"type\": \"string\",\n" +
133+
" \"contentEncoding\": \"base64\"\n" +
134+
" }\n" +
135+
" ]\n" +
136+
" },\n" +
137+
" \"customDataContentType\": {\n" +
138+
" \"type\": \"string\"\n" +
139+
" }\n" +
140+
" },\n" +
141+
" \"additionalProperties\": false,\n" +
142+
" \"type\": \"object\",\n" +
143+
" \"required\": [\n" +
144+
" \"context\",\n" +
145+
" \"subject\"\n" +
146+
" ]\n" +
147+
"}";
148+
}
149+
150+
/**
151+
* @param subjectId
152+
* sets the subject Id
153+
*/
154+
public void setSubjectId(String subjectId) {
155+
getSubject().setId(subjectId);
156+
}
157+
158+
/**
159+
* @param subjectSource
160+
* sets the subject source
161+
*/
162+
public void setSubjectSource(URI subjectSource) {
163+
getSubject().setSource(subjectSource);
164+
}
165+
166+
}

0 commit comments

Comments
 (0)