From e0a153a0c6d0facea5c6002ea58eeaa53fdae89b Mon Sep 17 00:00:00 2001 From: Tidy Date: Sat, 25 Oct 2025 21:52:53 +0000 Subject: [PATCH] Fix code formatting issues - Fix indentation in push_to_pull_request_branch_test.go - Remove trailing whitespace in safe_output_helpers.go --- .../push_to_pull_request_branch_test.go | 102 +++++++++--------- pkg/workflow/safe_output_helpers.go | 4 +- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/pkg/workflow/push_to_pull_request_branch_test.go b/pkg/workflow/push_to_pull_request_branch_test.go index f27d4be7b45..cda2ac079b6 100644 --- a/pkg/workflow/push_to_pull_request_branch_test.go +++ b/pkg/workflow/push_to_pull_request_branch_test.go @@ -705,11 +705,11 @@ This workflow appends a suffix to commit titles. } func TestPushToPullRequestBranchWithWorkingDirectory(t *testing.T) { -// Create a temporary directory for the test -tmpDir := t.TempDir() + // Create a temporary directory for the test + tmpDir := t.TempDir() -// Create a test markdown file with push-to-pull-request-branch configuration -testMarkdown := `--- + // Create a test markdown file with push-to-pull-request-branch configuration + testMarkdown := `--- on: pull_request: types: [opened] @@ -722,60 +722,60 @@ safe-outputs: Test that the push-to-pull-request-branch job includes working-directory configuration. ` -// Write the test file -mdFile := filepath.Join(tmpDir, "test-push-working-dir.md") -if err := os.WriteFile(mdFile, []byte(testMarkdown), 0644); err != nil { -t.Fatalf("Failed to write test markdown file: %v", err) -} + // Write the test file + mdFile := filepath.Join(tmpDir, "test-push-working-dir.md") + if err := os.WriteFile(mdFile, []byte(testMarkdown), 0644); err != nil { + t.Fatalf("Failed to write test markdown file: %v", err) + } -// Create compiler and compile the workflow -compiler := NewCompiler(false, "", "test") + // Create compiler and compile the workflow + compiler := NewCompiler(false, "", "test") -if err := compiler.CompileWorkflow(mdFile); err != nil { -t.Fatalf("Failed to compile workflow: %v", err) -} + if err := compiler.CompileWorkflow(mdFile); err != nil { + t.Fatalf("Failed to compile workflow: %v", err) + } -// Read the generated .lock.yml file -lockFile := strings.TrimSuffix(mdFile, ".md") + ".lock.yml" -lockContent, err := os.ReadFile(lockFile) -if err != nil { -t.Fatalf("Failed to read lock file: %v", err) -} + // Read the generated .lock.yml file + lockFile := strings.TrimSuffix(mdFile, ".md") + ".lock.yml" + lockContent, err := os.ReadFile(lockFile) + if err != nil { + t.Fatalf("Failed to read lock file: %v", err) + } -lockContentStr := string(lockContent) + lockContentStr := string(lockContent) -// Verify that push_to_pull_request_branch job is generated -if !strings.Contains(lockContentStr, "push_to_pull_request_branch:") { -t.Errorf("Generated workflow should contain push_to_pull_request_branch job") -} + // Verify that push_to_pull_request_branch job is generated + if !strings.Contains(lockContentStr, "push_to_pull_request_branch:") { + t.Errorf("Generated workflow should contain push_to_pull_request_branch job") + } -// Verify that working-directory is set to ${{ github.workspace }} -if !strings.Contains(lockContentStr, "working-directory: ${{ github.workspace }}") { -t.Errorf("Generated workflow should contain working-directory: ${{ github.workspace }}\nGenerated workflow:\n%s", lockContentStr) -} + // Verify that working-directory is set to ${{ github.workspace }} + if !strings.Contains(lockContentStr, "working-directory: ${{ github.workspace }}") { + t.Errorf("Generated workflow should contain working-directory: ${{ github.workspace }}\nGenerated workflow:\n%s", lockContentStr) + } -// Verify that the working-directory comes after github-token in the with section -githubTokenIdx := strings.Index(lockContentStr, "github-token:") -workingDirIdx := strings.Index(lockContentStr, "working-directory:") -scriptIdx := strings.Index(lockContentStr, "script: |") + // Verify that the working-directory comes after github-token in the with section + githubTokenIdx := strings.Index(lockContentStr, "github-token:") + workingDirIdx := strings.Index(lockContentStr, "working-directory:") + scriptIdx := strings.Index(lockContentStr, "script: |") -if githubTokenIdx == -1 { -t.Error("github-token not found in generated workflow") -} -if workingDirIdx == -1 { -t.Error("working-directory not found in generated workflow") -} -if scriptIdx == -1 { -t.Error("script section not found in generated workflow") -} + if githubTokenIdx == -1 { + t.Error("github-token not found in generated workflow") + } + if workingDirIdx == -1 { + t.Error("working-directory not found in generated workflow") + } + if scriptIdx == -1 { + t.Error("script section not found in generated workflow") + } -// Verify order: github-token comes before working-directory, which comes before script -if githubTokenIdx != -1 && workingDirIdx != -1 && scriptIdx != -1 { -if githubTokenIdx > workingDirIdx { -t.Error("github-token should come before working-directory in the 'with' section") -} -if workingDirIdx > scriptIdx { -t.Error("working-directory should come before script in the 'with' section") -} -} + // Verify order: github-token comes before working-directory, which comes before script + if githubTokenIdx != -1 && workingDirIdx != -1 && scriptIdx != -1 { + if githubTokenIdx > workingDirIdx { + t.Error("github-token should come before working-directory in the 'with' section") + } + if workingDirIdx > scriptIdx { + t.Error("working-directory should come before script in the 'with' section") + } + } } diff --git a/pkg/workflow/safe_output_helpers.go b/pkg/workflow/safe_output_helpers.go index 7f0fedc72ff..891c23da8b0 100644 --- a/pkg/workflow/safe_output_helpers.go +++ b/pkg/workflow/safe_output_helpers.go @@ -75,12 +75,12 @@ func (c *Compiler) buildGitHubScriptStep(data *WorkflowData, config GitHubScript } else { c.addSafeOutputGitHubTokenForConfig(&steps, data, config.Token) } - + // Add working-directory if specified (required for scripts that execute git commands) if config.WorkingDirectory != "" { steps = append(steps, fmt.Sprintf(" working-directory: %s\n", config.WorkingDirectory)) } - + steps = append(steps, " script: |\n") // Add the formatted JavaScript script