Skip to content

Add missing BuildNumber to CodeBuildEventAdditionalInformation #417

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 7 commits into from
Mar 25, 2022
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
21 changes: 21 additions & 0 deletions events/codebuild.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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
}
2 changes: 2 additions & 0 deletions events/codebuild_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions events/testdata/codebuild-phase-change.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
1 change: 1 addition & 0 deletions events/testdata/codebuild-state-change.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down