diff --git a/README.md b/README.md index 144bd5c..2c7a517 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ func main() { // Set the required subject fields event.SetSubjectPipelineName("myPipeline") - event.SetSubjectURL("https://example.com/myPipeline") + event.SetSubjectUrl("https://example.com/myPipeline") } ``` diff --git a/jsonschema/repositorycreated.json b/jsonschema/repositorycreated.json new file mode 100644 index 0000000..3028241 --- /dev/null +++ b/jsonschema/repositorycreated.json @@ -0,0 +1,91 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/cdevents/sdk-go/pkg/api/repository-created-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "minLength": 1 + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1 + }, + "content": { + "properties": { + "name": { + "type": "string", + "minLength": 1 + }, + "owner": { + "type": "string" + }, + "url": { + "type": "string", + "minLength": 1 + }, + "viewUrl": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "name", + "url" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} \ No newline at end of file diff --git a/jsonschema/repositorydeleted.json b/jsonschema/repositorydeleted.json new file mode 100644 index 0000000..c2bb926 --- /dev/null +++ b/jsonschema/repositorydeleted.json @@ -0,0 +1,85 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/cdevents/sdk-go/pkg/api/repository-deleted-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "minLength": 1 + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1 + }, + "content": { + "properties": { + "name": { + "type": "string" + }, + "owner": { + "type": "string" + }, + "url": { + "type": "string" + }, + "viewUrl": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} \ No newline at end of file diff --git a/jsonschema/repositorymodified.json b/jsonschema/repositorymodified.json new file mode 100644 index 0000000..128a2e9 --- /dev/null +++ b/jsonschema/repositorymodified.json @@ -0,0 +1,85 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://github.com/cdevents/sdk-go/pkg/api/repository-modified-event", + "properties": { + "context": { + "properties": { + "version": { + "type": "string", + "minLength": 1 + }, + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string", + "minLength": 1 + }, + "type": { + "type": "string", + "minLength": 1 + }, + "timestamp": { + "type": "string", + "format": "date-time" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "version", + "id", + "source", + "type", + "timestamp" + ] + }, + "subject": { + "properties": { + "id": { + "type": "string", + "minLength": 1 + }, + "source": { + "type": "string" + }, + "type": { + "type": "string", + "minLength": 1 + }, + "content": { + "properties": { + "name": { + "type": "string" + }, + "owner": { + "type": "string" + }, + "url": { + "type": "string" + }, + "viewUrl": { + "type": "string" + } + }, + "additionalProperties": false, + "type": "object" + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "id", + "type", + "content" + ] + } + }, + "additionalProperties": false, + "type": "object", + "required": [ + "context", + "subject" + ] +} \ No newline at end of file diff --git a/main.go b/main.go index db2f789..522ba65 100644 --- a/main.go +++ b/main.go @@ -39,6 +39,9 @@ var ( "changereviewed": &api.ChangeReviewedEvent{}, "changemerged": &api.ChangeMergedEvent{}, "changeabandoned": &api.ChangeAbandonedEvent{}, + "repositorycreated": &api.RepositoryCreatedEvent{}, + "repositorymodified": &api.RepositoryModifiedEvent{}, + "repositorydeleted": &api.RepositoryDeletedEvent{}, } ) diff --git a/pkg/api/bindings_test.go b/pkg/api/bindings_test.go index d3d9274..c30751a 100644 --- a/pkg/api/bindings_test.go +++ b/pkg/api/bindings_test.go @@ -34,12 +34,16 @@ var ( testSource = "TestAsCloudEvent" testSubjectId = "mySubject123" testPipeline = "myPipeline" - testSubjectURL = "https://www.example.com/mySubject123" + testSubjecturl = "https://www.example.com/mySubject123" testPipelineOutcome = PipelineRunOutcomeFailed testPipelineErrors = "Something went wrong\nWith some more details" testTaskName = "myTask" testTaskOutcome = TaskRunOutcomeFailed testTaskRunErrors = "Something went wrong\nWith some more details" + testRepo = "TestRepo" + testOwner = "TestOrg" + testUrl = "https://example.org/TestOrg/TestRepo" + testViewUrl = "https://example.org/view/TestOrg/TestRepo" pipelineRunQueuedEvent *PipelineRunQueuedEvent pipelineRunStartedEvent *PipelineRunStartedEvent @@ -51,6 +55,9 @@ var ( changeReviewedEvent *ChangeReviewedEvent changeMergedEvent *ChangeMergedEvent changeAbandonedEvent *ChangeAbandonedEvent + repositoryCreatedEvent *RepositoryCreatedEvent + repositoryModifiedEvent *RepositoryModifiedEvent + repositoryDeletedEvent *RepositoryDeletedEvent pipelineRunQueuedEventJsonTemplate = ` { @@ -238,6 +245,69 @@ var ( } }` + repositoryCreatedEventJsonTemplate = `{ + "context": { + "version": "draft", + "id": "%s", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.repository.created.v1", + "timestamp": "%s" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "repository", + "content": { + "name": "TestRepo", + "owner": "TestOrg", + "url": "https://example.org/TestOrg/TestRepo", + "viewUrl": "https://example.org/view/TestOrg/TestRepo" + } + } +}` + + repositoryModifiedEventJsonTemplate = `{ + "context": { + "version": "draft", + "id": "%s", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.repository.modified.v1", + "timestamp": "%s" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "repository", + "content": { + "name": "TestRepo", + "owner": "TestOrg", + "url": "https://example.org/TestOrg/TestRepo", + "viewUrl": "https://example.org/view/TestOrg/TestRepo" + } + } +}` + + repositoryDeletedEventJsonTemplate = `{ + "context": { + "version": "draft", + "id": "%s", + "source": "TestAsCloudEvent", + "type": "dev.cdevents.repository.deleted.v1", + "timestamp": "%s" + }, + "subject": { + "id": "mySubject123", + "source": "TestAsCloudEvent", + "type": "repository", + "content": { + "name": "TestRepo", + "owner": "TestOrg", + "url": "https://example.org/TestOrg/TestRepo", + "viewUrl": "https://example.org/view/TestOrg/TestRepo" + } + } +}` + pipelineRunQueuedEventJson string pipelineRunStartedEventJson string pipelineRunFinishedEventJson string @@ -248,6 +318,9 @@ var ( changeReviewedEventJson string changeMergedEventJson string changeAbandonedEventJson string + repositoryCreatedEventJson string + repositoryModifiedEventJson string + repositoryDeletedEventJson string ) func init() { @@ -274,30 +347,30 @@ func init() { pipelineRunQueuedEvent, _ = NewPipelineRunQueuedEvent() setContext(pipelineRunQueuedEvent) pipelineRunQueuedEvent.SetSubjectPipelineName(testPipeline) - pipelineRunQueuedEvent.SetSubjectURL(testSubjectURL) + pipelineRunQueuedEvent.SetSubjectUrl(testSubjecturl) pipelineRunStartedEvent, _ = NewPipelineRunStartedEvent() setContext(pipelineRunStartedEvent) pipelineRunStartedEvent.SetSubjectPipelineName(testPipeline) - pipelineRunStartedEvent.SetSubjectURL(testSubjectURL) + pipelineRunStartedEvent.SetSubjectUrl(testSubjecturl) pipelineRunFinishedEvent, _ = NewPipelineRunFinishedEvent() setContext(pipelineRunFinishedEvent) pipelineRunFinishedEvent.SetSubjectPipelineName(testPipeline) - pipelineRunFinishedEvent.SetSubjectURL(testSubjectURL) + pipelineRunFinishedEvent.SetSubjectUrl(testSubjecturl) pipelineRunFinishedEvent.SetSubjectOutcome(testPipelineOutcome) pipelineRunFinishedEvent.SetSubjectErrors(testPipelineErrors) taskRunStartedEvent, _ = NewTaskRunStartedEvent() setContext(taskRunStartedEvent) taskRunStartedEvent.SetSubjectTaskName(testTaskName) - taskRunStartedEvent.SetSubjectURL(testSubjectURL) + taskRunStartedEvent.SetSubjectUrl(testSubjecturl) taskRunStartedEvent.SetSubjectPipelineRun(Reference{Id: testSubjectId}) taskRunFinishedEvent, _ = NewTaskRunFinishedEvent() setContext(taskRunFinishedEvent) taskRunFinishedEvent.SetSubjectTaskName(testTaskName) - taskRunFinishedEvent.SetSubjectURL(testSubjectURL) + taskRunFinishedEvent.SetSubjectUrl(testSubjecturl) taskRunFinishedEvent.SetSubjectPipelineRun(Reference{Id: testSubjectId}) taskRunFinishedEvent.SetSubjectOutcome(testTaskOutcome) taskRunFinishedEvent.SetSubjectErrors(testTaskRunErrors) @@ -317,6 +390,27 @@ func init() { changeAbandonedEvent, _ = NewChangeAbandonedEvent() setContext(changeAbandonedEvent) + repositoryCreatedEvent, _ = NewRepositoryCreatedEvent() + setContext(repositoryCreatedEvent) + repositoryCreatedEvent.SetSubjectName(testRepo) + repositoryCreatedEvent.SetSubjectOwner(testOwner) + repositoryCreatedEvent.SetSubjectUrl(testUrl) + repositoryCreatedEvent.SetSubjectViewUrl(testViewUrl) + + repositoryModifiedEvent, _ = NewRepositoryModifiedEvent() + setContext(repositoryModifiedEvent) + repositoryModifiedEvent.SetSubjectName(testRepo) + repositoryModifiedEvent.SetSubjectOwner(testOwner) + repositoryModifiedEvent.SetSubjectUrl(testUrl) + repositoryModifiedEvent.SetSubjectViewUrl(testViewUrl) + + repositoryDeletedEvent, _ = NewRepositoryDeletedEvent() + setContext(repositoryDeletedEvent) + repositoryDeletedEvent.SetSubjectName(testRepo) + repositoryDeletedEvent.SetSubjectOwner(testOwner) + repositoryDeletedEvent.SetSubjectUrl(testUrl) + repositoryDeletedEvent.SetSubjectViewUrl(testViewUrl) + newUUID, _ := uuidNewRandom() newTime := timeNow().Format(time.RFC3339Nano) pipelineRunQueuedEventJson = fmt.Sprintf(pipelineRunQueuedEventJsonTemplate, newUUID, newTime) @@ -329,6 +423,9 @@ func init() { changeReviewedEventJson = fmt.Sprintf(changeReviewedEventJsonTemplate, newUUID, newTime) changeMergedEventJson = fmt.Sprintf(changeMergedEventJsonTemplate, newUUID, newTime) changeAbandonedEventJson = fmt.Sprintf(changeAbandonedEventJsonTemplate, newUUID, newTime) + repositoryCreatedEventJson = fmt.Sprintf(repositoryCreatedEventJsonTemplate, newUUID, newTime) + repositoryModifiedEventJson = fmt.Sprintf(repositoryModifiedEventJsonTemplate, newUUID, newTime) + repositoryDeletedEventJson = fmt.Sprintf(repositoryDeletedEventJsonTemplate, newUUID, newTime) } func TestAsCloudEvent(t *testing.T) { @@ -377,6 +474,18 @@ func TestAsCloudEvent(t *testing.T) { name: "change abandoned", event: changeAbandonedEvent, payloadReceiver: &ChangeAbandonedEvent{}, + }, { + name: "repository created", + event: repositoryCreatedEvent, + payloadReceiver: &RepositoryCreatedEvent{}, + }, { + name: "repository modified", + event: repositoryModifiedEvent, + payloadReceiver: &RepositoryModifiedEvent{}, + }, { + name: "repository deleted", + event: repositoryDeletedEvent, + payloadReceiver: &RepositoryDeletedEvent{}, }} for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { @@ -470,6 +579,21 @@ func TestAsJsonString(t *testing.T) { event: changeAbandonedEvent, jsonString: changeAbandonedEventJson, schemaName: "changeabandoned", + }, { + name: "repository created", + event: repositoryCreatedEvent, + jsonString: repositoryCreatedEventJson, + schemaName: "repositorycreated", + }, { + name: "repository modified", + event: repositoryModifiedEvent, + jsonString: repositoryModifiedEventJson, + schemaName: "repositorymodified", + }, { + name: "repository deleted", + event: repositoryDeletedEvent, + jsonString: repositoryDeletedEventJson, + schemaName: "repositorydeleted", }} for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { @@ -504,15 +628,24 @@ func TestAsJsonString(t *testing.T) { func TestInvalidEvent(t *testing.T) { - eventNoSource, _ := NewChangeAbandonedEvent() + // mandatory source missing + eventNoSource, _ := NewCDEvent(ChangeAbandonedEventV1) eventNoSource.SetSubjectId(testSubjectId) - eventNoSubjectId, _ := NewChangeAbandonedEvent() + // mandatory subject id missing + eventNoSubjectId, _ := NewCDEvent(ChangeAbandonedEventV1) eventNoSubjectId.SetSource(testSource) + // forced invalid version eventBadVersion, _ := NewChangeAbandonedEvent() eventBadVersion.Context.Version = "invalid" + // mandatory subject url missing + eventIncompleteSubject, _ := NewRepositoryCreatedEvent() + eventIncompleteSubject.SetSource(testSource) + eventIncompleteSubject.SetSubjectId(testSubjectId) + eventIncompleteSubject.SetSubjectName(testRepo) + tests := []struct { name string event CDEvent @@ -525,6 +658,9 @@ func TestInvalidEvent(t *testing.T) { }, { name: "invalid version", event: eventBadVersion, + }, { + name: "missing subject url", + event: eventIncompleteSubject, }} for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { diff --git a/pkg/api/pipelinerunfinished.go b/pkg/api/pipelinerunfinished.go index 964bef1..fb47219 100644 --- a/pkg/api/pipelinerunfinished.go +++ b/pkg/api/pipelinerunfinished.go @@ -50,7 +50,7 @@ type PipelineRunFinishedSubjectContent struct { PipelineName string `json:"pipelineName,omitempty"` // A URL to the pipeline run - URL string `json:"url,omitempty"` + Url string `json:"url,omitempty"` // The PipelineRun outcome Outcome PipelineRunOutcome `json:"outcome,omitempty"` @@ -143,8 +143,8 @@ func (e *PipelineRunFinishedEvent) SetSubjectPipelineName(pipelineName string) { e.Subject.Content.PipelineName = pipelineName } -func (e *PipelineRunFinishedEvent) SetSubjectURL(url string) { - e.Subject.Content.URL = url +func (e *PipelineRunFinishedEvent) SetSubjectUrl(url string) { + e.Subject.Content.Url = url } func (e *PipelineRunFinishedEvent) SetSubjectOutcome(outcome PipelineRunOutcome) { diff --git a/pkg/api/pipelinerunqueued.go b/pkg/api/pipelinerunqueued.go index 6ccdee9..5d90acb 100644 --- a/pkg/api/pipelinerunqueued.go +++ b/pkg/api/pipelinerunqueued.go @@ -34,7 +34,7 @@ type PipelineRunQueuedSubjectContent struct { PipelineName string `json:"pipelineName,omitempty"` // A URL to the pipeline run - URL string `json:"url,omitempty"` + Url string `json:"url,omitempty"` } type PipelineRunQueuedSubject struct { @@ -121,8 +121,8 @@ func (e *PipelineRunQueuedEvent) SetSubjectPipelineName(pipelineName string) { e.Subject.Content.PipelineName = pipelineName } -func (e *PipelineRunQueuedEvent) SetSubjectURL(url string) { - e.Subject.Content.URL = url +func (e *PipelineRunQueuedEvent) SetSubjectUrl(url string) { + e.Subject.Content.Url = url } func (e PipelineRunQueuedEvent) GetSchema() string { diff --git a/pkg/api/pipelinerunstarted.go b/pkg/api/pipelinerunstarted.go index 1a5203f..75b153d 100644 --- a/pkg/api/pipelinerunstarted.go +++ b/pkg/api/pipelinerunstarted.go @@ -34,7 +34,7 @@ type PipelineRunStartedSubjectContent struct { PipelineName string `json:"pipelineName"` // A URL to the pipeline run - URL string `json:"url"` + Url string `json:"url"` } type PipelineRunStartedSubject struct { @@ -121,8 +121,8 @@ func (e *PipelineRunStartedEvent) SetSubjectPipelineName(pipelineName string) { e.Subject.Content.PipelineName = pipelineName } -func (e *PipelineRunStartedEvent) SetSubjectURL(url string) { - e.Subject.Content.URL = url +func (e *PipelineRunStartedEvent) SetSubjectUrl(url string) { + e.Subject.Content.Url = url } func (e PipelineRunStartedEvent) GetSchema() string { diff --git a/pkg/api/repositorycreated.go b/pkg/api/repositorycreated.go index fd5ab25..c76e1d7 100644 --- a/pkg/api/repositorycreated.go +++ b/pkg/api/repositorycreated.go @@ -28,7 +28,20 @@ const ( repositoryCreatedSchemaFile string = "repositorycreated" ) -type RepositoryCreatedSubjectContent struct{} +type RepositoryCreatedSubjectContent struct { + + // The name of the repository, like "sdk-go", "spec" or "a-repo" + Name string `json:"name" jsonschema:"required,minLength=1"` + + // The owner of the repository, like "cdevents", "an-org" or "an-user" + Owner string `json:"owner,omitempty"` + + // The URL to programmatically access repository, for instance via "git clone" + Url string `json:"url" jsonschema:"required,minLength=1"` + + // The URL for a human to browse the repository, for instance a Web UI to the repo + ViewUrl string `json:"viewUrl,omitempty"` +} type RepositoryCreatedSubject struct { SubjectBase @@ -112,13 +125,34 @@ func (e RepositoryCreatedEvent) GetSchema() string { return repositoryCreatedSchemaFile } +// Subject field setters +func (e *RepositoryCreatedEvent) SetSubjectName(name string) { + e.Subject.Content.Name = name +} + +func (e *RepositoryCreatedEvent) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +func (e *RepositoryCreatedEvent) SetSubjectOwner(owner string) { + e.Subject.Content.Owner = owner +} + +func (e *RepositoryCreatedEvent) SetSubjectViewUrl(viewUrl string) { + e.Subject.Content.ViewUrl = viewUrl +} + func NewRepositoryCreatedEvent() (*RepositoryCreatedEvent, error) { e := &RepositoryCreatedEvent{ Context: Context{ Type: RepositoryCreatedEventV1, Version: CDEventsSpecVersion, }, - Subject: RepositoryCreatedSubject{}, + Subject: RepositoryCreatedSubject{ + SubjectBase: SubjectBase{ + Type: RepositorySubjectType, + }, + }, } _, err := initCDEvent(e) if err != nil { diff --git a/pkg/api/repositorydeleted.go b/pkg/api/repositorydeleted.go index 6e3b017..32334d2 100644 --- a/pkg/api/repositorydeleted.go +++ b/pkg/api/repositorydeleted.go @@ -28,7 +28,20 @@ const ( repositoryDeletedSchemaFile string = "repositorydeleted" ) -type RepositoryDeletedSubjectContent struct{} +type RepositoryDeletedSubjectContent struct { + + // The name of the repository, like "sdk-go", "spec" or "a-repo" + Name string `json:"name,omitempty"` + + // The owner of the repository, like "cdevents", "an-org" or "an-user" + Owner string `json:"owner,omitempty"` + + // The URL to programmatically access repository, for instance via "git clone" + Url string `json:"url,omitempty"` + + // The URL for a human to browse the repository, for instance a Web UI to the repo + ViewUrl string `json:"viewUrl,omitempty"` +} type RepositoryDeletedSubject struct { SubjectBase @@ -112,13 +125,34 @@ func (e RepositoryDeletedEvent) GetSchema() string { return repositoryDeletedSchemaFile } +// Subject field setters +func (e *RepositoryDeletedEvent) SetSubjectName(name string) { + e.Subject.Content.Name = name +} + +func (e *RepositoryDeletedEvent) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +func (e *RepositoryDeletedEvent) SetSubjectOwner(owner string) { + e.Subject.Content.Owner = owner +} + +func (e *RepositoryDeletedEvent) SetSubjectViewUrl(viewUrl string) { + e.Subject.Content.ViewUrl = viewUrl +} + func NewRepositoryDeletedEvent() (*RepositoryDeletedEvent, error) { e := &RepositoryDeletedEvent{ Context: Context{ Type: RepositoryDeletedEventV1, Version: CDEventsSpecVersion, }, - Subject: RepositoryDeletedSubject{}, + Subject: RepositoryDeletedSubject{ + SubjectBase: SubjectBase{ + Type: RepositorySubjectType, + }, + }, } _, err := initCDEvent(e) if err != nil { diff --git a/pkg/api/repositorymodified.go b/pkg/api/repositorymodified.go index 06538a3..46ebff3 100644 --- a/pkg/api/repositorymodified.go +++ b/pkg/api/repositorymodified.go @@ -28,7 +28,20 @@ const ( repositoryModifiedSchemaFile string = "repositorymodified" ) -type RepositoryModifiedSubjectContent struct{} +type RepositoryModifiedSubjectContent struct { + + // The name of the repository, like "sdk-go", "spec" or "a-repo" + Name string `json:"name,omitempty"` + + // The owner of the repository, like "cdevents", "an-org" or "an-user" + Owner string `json:"owner,omitempty"` + + // The URL to programmatically access repository, for instance via "git clone" + Url string `json:"url,omitempty"` + + // The URL for a human to browse the repository, for instance a Web UI to the repo + ViewUrl string `json:"viewUrl,omitempty"` +} type RepositoryModifiedSubject struct { SubjectBase @@ -112,13 +125,34 @@ func (e RepositoryModifiedEvent) GetSchema() string { return repositoryModifiedSchemaFile } +// Subject field setters +func (e *RepositoryModifiedEvent) SetSubjectName(name string) { + e.Subject.Content.Name = name +} + +func (e *RepositoryModifiedEvent) SetSubjectUrl(url string) { + e.Subject.Content.Url = url +} + +func (e *RepositoryModifiedEvent) SetSubjectOwner(owner string) { + e.Subject.Content.Owner = owner +} + +func (e *RepositoryModifiedEvent) SetSubjectViewUrl(viewUrl string) { + e.Subject.Content.ViewUrl = viewUrl +} + func NewRepositoryModifiedEvent() (*RepositoryModifiedEvent, error) { e := &RepositoryModifiedEvent{ Context: Context{ Type: RepositoryModifiedEventV1, Version: CDEventsSpecVersion, }, - Subject: RepositoryModifiedSubject{}, + Subject: RepositoryModifiedSubject{ + SubjectBase: SubjectBase{ + Type: RepositorySubjectType, + }, + }, } _, err := initCDEvent(e) if err != nil { diff --git a/pkg/api/taskrunfinished.go b/pkg/api/taskrunfinished.go index 5f54475..e5b4bda 100644 --- a/pkg/api/taskrunfinished.go +++ b/pkg/api/taskrunfinished.go @@ -49,7 +49,7 @@ type TaskRunFinishedSubjectContent struct { TaskName string `json:"taskName,omitempty"` // A URL to the pipeline run - URL string `json:"url,omitempty"` + Url string `json:"url,omitempty"` // The PipelineRun associated to the task run PipelineRun Reference `json:"pipelineRun,omitempty"` @@ -145,8 +145,8 @@ func (e *TaskRunFinishedEvent) SetSubjectTaskName(pipelineName string) { e.Subject.Content.TaskName = pipelineName } -func (e *TaskRunFinishedEvent) SetSubjectURL(url string) { - e.Subject.Content.URL = url +func (e *TaskRunFinishedEvent) SetSubjectUrl(url string) { + e.Subject.Content.Url = url } func (e *TaskRunFinishedEvent) SetSubjectPipelineRun(pipelineRun Reference) { diff --git a/pkg/api/taskrunstarted.go b/pkg/api/taskrunstarted.go index f113074..d6e4f3d 100644 --- a/pkg/api/taskrunstarted.go +++ b/pkg/api/taskrunstarted.go @@ -34,7 +34,7 @@ type TaskRunStartedSubjectContent struct { TaskName string `json:"taskName,omitempty"` // A URL to the pipeline run - URL string `json:"url,omitempty"` + Url string `json:"url,omitempty"` // The PipelineRun associated to the task run PipelineRun Reference `json:"pipelineRun,omitempty"` @@ -124,8 +124,8 @@ func (e *TaskRunStartedEvent) SetSubjectTaskName(pipelineName string) { e.Subject.Content.TaskName = pipelineName } -func (e *TaskRunStartedEvent) SetSubjectURL(url string) { - e.Subject.Content.URL = url +func (e *TaskRunStartedEvent) SetSubjectUrl(url string) { + e.Subject.Content.Url = url } func (e *TaskRunStartedEvent) SetSubjectPipelineRun(pipelineRun Reference) {