Skip to content

Commit 2bdd94c

Browse files
addresses float64 to in64 feedback from copilot
1 parent d5933b0 commit 2bdd94c

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

pkg/github/projects.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -861,6 +861,26 @@ func toNewProjectType(projType string) string {
861861
}
862862
}
863863

864+
// validateAndConvertToInt64 ensures the value is a number and converts it to int64.
865+
func validateAndConvertToInt64(value any) (int64, error) {
866+
switch v := value.(type) {
867+
case float64:
868+
// Validate that the float64 can be safely converted to int64
869+
intVal := int64(v)
870+
if float64(intVal) != v {
871+
return 0, fmt.Errorf("value must be a valid integer (got %v)", v)
872+
}
873+
return intVal, nil
874+
case int64:
875+
return v, nil
876+
case int:
877+
return int64(v), nil
878+
default:
879+
return 0, fmt.Errorf("value must be a number (got %T)", v)
880+
}
881+
}
882+
883+
// buildUpdateProjectItem constructs UpdateProjectItemOptions from the input map.
864884
func buildUpdateProjectItem(input map[string]any) (*github.UpdateProjectItemOptions, error) {
865885
if input == nil {
866886
return nil, fmt.Errorf("updated_field must be an object")
@@ -871,18 +891,19 @@ func buildUpdateProjectItem(input map[string]any) (*github.UpdateProjectItemOpti
871891
return nil, fmt.Errorf("updated_field.id is required")
872892
}
873893

874-
idFieldAsFloat64, ok := idField.(float64) // JSON numbers are float64
875-
if !ok {
876-
return nil, fmt.Errorf("updated_field.id must be a number")
894+
fieldID, err := validateAndConvertToInt64(idField)
895+
if err != nil {
896+
return nil, fmt.Errorf("updated_field.id: %w", err)
877897
}
878898

879899
valueField, ok := input["value"]
880900
if !ok {
881901
return nil, fmt.Errorf("updated_field.value is required")
882902
}
903+
883904
payload := &github.UpdateProjectItemOptions{
884905
Fields: []*github.UpdateProjectV2Field{{
885-
ID: int64(idFieldAsFloat64),
906+
ID: fieldID,
886907
Value: valueField,
887908
}},
888909
}

0 commit comments

Comments
 (0)