MCPcopy Create free account
hub / github.com/google/go-github / addRepoSecret

Function addRepoSecret

example/codespaces/newreposecretwithxcrypto/main.go:128–144  ·  view source on GitHub ↗

addRepoSecret will add a secret to a GitHub repo for use in GitHub Codespaces. The secretName and secretValue determine the name of the secret added and its corresponding value. The actual transmission of the secret value to GitHub using the API requires that the secret value is encrypted using th

(ctx context.Context, client *github.Client, owner, repo, secretName, secretValue string)

Source from the content-addressed store, hash-verified

126// Finally, the github.EncryptedSecret is passed into the GitHub client.Codespaces.CreateOrUpdateRepoSecret method to
127// populate the secret in the GitHub repo.
128func addRepoSecret(ctx context.Context, client *github.Client, owner, repo, secretName, secretValue string) error {
129 publicKey, _, err := client.Codespaces.GetRepoPublicKey(ctx, owner, repo)
130 if err != nil {
131 return err
132 }
133
134 encryptedSecret, err := encryptSecretWithPublicKey(publicKey, secretName, secretValue)
135 if err != nil {
136 return err
137 }
138
139 if _, err := client.Codespaces.CreateOrUpdateRepoSecret(ctx, owner, repo, encryptedSecret); err != nil {
140 return fmt.Errorf("client.Codespaces.CreateOrUpdateRepoSecret returned error: %v", err)
141 }
142
143 return nil
144}
145
146func encryptSecretWithPublicKey(publicKey *github.PublicKey, secretName, secretValue string) (*github.EncryptedSecret, error) {
147 decodedPublicKey, err := base64.StdEncoding.DecodeString(publicKey.GetKey())

Callers 1

mainFunction · 0.70

Calls 3

GetRepoPublicKeyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…