Hello,
I believe there was a regression in #2794.
Documentation of organization secrets expects a string but we're now sending integers.
This in turn causes a failure when calling the API.
I think the issue lies in that "setting" repository ids is done via integers on the API (REF), while creating or updating a secrets expects repository ids to be a string (REF). So they cannot have the same underlying type in the client as long as the API expected different types
Sample Go Code
package main
import (
"context""encoding/base64""fmt""log""os""github.com/google/go-github/v53/github""golang.org/x/crypto/nacl/box""golang.org/x/oauth2"
)
funcmain() {
ctx:=context.Background()
iferr:=run(ctx); err!=nil {
log.Fatal(err)
}
}
funcrun(ctx context.Context) error {
ts:=oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_API_TOKEN")},
)
tc:=oauth2.NewClient(ctx, ts)
client:=github.NewClient(tc)
org:=os.Getenv("GITHUB_OWNER")
pubKey, _, err:=client.Dependabot.GetOrgPublicKey(ctx, org)
iferr!=nil {
returnerr
}
enc, err:=encryptPlaintext("SECRET", *pubKey.Key)
iferr!=nil {
returnerr
}
_, err=client.Dependabot.CreateOrUpdateOrgSecret(ctx, org, &github.DependabotEncryptedSecret{
Name: "EXAMPLE",
KeyID: *pubKey.KeyID,
EncryptedValue: base64.StdEncoding.EncodeToString(enc),
SelectedRepositoryIDs: []int64{123456789},
Visibility: "selected",
})
returnerr
}
funcencryptPlaintext(plaintext, publicKeyB64string) ([]byte, error) {
publicKeyBytes, err:=base64.StdEncoding.DecodeString(publicKeyB64)
iferr!=nil {
returnnil, err
}
varpublicKeyBytes32 [32]bytecopiedLen:=copy(publicKeyBytes32[:], publicKeyBytes)
ifcopiedLen==0 {
returnnil, fmt.Errorf("could not convert publicKey to bytes")
}
plaintextBytes:= []byte(plaintext)
varencryptedBytes []bytecipherText, err:=box.SealAnonymous(encryptedBytes, plaintextBytes, &publicKeyBytes32, nil)
iferr!=nil {
returnnil, err
}
returncipherText, nil
} Sample Output
2023/06/22 09:52:26 PUT https://api.github.com/orgs/<my-org>/dependabot/secrets/EXAMPLE: 422 Invalid request.
Invalid property /selected_repository_ids/0: `123456789` is not of type`string`. []
exit status 1
Hello,
I believe there was a regression in #2794.
Documentation of organization secrets expects a string but we're now sending integers.
This in turn causes a failure when calling the API.
I think the issue lies in that "setting" repository ids is done via integers on the API (REF), while creating or updating a secrets expects repository ids to be a string (REF). So they cannot have the same underlying type in the client as long as the API expected different types
Sample Go Code
Sample Output