-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
Context
go version go1.24.0 darwin/arm64
Github Enterprise REST API
go-github versions v66 and v69 tested with
The issue
While pulling logs from the GH enterprise REST API via client.Enterprise.GetAuditLog(ctx, enterprise-name, &opts) it seems that there are some issues with actual API response vs the Github provided response schema for /enterprises/{enterprise}/audit-log
The docs state org should be a string
"org": {
"type": "string"
}However, while pulling audit logs from an enterprise account the org field may sometimes be an array of strings.
{
"@timestamp" : 1739983846824,
"_document_id" : "<redacted>",
"action" : "oauth_authorization.create",
"actor" : "<redacted>",
"actor_id" : 123456789,
"actor_ip" : "<redacted>",
"actor_is_bot" : false,
"actor_location" : {
"country_code" : "GB"
},
"business" : "<redacted>",
"business_id" : 123456,
"created_at" : 123456789,
"external_identity_username" : "<redacted>",
"operation_type" : "create",
"org" : [ "<redacted>", "<redacted>", "<redacted>" ],
"org_id" : [ 123456789, 123456789, 123456789 ],
"request_access_security_header" : null,
"token_scopes" : "gist,repo,workflow",
"user" : "<redacted>",
"user_agent" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36 Edg/133.0.0.0",
"user_id" : 123456789
}This is causing the following error when trying to unmarshal the response into a struct json: cannot unmarshal array into Go struct field entryAlias.org of type string
This error is present in v66 and v69, I've tested and was able to replicate the error with both versions.
Is this something this package may be able to flex? I wonder if the array can be turned into a string with strings.Join() when an array is detected during the type switch in this function https://github.com/google/go-github/blob/master/github/github.go#L1024-L1045
Specifically it is failing here
default:
decErr := json.NewDecoder(resp.Body).Decode(v)
if decErr == io.EOF {
decErr = nil // ignore EOF errors caused by empty response body
}
if decErr != nil {
err = decErr
}
}as it cannot decode the body properly.