Skip to content
Closed
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
4 changes: 2 additions & 2 deletions .custom-gcl.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: v2.2.2
plugins:
- module: "github.com/google/go-github/v75/tools/sliceofpointers"
path: ./tools/sliceofpointers
- module: "github.com/google/go-github/v75/tools/gogithub"
path: ./tools/gogithub
- module: "github.com/google/go-github/v75/tools/fmtpercentv"
path: ./tools/fmtpercentv
8 changes: 4 additions & 4 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ linters:
- paralleltest
- perfsprint
- revive
- sliceofpointers
- gogithub
- staticcheck
- tparallel
- unconvert
Expand Down Expand Up @@ -143,10 +143,10 @@ linters:
type: module
description: Reports usage of %d or %s in format strings.
original-url: github.com/google/go-github/v75/tools/fmtpercentv
sliceofpointers:
gogithub:
type: module
description: Reports usage of []*string and slices of structs without pointers.
original-url: github.com/google/go-github/v75/tools/sliceofpointers
description: Custom linter for this project.
original-url: github.com/google/go-github/v75/tools/gogithub
exclusions:
rules:
- linters:
Expand Down
28 changes: 14 additions & 14 deletions github/actions_hosted_runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,13 @@ type HostedRunnerImage struct {

// HostedRunnerRequest specifies body parameters to Hosted Runner configuration.
type HostedRunnerRequest struct {
Name string `json:"name,omitempty"`
Image HostedRunnerImage `json:"image,omitempty"`
RunnerGroupID int64 `json:"runner_group_id,omitempty"`
Size string `json:"size,omitempty"`
MaximumRunners int64 `json:"maximum_runners,omitempty"`
EnableStaticIP bool `json:"enable_static_ip,omitempty"`
ImageVersion string `json:"image_version,omitempty"`
Name *string `json:"name,omitempty"`
Image *HostedRunnerImage `json:"image,omitempty"`
RunnerGroupID *int64 `json:"runner_group_id,omitempty"`
Size *string `json:"size,omitempty"`
MaximumRunners *int64 `json:"maximum_runners,omitempty"`
EnableStaticIP *bool `json:"enable_static_ip,omitempty"`
ImageVersion *string `json:"image_version,omitempty"`
}

// validateCreateHostedRunnerRequest validates the provided HostedRunnerRequest to ensure
Expand All @@ -110,19 +110,19 @@ func validateCreateHostedRunnerRequest(request *HostedRunnerRequest) error {
if request == nil {
return errors.New("request is required for creating a hosted runner")
}
if request.Size == "" {
if request.Size == nil {
return errors.New("size is required for creating a hosted runner")
}
if request.Image == (HostedRunnerImage{}) {
if request.Image == nil {
return errors.New("image is required for creating a hosted runner")
}
if request.Name == "" {
if request.Name == nil {
return errors.New("name is required for creating a hosted runner")
}
if request.RunnerGroupID == 0 {
if request.RunnerGroupID == nil {
return errors.New("runner group ID is required for creating a hosted runner")
}
if request.ImageVersion != "" {
if request.ImageVersion != nil {
return errors.New("imageVersion should not be set directly; use the Image struct to specify image details")
}
return nil
Expand Down Expand Up @@ -323,10 +323,10 @@ func (s *ActionsService) GetHostedRunner(ctx context.Context, org string, runner
// If any of these conditions are violated, an appropriate error message is returned.
// Otherwise, nil is returned, indicating the request is valid for an update.
func validateUpdateHostedRunnerRequest(request *HostedRunnerRequest) error {
if request.Size != "" {
if request.Size != nil {
return errors.New("size cannot be updated, API does not support updating size")
}
if request.Image != (HostedRunnerImage{}) {
if request.Image != nil {
return errors.New("image struct should not be set directly; use the ImageVersion to specify version details")
}
return nil
Expand Down
84 changes: 42 additions & 42 deletions github/actions_hosted_runners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,16 +193,16 @@ func TestActionsService_CreateHostedRunner(t *testing.T) {
ctx := t.Context()

validReq := &HostedRunnerRequest{
Name: "My Hosted runner",
Image: HostedRunnerImage{
Name: Ptr("My Hosted runner"),
Image: &HostedRunnerImage{
ID: "ubuntu-latest",
Source: "github",
Version: "latest",
},
RunnerGroupID: 1,
Size: "4-core",
MaximumRunners: 50,
EnableStaticIP: false,
RunnerGroupID: Ptr(int64(1)),
Size: Ptr("4-core"),
MaximumRunners: Ptr(int64(50)),
EnableStaticIP: Ptr(false),
}
hostedRunner, _, err := client.Actions.CreateHostedRunner(ctx, "o", validReq)
if err != nil {
Expand Down Expand Up @@ -256,65 +256,65 @@ func TestActionsService_CreateHostedRunner(t *testing.T) {
{
name: "Missing Size",
request: &HostedRunnerRequest{
Name: "My Hosted runner",
Image: HostedRunnerImage{
Name: Ptr("My Hosted runner"),
Image: &HostedRunnerImage{
ID: "ubuntu-latest",
Source: "github",
Version: "latest",
},
RunnerGroupID: 1,
RunnerGroupID: Ptr(int64(1)),
},
expectedError: "validation failed: size is required for creating a hosted runner",
},
{
name: "Missing Image",
request: &HostedRunnerRequest{
Name: "My Hosted runner",
RunnerGroupID: 1,
Size: "4-core",
Name: Ptr("My Hosted runner"),
RunnerGroupID: Ptr(int64(1)),
Size: Ptr("4-core"),
},
expectedError: "validation failed: image is required for creating a hosted runner",
},
{
name: "Missing Name",
request: &HostedRunnerRequest{
Image: HostedRunnerImage{
Image: &HostedRunnerImage{
ID: "ubuntu-latest",
Source: "github",
Version: "latest",
},
RunnerGroupID: 1,
Size: "4-core",
RunnerGroupID: Ptr(int64(1)),
Size: Ptr("4-core"),
},
expectedError: "validation failed: name is required for creating a hosted runner",
},
{
name: "Missing RunnerGroupID",
request: &HostedRunnerRequest{
Name: "My Hosted runner",
Image: HostedRunnerImage{
Name: Ptr("My Hosted runner"),
Image: &HostedRunnerImage{
ID: "ubuntu-latest",
Source: "github",
Version: "latest",
},
Size: "4-core",
Size: Ptr("4-core"),
},
expectedError: "validation failed: runner group ID is required for creating a hosted runner",
},
{
name: "ImageVersion Set Instead of Image Struct",
request: &HostedRunnerRequest{
Name: "My Hosted runner",
Image: HostedRunnerImage{
Name: Ptr("My Hosted runner"),
Image: &HostedRunnerImage{
ID: "ubuntu-latest",
Source: "github",
Version: "latest",
},
RunnerGroupID: 1,
Size: "4-core",
ImageVersion: "1.0.0",
MaximumRunners: 50,
EnableStaticIP: false,
RunnerGroupID: Ptr(int64(1)),
Size: Ptr("4-core"),
ImageVersion: Ptr("1.0.0"),
MaximumRunners: Ptr(int64(50)),
EnableStaticIP: Ptr(false),
},
expectedError: "validation failed: imageVersion should not be set directly; use the Image struct to specify image details",
},
Expand Down Expand Up @@ -732,11 +732,11 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) {

ctx := t.Context()
validReq := HostedRunnerRequest{
Name: "My larger runner",
RunnerGroupID: 1,
MaximumRunners: 50,
EnableStaticIP: false,
ImageVersion: "1.0.0",
Name: Ptr("My larger runner"),
RunnerGroupID: Ptr(int64(1)),
MaximumRunners: Ptr(int64(50)),
EnableStaticIP: Ptr(false),
ImageVersion: Ptr("1.0.0"),
}
hostedRunner, _, err := client.Actions.UpdateHostedRunner(ctx, "o", 23, validReq)
if err != nil {
Expand Down Expand Up @@ -784,24 +784,24 @@ func TestActionsService_UpdateHostedRunner(t *testing.T) {
{
name: "Size Set in Update Request",
request: HostedRunnerRequest{
Name: "My larger runner",
RunnerGroupID: 1,
MaximumRunners: 50,
EnableStaticIP: false,
ImageVersion: "1.0.0",
Size: "4-core", // Should cause validation error
Name: Ptr("My larger runner"),
RunnerGroupID: Ptr(int64(1)),
MaximumRunners: Ptr(int64(50)),
EnableStaticIP: Ptr(false),
ImageVersion: Ptr("1.0.0"),
Size: Ptr("4-core"), // Should cause validation error
},
expectedError: "validation failed: size cannot be updated, API does not support updating size",
},
{
name: "Image Set in Update Request",
request: HostedRunnerRequest{
Name: "My larger runner",
RunnerGroupID: 1,
MaximumRunners: 50,
EnableStaticIP: false,
ImageVersion: "1.0.0",
Image: HostedRunnerImage{ // Should cause validation error
Name: Ptr("My larger runner"),
RunnerGroupID: Ptr(int64(1)),
MaximumRunners: Ptr(int64(50)),
EnableStaticIP: Ptr(false),
ImageVersion: Ptr("1.0.0"),
Image: &HostedRunnerImage{ // Should cause validation error
ID: "ubuntu-latest",
Source: "github",
Version: "latest",
Expand Down
14 changes: 7 additions & 7 deletions github/actions_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ type Secret struct {
Name string `json:"name"`
CreatedAt Timestamp `json:"created_at"`
UpdatedAt Timestamp `json:"updated_at"`
Visibility string `json:"visibility,omitempty"`
SelectedRepositoriesURL string `json:"selected_repositories_url,omitempty"`
Visibility *string `json:"visibility,omitempty"`
SelectedRepositoriesURL *string `json:"selected_repositories_url,omitempty"`
}

// Secrets represents one item from the ListSecrets response.
Expand Down Expand Up @@ -225,11 +225,11 @@ type SelectedRepoIDs []int64
// LibSodium (see documentation here: https://libsodium.gitbook.io/doc/bindings_for_other_languages)
// using the public key retrieved using the GetPublicKey method.
type EncryptedSecret struct {
Name string `json:"-"`
KeyID string `json:"key_id"`
EncryptedValue string `json:"encrypted_value"`
Visibility string `json:"visibility,omitempty"`
SelectedRepositoryIDs SelectedRepoIDs `json:"selected_repository_ids,omitempty"`
Name string `json:"-"`
KeyID string `json:"key_id"`
EncryptedValue string `json:"encrypted_value"`
Visibility *string `json:"visibility,omitempty"`
SelectedRepositoryIDs *SelectedRepoIDs `json:"selected_repository_ids,omitempty"`
}

func (s *ActionsService) putSecret(ctx context.Context, url string, eSecret *EncryptedSecret) (*Response, error) {
Expand Down
26 changes: 13 additions & 13 deletions github/actions_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -404,9 +404,9 @@ func TestActionsService_ListOrgSecrets(t *testing.T) {
want := &Secrets{
TotalCount: 3,
Secrets: []*Secret{
{Name: "GIST_ID", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: "private"},
{Name: "DEPLOY_TOKEN", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: "all"},
{Name: "GH_TOKEN", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: "selected", SelectedRepositoriesURL: "https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories"},
{Name: "GIST_ID", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: Ptr("private")},
{Name: "DEPLOY_TOKEN", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: Ptr("all")},
{Name: "GH_TOKEN", CreatedAt: Timestamp{time.Date(2019, time.August, 10, 14, 59, 22, 0, time.UTC)}, UpdatedAt: Timestamp{time.Date(2020, time.January, 10, 14, 59, 22, 0, time.UTC)}, Visibility: Ptr("selected"), SelectedRepositoriesURL: Ptr("https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories")},
},
}
if !cmp.Equal(secrets, want) {
Expand Down Expand Up @@ -447,8 +447,8 @@ func TestActionsService_GetOrgSecret(t *testing.T) {
Name: "NAME",
CreatedAt: Timestamp{time.Date(2019, time.January, 2, 15, 4, 5, 0, time.UTC)},
UpdatedAt: Timestamp{time.Date(2020, time.January, 2, 15, 4, 5, 0, time.UTC)},
Visibility: "selected",
SelectedRepositoriesURL: "https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories",
Visibility: Ptr("selected"),
SelectedRepositoriesURL: Ptr("https://api.github.com/orgs/octo-org/actions/secrets/SUPER_SECRET/repositories"),
}
if !cmp.Equal(secret, want) {
t.Errorf("Actions.GetOrgSecret returned %+v, want %+v", secret, want)
Expand Down Expand Up @@ -484,8 +484,8 @@ func TestActionsService_CreateOrUpdateOrgSecret(t *testing.T) {
Name: "NAME",
EncryptedValue: "QIv=",
KeyID: "1234",
Visibility: "selected",
SelectedRepositoryIDs: SelectedRepoIDs{1296269, 1269280},
Visibility: Ptr("selected"),
SelectedRepositoryIDs: &SelectedRepoIDs{1296269, 1269280},
}
ctx := t.Context()
_, err := client.Actions.CreateOrUpdateOrgSecret(ctx, "o", input)
Expand Down Expand Up @@ -900,8 +900,8 @@ func TestSecret_Marshal(t *testing.T) {
Name: "n",
CreatedAt: Timestamp{referenceTime},
UpdatedAt: Timestamp{referenceTime},
Visibility: "v",
SelectedRepositoriesURL: "s",
Visibility: Ptr("v"),
SelectedRepositoriesURL: Ptr("s"),
}

want := `{
Expand All @@ -926,8 +926,8 @@ func TestSecrets_Marshal(t *testing.T) {
Name: "n",
CreatedAt: Timestamp{referenceTime},
UpdatedAt: Timestamp{referenceTime},
Visibility: "v",
SelectedRepositoriesURL: "s",
Visibility: Ptr("v"),
SelectedRepositoriesURL: Ptr("s"),
},
},
}
Expand Down Expand Up @@ -956,8 +956,8 @@ func TestEncryptedSecret_Marshal(t *testing.T) {
Name: "n",
KeyID: "kid",
EncryptedValue: "e",
Visibility: "v",
SelectedRepositoryIDs: []int64{1},
Visibility: Ptr("v"),
SelectedRepositoryIDs: &SelectedRepoIDs{1},
}

want := `{
Expand Down
6 changes: 3 additions & 3 deletions github/activity_notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (s *ActivityService) ListRepositoryNotifications(ctx context.Context, owner
}

type markReadOptions struct {
LastReadAt Timestamp `json:"last_read_at,omitempty"`
LastReadAt *Timestamp `json:"last_read_at,omitempty"`
}

// MarkNotificationsRead marks all notifications up to lastRead as read.
Expand All @@ -111,7 +111,7 @@ type markReadOptions struct {
//meta:operation PUT /notifications
func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead Timestamp) (*Response, error) {
opts := &markReadOptions{
LastReadAt: lastRead,
LastReadAt: &lastRead,
}
req, err := s.client.NewRequest("PUT", "notifications", opts)
if err != nil {
Expand All @@ -129,7 +129,7 @@ func (s *ActivityService) MarkNotificationsRead(ctx context.Context, lastRead Ti
//meta:operation PUT /repos/{owner}/{repo}/notifications
func (s *ActivityService) MarkRepositoryNotificationsRead(ctx context.Context, owner, repo string, lastRead Timestamp) (*Response, error) {
opts := &markReadOptions{
LastReadAt: lastRead,
LastReadAt: &lastRead,
}
u := fmt.Sprintf("repos/%v/%v/notifications", owner, repo)
req, err := s.client.NewRequest("PUT", u, opts)
Expand Down
2 changes: 1 addition & 1 deletion github/activity_notifications_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ func TestMarkReadOptions_Marshal(t *testing.T) {
testJSONMarshal(t, &markReadOptions{}, "{}")

u := &markReadOptions{
LastReadAt: Timestamp{referenceTime},
LastReadAt: &Timestamp{referenceTime},
}

want := `{
Expand Down
Loading
Loading