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
https://docs.github.com/en/enterprise-cloud@latest/rest/enterprise-admin/audit-log?apiVersion=2022-11-28#get-the-audit-log-for-an-enterprise
"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.
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-logThe docs state org should be a string
https://docs.github.com/en/enterprise-cloud@latest/rest/enterprise-admin/audit-log?apiVersion=2022-11-28#get-the-audit-log-for-an-enterprise
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 stringThis 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-L1045Specifically it is failing here
as it cannot decode the body properly.