Skip to content

Continuous Integration CDEvents to render as CloudEvent and schema validation #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion src/main/java/dev/cdevents/constants/CDEventConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,27 @@ public enum SubjectType {
/**
* Subject type change.
*/
CHANGE("change");
CHANGE("change"),

/**
* Subject type build.
*/
BUILD("build"),

/**
* subject type testCase.
*/
TESTCASE("testCase"),

/**
* subject type testSuite.
*/
TESTSUITE("testSuite"),

/**
* subject type artifact.
*/
ARTIFACT("artifact");

private String subjectType;

Expand Down
203 changes: 203 additions & 0 deletions src/main/java/dev/cdevents/events/ArtifactPackagedCDEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
package dev.cdevents.events;

import com.fasterxml.jackson.annotation.JsonProperty;
import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.models.ArtifactPackagedSubject;
import dev.cdevents.models.CDEvent;

import java.net.URI;

public class ArtifactPackagedCDEvent extends CDEvent {

private static final String CDEVENT_VERSION = "0.1.0";
@JsonProperty(required = true)
private ArtifactPackagedSubject subject;

/**
* Constructor to init CDEvent and set the Subject for {@link ArtifactPackagedCDEvent}.
*/
public ArtifactPackagedCDEvent() {
initCDEvent(currentCDEventType());
setSubject(new ArtifactPackagedSubject(CDEventConstants.SubjectType.ARTIFACT));
}

/**
* @return subject
*/
public ArtifactPackagedSubject getSubject() {
return subject;
}

/**
* @param subject
*/
public void setSubject(ArtifactPackagedSubject subject) {
this.subject = subject;
}

/**
* @return the current CDEvent type
*/
@Override
public String currentCDEventType() {
return CDEventConstants.CDEventTypes.ArtifactPackagedEvent.getEventType().concat(CDEVENT_VERSION);
}

/**
* @return the artifact-packaged-event schema URL
*/
@Override
public String schemaURL() {
return String.format("https://cdevents.dev/%s/schema/artifact-packaged-event", CDEventConstants.CDEVENTS_SPEC_VERSION);
}

/**
* @return the artifact-packaged-event schema Json
*/
@Override
public String eventSchema() {
return "{\n" +
" \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n" +
" \"$id\": \"https://cdevents.dev/0.1.2/schema/artifact-packaged-event\",\n" +
" \"properties\": {\n" +
" \"context\": {\n" +
" \"properties\": {\n" +
" \"version\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"id\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"source\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"type\": {\n" +
" \"type\": \"string\",\n" +
" \"enum\": [\n" +
" \"dev.cdevents.artifact.packaged.0.1.0\"\n" +
" ],\n" +
" \"default\": \"dev.cdevents.artifact.packaged.0.1.0\"\n" +
" },\n" +
" \"timestamp\": {\n" +
" \"type\": \"string\",\n" +
" \"format\": \"date-time\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"version\",\n" +
" \"id\",\n" +
" \"source\",\n" +
" \"type\",\n" +
" \"timestamp\"\n" +
" ]\n" +
" },\n" +
" \"subject\": {\n" +
" \"properties\": {\n" +
" \"id\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"source\": {\n" +
" \"type\": \"string\"\n" +
" },\n" +
" \"type\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"content\": {\n" +
" \"properties\": {\n" +
" \"change\": {\n" +
" \"properties\": {\n" +
" \"id\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"source\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"id\"\n" +
" ]\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"change\"\n" +
" ]\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"id\",\n" +
" \"type\",\n" +
" \"content\"\n" +
" ]\n" +
" },\n" +
" \"customData\": {\n" +
" \"oneOf\": [\n" +
" {\n" +
" \"type\": \"object\"\n" +
" },\n" +
" {\n" +
" \"type\": \"string\",\n" +
" \"contentEncoding\": \"base64\"\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"customDataContentType\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"context\",\n" +
" \"subject\"\n" +
" ]\n" +
"}";
}

/**
* @param subjectId
* sets the subject Id
*/
public void setSubjectId(String subjectId) {
getSubject().setId(subjectId);
}

/**
* @param subjectSource
* sets the subject source
*/
public void setSubjectSource(URI subjectSource) {
getSubject().setSource(subjectSource);
}

/**
* @param changeId
* sets The changeId that this artifact belongs to
*/
public void setSubjectChangeId(String changeId) {
getSubject().getContent().getChange().setId(changeId);

}

/**
* @param changeSource
* sets The changeSource that this artifact belongs to
*/
public void setSubjectChangeSource(URI changeSource) {
getSubject().getContent().getChange().setSource(changeSource);
}

}
166 changes: 166 additions & 0 deletions src/main/java/dev/cdevents/events/ArtifactPublishedCDEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,166 @@
package dev.cdevents.events;

import com.fasterxml.jackson.annotation.JsonProperty;
import dev.cdevents.constants.CDEventConstants;
import dev.cdevents.models.ArtifactPublishedSubject;
import dev.cdevents.models.CDEvent;

import java.net.URI;

public class ArtifactPublishedCDEvent extends CDEvent {

private static final String CDEVENT_VERSION = "0.1.0";
@JsonProperty(required = true)
private ArtifactPublishedSubject subject;

/**
* Constructor to init CDEvent and set the Subject for {@link ArtifactPublishedCDEvent}.
*/
public ArtifactPublishedCDEvent() {
initCDEvent(currentCDEventType());
setSubject(new ArtifactPublishedSubject(CDEventConstants.SubjectType.ARTIFACT));
}

/**
* @return subject
*/
public ArtifactPublishedSubject getSubject() {
return subject;
}

/**
* @param subject
*/
public void setSubject(ArtifactPublishedSubject subject) {
this.subject = subject;
}

/**
* @return the current CDEvent type
*/
@Override
public String currentCDEventType() {
return CDEventConstants.CDEventTypes.ArtifactPublishedEvent.getEventType().concat(CDEVENT_VERSION);
}

/**
* @return the artifact-published-event schema URL
*/
@Override
public String schemaURL() {
return String.format("https://cdevents.dev/%s/schema/artifact-published-event", CDEventConstants.CDEVENTS_SPEC_VERSION);
}

/**
* @return the artifact-published-event schema Json
*/
@Override
public String eventSchema() {
return "{\n" +
" \"$schema\": \"https://json-schema.org/draft/2020-12/schema\",\n" +
" \"$id\": \"https://cdevents.dev/0.1.2/schema/artifact-published-event\",\n" +
" \"properties\": {\n" +
" \"context\": {\n" +
" \"properties\": {\n" +
" \"version\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"id\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"source\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"type\": {\n" +
" \"type\": \"string\",\n" +
" \"enum\": [\n" +
" \"dev.cdevents.artifact.published.0.1.0\"\n" +
" ],\n" +
" \"default\": \"dev.cdevents.artifact.published.0.1.0\"\n" +
" },\n" +
" \"timestamp\": {\n" +
" \"type\": \"string\",\n" +
" \"format\": \"date-time\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"version\",\n" +
" \"id\",\n" +
" \"source\",\n" +
" \"type\",\n" +
" \"timestamp\"\n" +
" ]\n" +
" },\n" +
" \"subject\": {\n" +
" \"properties\": {\n" +
" \"id\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"source\": {\n" +
" \"type\": \"string\"\n" +
" },\n" +
" \"type\": {\n" +
" \"type\": \"string\",\n" +
" \"minLength\": 1\n" +
" },\n" +
" \"content\": {\n" +
" \"properties\": {},\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"id\",\n" +
" \"type\",\n" +
" \"content\"\n" +
" ]\n" +
" },\n" +
" \"customData\": {\n" +
" \"oneOf\": [\n" +
" {\n" +
" \"type\": \"object\"\n" +
" },\n" +
" {\n" +
" \"type\": \"string\",\n" +
" \"contentEncoding\": \"base64\"\n" +
" }\n" +
" ]\n" +
" },\n" +
" \"customDataContentType\": {\n" +
" \"type\": \"string\"\n" +
" }\n" +
" },\n" +
" \"additionalProperties\": false,\n" +
" \"type\": \"object\",\n" +
" \"required\": [\n" +
" \"context\",\n" +
" \"subject\"\n" +
" ]\n" +
"}";
}

/**
* @param subjectId
* sets the subject Id
*/
public void setSubjectId(String subjectId) {
getSubject().setId(subjectId);
}

/**
* @param subjectSource
* sets the subject source
*/
public void setSubjectSource(URI subjectSource) {
getSubject().setSource(subjectSource);
}

}
Loading