Skip to content

Commit 62daa70

Browse files
authored
Refactor: Extract detection and validation methods from compiler.go (#3497)
1 parent 083c029 commit 62daa70

4 files changed

Lines changed: 64 additions & 48 deletions

File tree

pkg/workflow/compiler.go

Lines changed: 0 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1530,14 +1530,6 @@ func needsGitCommands(safeOutputs *SafeOutputsConfig) bool {
15301530
return safeOutputs.CreatePullRequests != nil || safeOutputs.PushToPullRequestBranch != nil
15311531
}
15321532

1533-
// detectTextOutputUsage checks if the markdown content uses ${{ needs.activation.outputs.text }}
1534-
func (c *Compiler) detectTextOutputUsage(markdownContent string) bool {
1535-
// Check for the specific GitHub Actions expression
1536-
hasUsage := strings.Contains(markdownContent, "${{ needs.activation.outputs.text }}")
1537-
log.Printf("Detected usage of activation.outputs.text: %v", hasUsage)
1538-
return hasUsage
1539-
}
1540-
15411533
// generateYAML generates the complete GitHub Actions YAML content
15421534

15431535
// isActivationJobNeeded determines if the activation job is required
@@ -1566,43 +1558,3 @@ func (c *Compiler) detectTextOutputUsage(markdownContent string) bool {
15661558
// generateCreateAwInfo generates a step that creates aw_info.json with agentic run metadata
15671559

15681560
// generateOutputCollectionStep generates a step that reads the output file and sets it as a GitHub Actions output
1569-
// parseBaseSafeOutputConfig parses common fields (max, min, github-token) from a config map
1570-
func (c *Compiler) parseBaseSafeOutputConfig(configMap map[string]any, config *BaseSafeOutputConfig) {
1571-
// Parse max
1572-
if max, exists := configMap["max"]; exists {
1573-
if maxInt, ok := parseIntValue(max); ok {
1574-
config.Max = maxInt
1575-
}
1576-
}
1577-
1578-
// Parse github-token
1579-
if githubToken, exists := configMap["github-token"]; exists {
1580-
if githubTokenStr, ok := githubToken.(string); ok {
1581-
config.GitHubToken = githubTokenStr
1582-
}
1583-
}
1584-
}
1585-
1586-
// computeAllowedDomainsForSanitization computes the allowed domains for sanitization
1587-
// based on the engine and network configuration, matching what's provided to the firewall
1588-
func (c *Compiler) computeAllowedDomainsForSanitization(data *WorkflowData) string {
1589-
// Determine which engine is being used
1590-
var engineID string
1591-
if data.EngineConfig != nil {
1592-
engineID = data.EngineConfig.ID
1593-
} else if data.AI != "" {
1594-
engineID = data.AI
1595-
}
1596-
1597-
// Compute domains based on engine type
1598-
// For Copilot with firewall support, use GetCopilotAllowedDomains which merges
1599-
// Copilot defaults with network permissions
1600-
// For other engines, use GetAllowedDomains which uses network permissions only
1601-
if engineID == "copilot" {
1602-
return GetCopilotAllowedDomains(data.NetworkPermissions)
1603-
}
1604-
1605-
// For Claude, Codex, and other engines, use network permissions
1606-
domains := GetAllowedDomains(data.NetworkPermissions)
1607-
return strings.Join(domains, ",")
1608-
}

pkg/workflow/detection.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package workflow
2+
3+
import (
4+
"strings"
5+
6+
"github.com/githubnext/gh-aw/pkg/logger"
7+
)
8+
9+
var detectionLog = logger.New("workflow:detection")
10+
11+
// detectTextOutputUsage checks if the markdown content uses ${{ needs.activation.outputs.text }}
12+
func (c *Compiler) detectTextOutputUsage(markdownContent string) bool {
13+
// Check for the specific GitHub Actions expression
14+
hasUsage := strings.Contains(markdownContent, "${{ needs.activation.outputs.text }}")
15+
detectionLog.Printf("Detected usage of activation.outputs.text: %v", hasUsage)
16+
return hasUsage
17+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package workflow
2+
3+
import (
4+
"strings"
5+
)
6+
7+
// computeAllowedDomainsForSanitization computes the allowed domains for sanitization
8+
// based on the engine and network configuration, matching what's provided to the firewall
9+
func (c *Compiler) computeAllowedDomainsForSanitization(data *WorkflowData) string {
10+
// Determine which engine is being used
11+
var engineID string
12+
if data.EngineConfig != nil {
13+
engineID = data.EngineConfig.ID
14+
} else if data.AI != "" {
15+
engineID = data.AI
16+
}
17+
18+
// Compute domains based on engine type
19+
// For Copilot with firewall support, use GetCopilotAllowedDomains which merges
20+
// Copilot defaults with network permissions
21+
// For other engines, use GetAllowedDomains which uses network permissions only
22+
if engineID == "copilot" {
23+
return GetCopilotAllowedDomains(data.NetworkPermissions)
24+
}
25+
26+
// For Claude, Codex, and other engines, use network permissions
27+
domains := GetAllowedDomains(data.NetworkPermissions)
28+
return strings.Join(domains, ",")
29+
}

pkg/workflow/safe_output_config.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package workflow
2+
3+
// parseBaseSafeOutputConfig parses common fields (max, github-token) from a config map
4+
func (c *Compiler) parseBaseSafeOutputConfig(configMap map[string]any, config *BaseSafeOutputConfig) {
5+
// Parse max
6+
if max, exists := configMap["max"]; exists {
7+
if maxInt, ok := parseIntValue(max); ok {
8+
config.Max = maxInt
9+
}
10+
}
11+
12+
// Parse github-token
13+
if githubToken, exists := configMap["github-token"]; exists {
14+
if githubTokenStr, ok := githubToken.(string); ok {
15+
config.GitHubToken = githubTokenStr
16+
}
17+
}
18+
}

0 commit comments

Comments
 (0)