Skip to content

Commit

Permalink
[Fix] Correctly handle environments with names containing spaces (#2072)
Browse files Browse the repository at this point in the history
* Use url.PathEscape to encode environment names instead of url.QueryEscape

* Update all environment tests to include spaces in environment names

---------

Co-authored-by: Keegan Campbell <me@kfcampbell.com>
  • Loading branch information
nint8835 and kfcampbell committed Jan 5, 2024
1 parent 034789d commit d3bc5ba
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccGithubActionsEnvironmentSecretsDataSource(t *testing.T) {
resource "github_repository_environment" "test" {
repository = github_repository.test.name
environment = "environment/test"
environment = "environment / test"
}
resource "github_actions_environment_secret" "test" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestAccGithubActionsEnvironmentVariablesDataSource(t *testing.T) {
resource "github_repository_environment" "test" {
repository = github_repository.test.name
environment = "environment/test"
environment = "environment / test"
}
resource "github_actions_environment_variable" "variable" {
Expand Down
4 changes: 2 additions & 2 deletions github/resource_github_actions_environment_secret_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAccGithubActionsEnvironmentSecret(t *testing.T) {
resource "github_repository_environment" "test" {
repository = github_repository.test.name
environment = "environment/test"
environment = "environment / test"
}
resource "github_actions_environment_secret" "plaintext_secret" {
Expand Down Expand Up @@ -122,7 +122,7 @@ func TestAccGithubActionsEnvironmentSecret(t *testing.T) {
resource "github_repository_environment" "test" {
repository = github_repository.test.name
environment = "environment/test"
environment = "environment / test"
}
resource "github_actions_environment_secret" "plaintext_secret" {
Expand Down
2 changes: 1 addition & 1 deletion github/resource_github_actions_environment_variable.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func resourceGithubActionsEnvironmentVariableDelete(d *schema.ResourceData, meta
if err != nil {
return err
}
escapedEnvName := url.QueryEscape(envName)
escapedEnvName := url.PathEscape(envName)

repo, _, err := client.Repositories.Get(ctx, owner, repoName)
if err != nil {
Expand Down
6 changes: 3 additions & 3 deletions github/resource_github_actions_environment_variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) {
resource "github_repository_environment" "test" {
repository = github_repository.test.name
environment = "environment/test"
environment = "environment / test"
}
resource "github_actions_environment_variable" "variable" {
Expand Down Expand Up @@ -103,7 +103,7 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) {
resource "github_repository_environment" "test" {
repository = github_repository.test.name
environment = "environment/test"
environment = "environment / test"
}
resource "github_actions_environment_variable" "variable" {
Expand Down Expand Up @@ -143,7 +143,7 @@ func TestAccGithubActionsEnvironmentVariable(t *testing.T) {

t.Run("imports environment variables without error", func(t *testing.T) {
value := "my_variable_value"
envName := "environment/test"
envName := "environment / test"
varName := "test_variable"

config := fmt.Sprintf(`
Expand Down
8 changes: 4 additions & 4 deletions github/resource_github_repository_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func resourceGithubRepositoryEnvironmentCreate(d *schema.ResourceData, meta inte
owner := meta.(*Owner).name
repoName := d.Get("repository").(string)
envName := d.Get("environment").(string)
escapedEnvName := url.QueryEscape(envName)
escapedEnvName := url.PathEscape(envName)
updateData := createUpdateEnvironmentData(d, meta)

ctx := context.Background()
Expand All @@ -118,7 +118,7 @@ func resourceGithubRepositoryEnvironmentRead(d *schema.ResourceData, meta interf

owner := meta.(*Owner).name
repoName, envName, err := parseTwoPartID(d.Id(), "repository", "environment")
escapedEnvName := url.QueryEscape(envName)
escapedEnvName := url.PathEscape(envName)
if err != nil {
return err
}
Expand Down Expand Up @@ -193,7 +193,7 @@ func resourceGithubRepositoryEnvironmentUpdate(d *schema.ResourceData, meta inte
owner := meta.(*Owner).name
repoName := d.Get("repository").(string)
envName := d.Get("environment").(string)
escapedEnvName := url.QueryEscape(envName)
escapedEnvName := url.PathEscape(envName)
updateData := createUpdateEnvironmentData(d, meta)

ctx := context.Background()
Expand All @@ -213,7 +213,7 @@ func resourceGithubRepositoryEnvironmentDelete(d *schema.ResourceData, meta inte

owner := meta.(*Owner).name
repoName, envName, err := parseTwoPartID(d.Id(), "repository", "environment")
escapedEnvName := url.QueryEscape(envName)
escapedEnvName := url.PathEscape(envName)
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) {
resource "github_repository_environment" "test" {
repository = github_repository.test.name
environment = "environment/test"
environment = "environment / test"
wait_timer = 10000
reviewers {
users = [data.github_user.current.id]
Expand All @@ -52,7 +52,7 @@ func TestAccGithubRepositoryEnvironmentDeploymentPolicy(t *testing.T) {
),
resource.TestCheckResourceAttr(
"github_repository_environment_deployment_policy.test", "environment",
"environment/test",
"environment / test",
),
resource.TestCheckResourceAttr(
"github_repository_environment_deployment_policy.test", "branch_pattern",
Expand Down
4 changes: 2 additions & 2 deletions github/resource_github_repository_environment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) {
resource "github_repository_environment" "test" {
repository = github_repository.test.name
environment = "environment/test"
environment = "environment / test"
can_admins_bypass = false
wait_timer = 10000
reviewers {
Expand All @@ -42,7 +42,7 @@ func TestAccGithubRepositoryEnvironment(t *testing.T) {
`, randomID)

check := resource.ComposeAggregateTestCheckFunc(
resource.TestCheckResourceAttr("github_repository_environment.test", "environment", "environment/test"),
resource.TestCheckResourceAttr("github_repository_environment.test", "environment", "environment / test"),
resource.TestCheckResourceAttr("github_repository_environment.test", "can_admins_bypass", "false"),
resource.TestCheckResourceAttr("github_repository_environment.test", "wait_timer", "10000"),
)
Expand Down

0 comments on commit d3bc5ba

Please sign in to comment.