diff --git a/events/codebuild.go b/events/codebuild.go index 82e1eeea..a227abd0 100644 --- a/events/codebuild.go +++ b/events/codebuild.go @@ -103,6 +103,8 @@ type CodeBuildEventAdditionalInformation struct { BuildComplete bool `json:"build-complete"` + BuildNumber CodeBuildNumber `json:"build-number,omitempty"` + Initiator string `json:"initiator"` BuildStartTime CodeBuildTime `json:"build-start-time"` @@ -195,3 +197,22 @@ func (t *CodeBuildTime) UnmarshalJSON(data []byte) error { *t = CodeBuildTime(ts) return nil } + +// CodeBuildNumber represents the number of the build +type CodeBuildNumber int32 + +// MarshalJSON converts a given CodeBuildNumber to json +func (n CodeBuildNumber) MarshalJSON() ([]byte, error) { + return json.Marshal(float32(n)) +} + +// UnmarshalJSON converts a given json to a CodeBuildNumber +func (n *CodeBuildNumber) UnmarshalJSON(data []byte) error { + var f float32 + if err := json.Unmarshal(data, &f); err != nil { + return err + } + + *n = CodeBuildNumber(int32(f)) + return nil +} diff --git a/events/codebuild_test.go b/events/codebuild_test.go index bc03032d..1f8032fc 100644 --- a/events/codebuild_test.go +++ b/events/codebuild_test.go @@ -52,6 +52,7 @@ func TestUnmarshalCodeBuildEvent(t *testing.T) { }, Timeout: DurationMinutes(60 * time.Minute), BuildComplete: true, + BuildNumber: 55, Initiator: "MyCodeBuildDemoUser", BuildStartTime: CodeBuildTime(time.Date(2017, 9, 1, 16, 12, 29, 0, time.UTC)), Source: CodeBuildSource{ @@ -189,6 +190,7 @@ func TestUnmarshalCodeBuildEvent(t *testing.T) { }, Timeout: DurationMinutes(60 * time.Minute), BuildComplete: true, + BuildNumber: 55, Initiator: "MyCodeBuildDemoUser", BuildStartTime: CodeBuildTime(time.Date(2017, 9, 1, 16, 12, 29, 0, time.UTC)), Source: CodeBuildSource{ diff --git a/events/testdata/codebuild-phase-change.json b/events/testdata/codebuild-phase-change.json index 6de723ec..23e09077 100644 --- a/events/testdata/codebuild-phase-change.json +++ b/events/testdata/codebuild-phase-change.json @@ -29,6 +29,7 @@ }, "timeout-in-minutes": 60.0, "build-complete": true, + "build-number": 55.0, "initiator": "MyCodeBuildDemoUser", "build-start-time": "Sep 1, 2017 4:12:29 PM", "source": { diff --git a/events/testdata/codebuild-state-change.json b/events/testdata/codebuild-state-change.json index 4be1cb75..9c9c4ed7 100644 --- a/events/testdata/codebuild-state-change.json +++ b/events/testdata/codebuild-state-change.json @@ -34,6 +34,7 @@ }, "timeout-in-minutes": 60.0, "build-complete": true, + "build-number": 55.0, "initiator": "MyCodeBuildDemoUser", "build-start-time": "Sep 1, 2017 4:12:29 PM", "source": {