Skip to content

Commit 24d30e2

Browse files
committed
Introduce CodeBuildNumber type
1 parent ce57ff4 commit 24d30e2

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

events/codebuild.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ type CodeBuildEventAdditionalInformation struct {
103103

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

106-
BuildNumber int `json:"build-number,omitempty"`
106+
BuildNumber CodeBuildNumber `json:"build-number,omitempty"`
107107

108108
Initiator string `json:"initiator"`
109109

@@ -197,3 +197,22 @@ func (t *CodeBuildTime) UnmarshalJSON(data []byte) error {
197197
*t = CodeBuildTime(ts)
198198
return nil
199199
}
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+
}

0 commit comments

Comments
 (0)