Skip to content

Commit f3fafd7

Browse files
Add debug logging to 5 workflow files (#3481)
1 parent e551f1d commit f3fafd7

5 files changed

Lines changed: 62 additions & 3 deletions

File tree

pkg/workflow/copilot_participant_steps.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ package workflow
22

33
import (
44
"fmt"
5+
6+
"github.com/githubnext/gh-aw/pkg/logger"
57
)
68

9+
var copilotParticipantLog = logger.New("workflow:copilot_participant_steps")
10+
711
// CopilotParticipantConfig holds configuration for generating Copilot participant steps
812
type CopilotParticipantConfig struct {
913
// Participants is the list of users/bots to assign/review
@@ -25,7 +29,10 @@ type CopilotParticipantConfig struct {
2529
// buildCopilotParticipantSteps generates steps for adding Copilot participants (assignees or reviewers)
2630
// This function extracts the common logic between issue assignees and PR reviewers
2731
func buildCopilotParticipantSteps(config CopilotParticipantConfig) []string {
32+
copilotParticipantLog.Printf("Building Copilot participant steps: type=%s, count=%d", config.ParticipantType, len(config.Participants))
33+
2834
if len(config.Participants) == 0 {
35+
copilotParticipantLog.Print("No participants to add, returning empty steps")
2936
return nil
3037
}
3138

@@ -50,15 +57,19 @@ func buildCopilotParticipantSteps(config CopilotParticipantConfig) []string {
5057
// Use Copilot token preference if adding copilot as participant, otherwise use regular token
5158
var effectiveToken string
5259
if hasCopilotParticipant {
60+
copilotParticipantLog.Print("Using Copilot token preference")
5361
effectiveToken = getEffectiveCopilotGitHubToken(config.CustomToken, getEffectiveCopilotGitHubToken(config.SafeOutputsToken, config.WorkflowToken))
5462
} else {
63+
copilotParticipantLog.Print("Using regular GitHub token")
5564
effectiveToken = getEffectiveGitHubToken(config.CustomToken, getEffectiveGitHubToken(config.SafeOutputsToken, config.WorkflowToken))
5665
}
5766

5867
// Generate participant-specific steps
5968
if config.ParticipantType == "assignee" {
69+
copilotParticipantLog.Printf("Generating issue assignee steps for %d participants", len(config.Participants))
6070
steps = append(steps, buildIssueAssigneeSteps(config, effectiveToken)...)
6171
} else if config.ParticipantType == "reviewer" {
72+
copilotParticipantLog.Printf("Generating PR reviewer steps for %d participants", len(config.Participants))
6273
steps = append(steps, buildPRReviewerSteps(config, effectiveToken)...)
6374
}
6475

pkg/workflow/manual_approval.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,36 @@ package workflow
22

33
import (
44
"fmt"
5+
6+
"github.com/githubnext/gh-aw/pkg/logger"
57
)
68

9+
var manualApprovalLog = logger.New("workflow:manual_approval")
10+
711
// extractManualApprovalFromOn extracts the manual-approval value from the on: section
812
func (c *Compiler) extractManualApprovalFromOn(frontmatter map[string]any) (string, error) {
913
onSection, exists := frontmatter["on"]
1014
if !exists {
15+
manualApprovalLog.Print("No on: section found in frontmatter")
1116
return "", nil
1217
}
1318

1419
// Handle different formats of the on: section
1520
switch on := onSection.(type) {
1621
case string:
1722
// Simple string format like "on: push" - no manual-approval possible
23+
manualApprovalLog.Printf("on: section is simple string format: %s", on)
1824
return "", nil
1925
case map[string]any:
2026
// Complex object format - look for manual-approval
2127
if manualApproval, exists := on["manual-approval"]; exists {
2228
if str, ok := manualApproval.(string); ok {
29+
manualApprovalLog.Printf("Found manual-approval configuration: %s", str)
2330
return str, nil
2431
}
2532
return "", fmt.Errorf("manual-approval value must be a string")
2633
}
34+
manualApprovalLog.Print("on: section is object format but no manual-approval field found")
2735
return "", nil
2836
default:
2937
return "", fmt.Errorf("invalid on: section format")
@@ -32,12 +40,21 @@ func (c *Compiler) extractManualApprovalFromOn(frontmatter map[string]any) (stri
3240

3341
// processManualApprovalConfiguration extracts manual-approval configuration from frontmatter
3442
func (c *Compiler) processManualApprovalConfiguration(frontmatter map[string]any, workflowData *WorkflowData) error {
43+
manualApprovalLog.Print("Processing manual-approval configuration")
44+
3545
// Extract manual-approval from the on: section
3646
manualApproval, err := c.extractManualApprovalFromOn(frontmatter)
3747
if err != nil {
48+
manualApprovalLog.Printf("Failed to extract manual-approval: %v", err)
3849
return err
3950
}
4051
workflowData.ManualApproval = manualApproval
4152

53+
if manualApproval != "" {
54+
manualApprovalLog.Printf("Manual approval configured for workflow: %s", manualApproval)
55+
} else {
56+
manualApprovalLog.Print("No manual approval configured for workflow")
57+
}
58+
4259
return nil
4360
}

pkg/workflow/secret_masking.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import (
77

88
// extractSecretMaskingConfig extracts secret-masking configuration from frontmatter
99
func (c *Compiler) extractSecretMaskingConfig(frontmatter map[string]any) *SecretMaskingConfig {
10+
secretMaskingLog.Print("Extracting secret-masking configuration from frontmatter")
11+
1012
if secretMasking, exists := frontmatter["secret-masking"]; exists {
1113
if secretMaskingMap, ok := secretMasking.(map[string]any); ok {
1214
config := &SecretMaskingConfig{}
@@ -21,18 +23,21 @@ func (c *Compiler) extractSecretMaskingConfig(frontmatter map[string]any) *Secre
2123
}
2224
}
2325
config.Steps = stepsConfig
26+
secretMaskingLog.Printf("Extracted %d secret-masking steps from frontmatter", len(stepsConfig))
2427
}
2528
}
2629

2730
// Return nil if no steps were found
2831
if len(config.Steps) == 0 {
32+
secretMaskingLog.Print("No secret-masking steps found in frontmatter")
2933
return nil
3034
}
3135

3236
return config
3337
}
3438
}
3539

40+
secretMaskingLog.Print("No secret-masking configuration found in frontmatter")
3641
return nil
3742
}
3843

pkg/workflow/time_delta.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@ import (
66
"strconv"
77
"strings"
88
"time"
9+
10+
"github.com/githubnext/gh-aw/pkg/logger"
911
)
1012

13+
var timeDeltaLog = logger.New("workflow:time_delta")
14+
1115
// Pre-compiled regexes for time parsing (performance optimization)
1216
var (
1317
timeDeltaPattern = regexp.MustCompile(`(\d+)(mo|w|d|h|m)`)
@@ -53,12 +57,15 @@ func parseTimeDeltaForStopAfter(deltaStr string) (*TimeDelta, error) {
5357

5458
// parseTimeDeltaWithMinutes parses a relative time delta string with optional minute support
5559
func parseTimeDeltaWithMinutes(deltaStr string, allowMinutes bool) (*TimeDelta, error) {
60+
timeDeltaLog.Printf("Parsing time delta: input=%s, allowMinutes=%v", deltaStr, allowMinutes)
61+
5662
if deltaStr == "" {
5763
return nil, fmt.Errorf("empty time delta")
5864
}
5965

6066
// Must start with '+'
6167
if !strings.HasPrefix(deltaStr, "+") {
68+
timeDeltaLog.Printf("Time delta validation failed: missing '+' prefix")
6269
return nil, fmt.Errorf("time delta must start with '+', got: %s", deltaStr)
6370
}
6471

@@ -148,6 +155,7 @@ func parseTimeDeltaWithMinutes(deltaStr string, allowMinutes bool) (*TimeDelta,
148155
return nil, fmt.Errorf("time delta too large: %d minutes exceeds maximum of 525600 minutes", delta.Minutes)
149156
}
150157

158+
timeDeltaLog.Printf("Parsed time delta successfully: %s", delta.String())
151159
return delta, nil
152160
}
153161

@@ -182,6 +190,8 @@ func isRelativeStopTime(stopTime string) bool {
182190

183191
// parseAbsoluteDateTime parses various date-time formats and returns a standardized timestamp
184192
func parseAbsoluteDateTime(dateTimeStr string) (string, error) {
193+
timeDeltaLog.Printf("Parsing absolute date-time: %s", dateTimeStr)
194+
185195
// Try multiple date-time formats in order of preference
186196
formats := []string{
187197
// Standard formats
@@ -236,7 +246,9 @@ func parseAbsoluteDateTime(dateTimeStr string) (string, error) {
236246
for _, format := range formats {
237247
if parsed, err := time.Parse(format, dateTimeStr); err == nil {
238248
// Successfully parsed, convert to UTC and return in standard format
239-
return parsed.UTC().Format("2006-01-02 15:04:05"), nil
249+
result := parsed.UTC().Format("2006-01-02 15:04:05")
250+
timeDeltaLog.Printf("Successfully parsed date-time using format, result: %s", result)
251+
return result, nil
240252
}
241253
}
242254

@@ -247,7 +259,9 @@ func parseAbsoluteDateTime(dateTimeStr string) (string, error) {
247259
for _, format := range formats {
248260
if parsed, err := time.Parse(format, normalizedStr); err == nil {
249261
// Successfully parsed, convert to UTC and return in standard format
250-
return parsed.UTC().Format("2006-01-02 15:04:05"), nil
262+
result := parsed.UTC().Format("2006-01-02 15:04:05")
263+
timeDeltaLog.Printf("Successfully parsed date-time using ordinal normalization, result: %s", result)
264+
return result, nil
251265
}
252266
}
253267

pkg/workflow/xml_comments.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
11
package workflow
22

3-
import "strings"
3+
import (
4+
"strings"
5+
6+
"github.com/githubnext/gh-aw/pkg/logger"
7+
)
8+
9+
var xmlCommentsLog = logger.New("workflow:xml_comments")
410

511
// removeXMLComments removes XML comments (<!-- -->) from markdown content
612
// while preserving comments that appear within code blocks
713
func removeXMLComments(content string) string {
14+
xmlCommentsLog.Printf("Removing XML comments from content: %d lines", len(strings.Split(content, "\n")))
15+
816
// Track if we're inside a code block to avoid removing comments in code
917
lines := strings.Split(content, "\n")
1018
var result []string
1119
inCodeBlock := false
1220
var openMarker string
1321
inXMLComment := false
22+
removedComments := 0
1423

1524
for _, line := range lines {
1625
// If we're in a code block, preserve the line as-is (ignore XML comment processing)
@@ -33,6 +42,7 @@ func removeXMLComments(content string) string {
3342
// If we're in an XML comment, skip this line entirely (including code block markers)
3443
if wasInComment && isInComment {
3544
// In the middle of a comment, skip the line completely
45+
removedComments++
3646
continue
3747
}
3848

@@ -43,6 +53,7 @@ func removeXMLComments(content string) string {
4353
// Opening a code block
4454
openMarker, _ = extractCodeBlockMarker(trimmedLine)
4555
inCodeBlock = true
56+
xmlCommentsLog.Printf("Detected code block opening with marker: %s", openMarker)
4657
result = append(result, processedLine)
4758
continue
4859
}
@@ -65,6 +76,7 @@ func removeXMLComments(content string) string {
6576
}
6677
}
6778

79+
xmlCommentsLog.Printf("XML comment removal completed: removed %d comment lines, output %d lines", removedComments, len(result))
6880
return strings.Join(result, "\n")
6981
}
7082

0 commit comments

Comments
 (0)