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
3 changes: 3 additions & 0 deletions github/actions_hosted_runners.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ type HostedRunnerRequest struct {
// If any of these conditions are violated, an appropriate error message is returned.
// Otherwise, nil is returned, indicating the request is valid.
func validateCreateHostedRunnerRequest(request *HostedRunnerRequest) error {
if request == nil {
return errors.New("request is required for creating a hosted runner")
}
if request.Size == "" {
return errors.New("size is required for creating a hosted runner")
}
Expand Down
5 changes: 5 additions & 0 deletions github/actions_hosted_runners_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ func TestActionsService_CreateHostedRunner(t *testing.T) {
request *HostedRunnerRequest
expectedError string
}{
{
name: "Missing Request",
request: nil,
expectedError: "validation failed: request is required for creating a hosted runner",
},
{
name: "Missing Size",
request: &HostedRunnerRequest{
Expand Down
21 changes: 21 additions & 0 deletions github/actions_secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package github
import (
"context"
"encoding/json"
"errors"
"fmt"
"strconv"
)
Expand Down Expand Up @@ -246,6 +247,10 @@ func (s *ActionsService) putSecret(ctx context.Context, url string, eSecret *Enc
//
//meta:operation PUT /repos/{owner}/{repo}/actions/secrets/{secret_name}
func (s *ActionsService) CreateOrUpdateRepoSecret(ctx context.Context, owner, repo string, eSecret *EncryptedSecret) (*Response, error) {
if eSecret == nil {
return nil, errors.New("encrypted secret must be provided")
}

url := fmt.Sprintf("repos/%v/%v/actions/secrets/%v", owner, repo, eSecret.Name)
return s.putSecret(ctx, url, eSecret)
}
Expand All @@ -256,6 +261,10 @@ func (s *ActionsService) CreateOrUpdateRepoSecret(ctx context.Context, owner, re
//
//meta:operation PUT /orgs/{org}/actions/secrets/{secret_name}
func (s *ActionsService) CreateOrUpdateOrgSecret(ctx context.Context, org string, eSecret *EncryptedSecret) (*Response, error) {
if eSecret == nil {
return nil, errors.New("encrypted secret must be provided")
}

url := fmt.Sprintf("orgs/%v/actions/secrets/%v", org, eSecret.Name)
return s.putSecret(ctx, url, eSecret)
}
Expand All @@ -266,6 +275,10 @@ func (s *ActionsService) CreateOrUpdateOrgSecret(ctx context.Context, org string
//
//meta:operation PUT /repositories/{repository_id}/environments/{environment_name}/secrets/{secret_name}
func (s *ActionsService) CreateOrUpdateEnvSecret(ctx context.Context, repoID int, env string, eSecret *EncryptedSecret) (*Response, error) {
if eSecret == nil {
return nil, errors.New("encrypted secret must be provided")
}

url := fmt.Sprintf("repositories/%v/environments/%v/secrets/%v", repoID, env, eSecret.Name)
return s.putSecret(ctx, url, eSecret)
}
Expand Down Expand Up @@ -383,6 +396,10 @@ func (s *ActionsService) addSelectedRepoToSecret(ctx context.Context, url string
//
//meta:operation PUT /orgs/{org}/actions/secrets/{secret_name}/repositories/{repository_id}
func (s *ActionsService) AddSelectedRepoToOrgSecret(ctx context.Context, org, name string, repo *Repository) (*Response, error) {
if repo == nil {
return nil, errors.New("repository must be provided")
}

url := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories/%v", org, name, *repo.ID)
return s.addSelectedRepoToSecret(ctx, url)
}
Expand All @@ -402,6 +419,10 @@ func (s *ActionsService) removeSelectedRepoFromSecret(ctx context.Context, url s
//
//meta:operation DELETE /orgs/{org}/actions/secrets/{secret_name}/repositories/{repository_id}
func (s *ActionsService) RemoveSelectedRepoFromOrgSecret(ctx context.Context, org, name string, repo *Repository) (*Response, error) {
if repo == nil {
return nil, errors.New("repository must be provided")
}

url := fmt.Sprintf("orgs/%v/actions/secrets/%v/repositories/%v", org, name, *repo.ID)
return s.removeSelectedRepoFromSecret(ctx, url)
}
20 changes: 20 additions & 0 deletions github/actions_secrets_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,10 @@ func TestActionsService_CreateOrUpdateRepoSecret(t *testing.T) {
}

const methodName = "CreateOrUpdateRepoSecret"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.CreateOrUpdateRepoSecret(ctx, "o", "r", nil)
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.CreateOrUpdateRepoSecret(ctx, "\n", "\n", input)
return err
Expand Down Expand Up @@ -491,6 +495,10 @@ func TestActionsService_CreateOrUpdateOrgSecret(t *testing.T) {
}

const methodName = "CreateOrUpdateOrgSecret"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.CreateOrUpdateOrgSecret(ctx, "o", nil)
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.CreateOrUpdateOrgSecret(ctx, "\n", input)
return err
Expand Down Expand Up @@ -585,6 +593,10 @@ func TestActionsService_AddSelectedRepoToOrgSecret(t *testing.T) {
}

const methodName = "AddSelectedRepoToOrgSecret"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.AddSelectedRepoToOrgSecret(ctx, "o", "NAME", nil)
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.AddSelectedRepoToOrgSecret(ctx, "\n", "\n", repo)
return err
Expand All @@ -611,6 +623,10 @@ func TestActionsService_RemoveSelectedRepoFromOrgSecret(t *testing.T) {
}

const methodName = "RemoveSelectedRepoFromOrgSecret"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.RemoveSelectedRepoFromOrgSecret(ctx, "o", "NAME", nil)
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.RemoveSelectedRepoFromOrgSecret(ctx, "\n", "\n", repo)
return err
Expand Down Expand Up @@ -821,6 +837,10 @@ func TestActionsService_CreateOrUpdateEnvSecret(t *testing.T) {
}

const methodName = "CreateOrUpdateEnvSecret"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.CreateOrUpdateEnvSecret(ctx, 1, "e", nil)
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.CreateOrUpdateEnvSecret(ctx, 0.0, "\n", input)
return err
Expand Down
27 changes: 27 additions & 0 deletions github/actions_variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package github

import (
"context"
"errors"
"fmt"
)

Expand Down Expand Up @@ -186,6 +187,10 @@ func (s *ActionsService) patchVariable(ctx context.Context, url string, variable
//
//meta:operation PATCH /repos/{owner}/{repo}/actions/variables/{name}
func (s *ActionsService) UpdateRepoVariable(ctx context.Context, owner, repo string, variable *ActionsVariable) (*Response, error) {
if variable == nil {
return nil, errors.New("variable must be provided")
}

url := fmt.Sprintf("repos/%v/%v/actions/variables/%v", owner, repo, variable.Name)
return s.patchVariable(ctx, url, variable)
}
Expand All @@ -196,6 +201,10 @@ func (s *ActionsService) UpdateRepoVariable(ctx context.Context, owner, repo str
//
//meta:operation PATCH /orgs/{org}/actions/variables/{name}
func (s *ActionsService) UpdateOrgVariable(ctx context.Context, org string, variable *ActionsVariable) (*Response, error) {
if variable == nil {
return nil, errors.New("variable must be provided")
}

url := fmt.Sprintf("orgs/%v/actions/variables/%v", org, variable.Name)
return s.patchVariable(ctx, url, variable)
}
Expand All @@ -206,6 +215,10 @@ func (s *ActionsService) UpdateOrgVariable(ctx context.Context, org string, vari
//
//meta:operation PATCH /repos/{owner}/{repo}/environments/{environment_name}/variables/{name}
func (s *ActionsService) UpdateEnvVariable(ctx context.Context, owner, repo, env string, variable *ActionsVariable) (*Response, error) {
if variable == nil {
return nil, errors.New("variable must be provided")
}

url := fmt.Sprintf("repos/%v/%v/environments/%v/variables/%v", owner, repo, env, variable.Name)
return s.patchVariable(ctx, url, variable)
}
Expand Down Expand Up @@ -317,6 +330,13 @@ func (s *ActionsService) addSelectedRepoToVariable(ctx context.Context, url stri
//
//meta:operation PUT /orgs/{org}/actions/variables/{name}/repositories/{repository_id}
func (s *ActionsService) AddSelectedRepoToOrgVariable(ctx context.Context, org, name string, repo *Repository) (*Response, error) {
if repo == nil {
return nil, errors.New("repository must be provided")
}
if repo.ID == nil {
return nil, errors.New("id must be provided")
}

url := fmt.Sprintf("orgs/%v/actions/variables/%v/repositories/%v", org, name, *repo.ID)
return s.addSelectedRepoToVariable(ctx, url)
}
Expand All @@ -336,6 +356,13 @@ func (s *ActionsService) removeSelectedRepoFromVariable(ctx context.Context, url
//
//meta:operation DELETE /orgs/{org}/actions/variables/{name}/repositories/{repository_id}
func (s *ActionsService) RemoveSelectedRepoFromOrgVariable(ctx context.Context, org, name string, repo *Repository) (*Response, error) {
if repo == nil {
return nil, errors.New("repository must be provided")
}
if repo.ID == nil {
return nil, errors.New("id must be provided")
}

url := fmt.Sprintf("orgs/%v/actions/variables/%v/repositories/%v", org, name, *repo.ID)
return s.removeSelectedRepoFromVariable(ctx, url)
}
28 changes: 28 additions & 0 deletions github/actions_variables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ func TestActionsService_UpdateRepoVariable(t *testing.T) {
}

const methodName = "UpdateRepoVariable"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.UpdateRepoVariable(ctx, "o", "r", nil)
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.UpdateRepoVariable(ctx, "\n", "\n", input)
return err
Expand Down Expand Up @@ -374,6 +378,10 @@ func TestActionsService_UpdateOrgVariable(t *testing.T) {
}

const methodName = "UpdateOrgVariable"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.UpdateOrgVariable(ctx, "o", nil)
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.UpdateOrgVariable(ctx, "\n", input)
return err
Expand Down Expand Up @@ -468,6 +476,14 @@ func TestActionsService_AddSelectedRepoToOrgVariable(t *testing.T) {
}

const methodName = "AddSelectedRepoToOrgVariable"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.AddSelectedRepoToOrgVariable(ctx, "o", "NAME", nil)
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.AddSelectedRepoToOrgVariable(ctx, "o", "NAME", &Repository{ID: nil})
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.AddSelectedRepoToOrgVariable(ctx, "\n", "\n", repo)
return err
Expand All @@ -494,6 +510,14 @@ func TestActionsService_RemoveSelectedRepoFromOrgVariable(t *testing.T) {
}

const methodName = "RemoveSelectedRepoFromOrgVariable"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.RemoveSelectedRepoFromOrgVariable(ctx, "o", "NAME", nil)
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.RemoveSelectedRepoFromOrgVariable(ctx, "o", "NAME", &Repository{ID: nil})
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.RemoveSelectedRepoFromOrgVariable(ctx, "\n", "\n", repo)
return err
Expand Down Expand Up @@ -666,6 +690,10 @@ func TestActionsService_UpdateEnvVariable(t *testing.T) {
}

const methodName = "UpdateEnvVariable"
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.UpdateEnvVariable(ctx, "usr", "1", "e", nil)
return err
})
testBadOptions(t, methodName, func() (err error) {
_, err = client.Actions.UpdateEnvVariable(ctx, "usr", "1", "\n", input)
return err
Expand Down
8 changes: 8 additions & 0 deletions github/admin_orgs.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package github

import (
"context"
"errors"
"fmt"
)

Expand Down Expand Up @@ -65,6 +66,13 @@ type RenameOrgResponse struct {
//
//meta:operation PATCH /admin/organizations/{org}
func (s *AdminService) RenameOrg(ctx context.Context, org *Organization, newName string) (*RenameOrgResponse, *Response, error) {
if org == nil {
return nil, nil, errors.New("organization must be provided")
}
if org.Login == nil {
return nil, nil, errors.New("login must be provided")
}

return s.RenameOrgByName(ctx, *org.Login, newName)
}

Expand Down
9 changes: 9 additions & 0 deletions github/admin_orgs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ func TestAdminOrgs_Rename(t *testing.T) {
}

const methodName = "RenameOrg"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Admin.RenameOrg(ctx, nil, "the-new-octocats")
return err
})
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Admin.RenameOrg(ctx, &Organization{Login: nil}, "the-new-octocats")
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Admin.RenameOrg(ctx, input, "the-new-octocats")
if got != nil {
Expand Down
Loading
Loading