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
1 change: 1 addition & 0 deletions .github/workflows/breaking-change-checker.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .github/workflows/duplicate-code-detector.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 2 additions & 13 deletions .github/workflows/security-alert-burndown.lock.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions pkg/workflow/compiler_safe_outputs_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ func (c *Compiler) addAllSafeOutputConfigEnvVars(steps *[]string, data *Workflow
stagedFlagAdded = true
compilerSafeOutputsEnvLog.Print("Added staged flag for create-issue")
}
// Check if copilot is in assignees - if so, we'll output issues for assign_to_agent job
if hasCopilotAssignee(cfg.Assignees) {
*steps = append(*steps, " GH_AW_ASSIGN_COPILOT: \"true\"\n")
compilerSafeOutputsEnvLog.Print("Copilot assignment requested - will output issues_to_assign_copilot")
}
}

// Add Comment - all config now in handler config JSON
Expand Down
132 changes: 132 additions & 0 deletions pkg/workflow/compiler_safe_outputs_env_copilot_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@
//go:build !integration

package workflow

import (
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

// TestCopilotAssignmentEnvVarIsSet verifies that GH_AW_ASSIGN_COPILOT is set
// when copilot is in the assignees list
func TestCopilotAssignmentEnvVarIsSet(t *testing.T) {
compiler := NewCompiler()

data := &WorkflowData{
Name: "Test",
SafeOutputs: &SafeOutputsConfig{
CreateIssues: &CreateIssuesConfig{
BaseSafeOutputConfig: BaseSafeOutputConfig{Max: 1},
Assignees: []string{"copilot"},
},
},
}

var steps []string
compiler.addAllSafeOutputConfigEnvVars(&steps, data)

// Join steps to search for the env var
stepsStr := strings.Join(steps, "")

assert.Contains(t, stepsStr, "GH_AW_ASSIGN_COPILOT", "Expected GH_AW_ASSIGN_COPILOT to be set when copilot is in assignees")
assert.Contains(t, stepsStr, `GH_AW_ASSIGN_COPILOT: "true"`, "Expected GH_AW_ASSIGN_COPILOT to be set to 'true'")
}

// TestCopilotAssignmentEnvVarNotSetWithoutCopilot verifies that GH_AW_ASSIGN_COPILOT
// is not set when copilot is not in the assignees list
func TestCopilotAssignmentEnvVarNotSetWithoutCopilot(t *testing.T) {
compiler := NewCompiler()

data := &WorkflowData{
Name: "Test",
SafeOutputs: &SafeOutputsConfig{
CreateIssues: &CreateIssuesConfig{
BaseSafeOutputConfig: BaseSafeOutputConfig{Max: 1},
Assignees: []string{"user1"},
},
},
}

var steps []string
compiler.addAllSafeOutputConfigEnvVars(&steps, data)

// Join steps to search for the env var
stepsStr := strings.Join(steps, "")

assert.NotContains(t, stepsStr, "GH_AW_ASSIGN_COPILOT", "Expected GH_AW_ASSIGN_COPILOT not to be set when copilot is not in assignees")
}

// TestCopilotAssignmentEnvVarWithMixedAssignees verifies that GH_AW_ASSIGN_COPILOT is set
// when copilot is in the assignees list along with other users
func TestCopilotAssignmentEnvVarWithMixedAssignees(t *testing.T) {
compiler := NewCompiler()

data := &WorkflowData{
Name: "Test",
SafeOutputs: &SafeOutputsConfig{
CreateIssues: &CreateIssuesConfig{
BaseSafeOutputConfig: BaseSafeOutputConfig{Max: 1},
Assignees: []string{"user1", "copilot", "user2"},
},
},
}

var steps []string
compiler.addAllSafeOutputConfigEnvVars(&steps, data)

// Join steps to search for the env var
stepsStr := strings.Join(steps, "")

assert.Contains(t, stepsStr, "GH_AW_ASSIGN_COPILOT", "Expected GH_AW_ASSIGN_COPILOT to be set when copilot is among multiple assignees")
assert.Contains(t, stepsStr, `GH_AW_ASSIGN_COPILOT: "true"`, "Expected GH_AW_ASSIGN_COPILOT to be set to 'true'")
}

// TestCopilotAssignmentEnvVarWithNilAssignees verifies that GH_AW_ASSIGN_COPILOT
// is not set when assignees field is nil
func TestCopilotAssignmentEnvVarWithNilAssignees(t *testing.T) {
compiler := NewCompiler()

data := &WorkflowData{
Name: "Test",
SafeOutputs: &SafeOutputsConfig{
CreateIssues: &CreateIssuesConfig{
BaseSafeOutputConfig: BaseSafeOutputConfig{Max: 1},
Assignees: nil,
},
},
}

var steps []string
compiler.addAllSafeOutputConfigEnvVars(&steps, data)

// Join steps to search for the env var
stepsStr := strings.Join(steps, "")

assert.NotContains(t, stepsStr, "GH_AW_ASSIGN_COPILOT", "Expected GH_AW_ASSIGN_COPILOT not to be set when assignees is nil")
}

// TestCopilotAssignmentEnvVarWithEmptyAssignees verifies that GH_AW_ASSIGN_COPILOT
// is not set when assignees array is empty
func TestCopilotAssignmentEnvVarWithEmptyAssignees(t *testing.T) {
compiler := NewCompiler()

data := &WorkflowData{
Name: "Test",
SafeOutputs: &SafeOutputsConfig{
CreateIssues: &CreateIssuesConfig{
BaseSafeOutputConfig: BaseSafeOutputConfig{Max: 1},
Assignees: []string{},
},
},
}

var steps []string
compiler.addAllSafeOutputConfigEnvVars(&steps, data)

// Join steps to search for the env var
stepsStr := strings.Join(steps, "")

assert.NotContains(t, stepsStr, "GH_AW_ASSIGN_COPILOT", "Expected GH_AW_ASSIGN_COPILOT not to be set when assignees is empty")
}
Loading