Skip to content

Commit 1ebff2c

Browse files
authored
Add missing BuildNumber to CodeBuildEventAdditionalInformation (#417)
* Add missing BuildNumber to CodeBuildEventAdditionalInformation * Update test data for build-number * Introduce CodeBuildNumber type * Update test data Co-authored-by: Guimin YAO <[email protected]>
1 parent 3afc312 commit 1ebff2c

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

events/codebuild.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,8 @@ type CodeBuildEventAdditionalInformation struct {
103103

104104
BuildComplete bool `json:"build-complete"`
105105

106+
BuildNumber CodeBuildNumber `json:"build-number,omitempty"`
107+
106108
Initiator string `json:"initiator"`
107109

108110
BuildStartTime CodeBuildTime `json:"build-start-time"`
@@ -195,3 +197,22 @@ func (t *CodeBuildTime) UnmarshalJSON(data []byte) error {
195197
*t = CodeBuildTime(ts)
196198
return nil
197199
}
200+
201+
// CodeBuildNumber represents the number of the build
202+
type CodeBuildNumber int32
203+
204+
// MarshalJSON converts a given CodeBuildNumber to json
205+
func (n CodeBuildNumber) MarshalJSON() ([]byte, error) {
206+
return json.Marshal(float32(n))
207+
}
208+
209+
// UnmarshalJSON converts a given json to a CodeBuildNumber
210+
func (n *CodeBuildNumber) UnmarshalJSON(data []byte) error {
211+
var f float32
212+
if err := json.Unmarshal(data, &f); err != nil {
213+
return err
214+
}
215+
216+
*n = CodeBuildNumber(int32(f))
217+
return nil
218+
}

events/codebuild_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func TestUnmarshalCodeBuildEvent(t *testing.T) {
5252
},
5353
Timeout: DurationMinutes(60 * time.Minute),
5454
BuildComplete: true,
55+
BuildNumber: 55,
5556
Initiator: "MyCodeBuildDemoUser",
5657
BuildStartTime: CodeBuildTime(time.Date(2017, 9, 1, 16, 12, 29, 0, time.UTC)),
5758
Source: CodeBuildSource{
@@ -189,6 +190,7 @@ func TestUnmarshalCodeBuildEvent(t *testing.T) {
189190
},
190191
Timeout: DurationMinutes(60 * time.Minute),
191192
BuildComplete: true,
193+
BuildNumber: 55,
192194
Initiator: "MyCodeBuildDemoUser",
193195
BuildStartTime: CodeBuildTime(time.Date(2017, 9, 1, 16, 12, 29, 0, time.UTC)),
194196
Source: CodeBuildSource{

events/testdata/codebuild-phase-change.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
},
3030
"timeout-in-minutes": 60.0,
3131
"build-complete": true,
32+
"build-number": 55.0,
3233
"initiator": "MyCodeBuildDemoUser",
3334
"build-start-time": "Sep 1, 2017 4:12:29 PM",
3435
"source": {

events/testdata/codebuild-state-change.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
},
3535
"timeout-in-minutes": 60.0,
3636
"build-complete": true,
37+
"build-number": 55.0,
3738
"initiator": "MyCodeBuildDemoUser",
3839
"build-start-time": "Sep 1, 2017 4:12:29 PM",
3940
"source": {

0 commit comments

Comments
 (0)