Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commite95d8ee

Browse files
stephenotaloraSamMorrowDrums
authored andcommitted
addresses float64 to in64 feedback from copilot
1 parent1d6499d commite95d8ee

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+
funcvalidateAndConvertToInt64(valueany) (int64,error) {
866+
switchv:=value.(type) {
867+
casefloat64:
868+
// Validate that the float64 can be safely converted to int64
869+
intVal:=int64(v)
870+
iffloat64(intVal)!=v {
871+
return0,fmt.Errorf("value must be a valid integer (got %v)",v)
872+
}
873+
returnintVal,nil
874+
caseint64:
875+
returnv,nil
876+
caseint:
877+
returnint64(v),nil
878+
default:
879+
return0,fmt.Errorf("value must be a number (got %T)",v)
880+
}
881+
}
882+
883+
// buildUpdateProjectItem constructs UpdateProjectItemOptions from the input map.
864884
funcbuildUpdateProjectItem(inputmap[string]any) (*github.UpdateProjectItemOptions,error) {
865885
ifinput==nil {
866886
returnnil,fmt.Errorf("updated_field must be an object")
@@ -871,18 +891,19 @@ func buildUpdateProjectItem(input map[string]any) (*github.UpdateProjectItemOpti
871891
returnnil,fmt.Errorf("updated_field.id is required")
872892
}
873893

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

879899
valueField,ok:=input["value"]
880900
if!ok {
881901
returnnil,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)

[8]ページ先頭

©2009-2025 Movatter.jp