Skip to content

Commit 2aec85a

Browse files
Thomas StrombergThomas Stromberg
authored andcommitted
fix DM config loading
1 parent df8c9a5 commit 2aec85a

File tree

4 files changed

+140
-1
lines changed

4 files changed

+140
-1
lines changed

pkg/config/config.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ func (m *Manager) LoadConfig(ctx context.Context, org string) error {
374374
"team_id": config.Global.TeamID,
375375
"email_domain": config.Global.EmailDomain,
376376
"daily_reminders": config.Global.DailyReminders,
377+
"reminder_dm_delay": config.Global.ReminderDMDelay,
377378
"total_channels": len(config.Channels),
378379
"muted_channels": muted,
379380
"wildcard_channels": wildcard,
@@ -575,20 +576,36 @@ func (m *Manager) ReminderDMDelay(org, channel string) int {
575576

576577
config, exists := m.configs[org]
577578
if !exists {
579+
slog.Debug("no config for org - using default delay",
580+
logFieldOrg, org,
581+
"default_delay_mins", defaultReminderDMDelayMinutes)
578582
return defaultReminderDMDelayMinutes
579583
}
580584

581585
// Check for channel-specific override
582586
if channelConfig, ok := config.Channels[channel]; ok {
583587
if channelConfig.ReminderDMDelay != nil {
588+
slog.Debug("using channel-specific reminder delay",
589+
logFieldOrg, org,
590+
"channel", channel,
591+
"delay_mins", *channelConfig.ReminderDMDelay)
584592
return *channelConfig.ReminderDMDelay
585593
}
586594
}
587595

588596
// Return global setting (or default if not set)
589597
if config.Global.ReminderDMDelay > 0 {
598+
slog.Debug("using global reminder delay",
599+
logFieldOrg, org,
600+
"channel", channel,
601+
"delay_mins", config.Global.ReminderDMDelay)
590602
return config.Global.ReminderDMDelay
591603
}
604+
slog.Debug("global delay is 0 or unset - using default",
605+
logFieldOrg, org,
606+
"channel", channel,
607+
"global_value", config.Global.ReminderDMDelay,
608+
"default_delay_mins", defaultReminderDMDelayMinutes)
592609
return defaultReminderDMDelayMinutes
593610
}
594611

pkg/config/config_test.go

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,6 +1071,112 @@ channels: [1, 2, 3]
10711071
}
10721072
}
10731073

1074+
func TestManager_LoadConfigCodeGROOVEProdConfig(t *testing.T) {
1075+
// Test with actual production config from codeGROOVE-dev/.codeGROOVE/slack.yaml
1076+
prodYAML := `global:
1077+
team_id: T09CJ7X7T7Y
1078+
email_domain: codegroove.dev
1079+
reminder_dm_delay: 1
1080+
1081+
channels:
1082+
goose:
1083+
mute: true
1084+
1085+
all-codegroove:
1086+
repos:
1087+
- "*"
1088+
1089+
social:
1090+
repos:
1091+
- goose
1092+
- sprinkler
1093+
- slacker
1094+
`
1095+
1096+
handler := func(w http.ResponseWriter, r *http.Request) {
1097+
content := base64.StdEncoding.EncodeToString([]byte(prodYAML))
1098+
encoding := "base64"
1099+
response := github.RepositoryContent{
1100+
Type: github.String("file"),
1101+
Content: &content,
1102+
Encoding: &encoding,
1103+
}
1104+
w.Header().Set("Content-Type", "application/json")
1105+
if err := json.NewEncoder(w).Encode(response); err != nil {
1106+
t.Errorf("failed to encode response: %v", err)
1107+
}
1108+
}
1109+
1110+
client, server := createTestGitHubClient(handler)
1111+
defer server.Close()
1112+
1113+
m := New()
1114+
m.SetGitHubClient("codeGROOVE-dev", client)
1115+
1116+
ctx := context.Background()
1117+
err := m.LoadConfig(ctx, "codeGROOVE-dev")
1118+
if err != nil {
1119+
t.Fatalf("unexpected error loading production config: %v", err)
1120+
}
1121+
1122+
// Verify config was loaded correctly
1123+
cfg, exists := m.Config("codeGROOVE-dev")
1124+
if !exists {
1125+
t.Fatal("expected config to exist after loading")
1126+
}
1127+
if cfg.Global.TeamID != "T09CJ7X7T7Y" {
1128+
t.Errorf("expected TeamID T09CJ7X7T7Y, got %q", cfg.Global.TeamID)
1129+
}
1130+
if cfg.Global.EmailDomain != "codegroove.dev" {
1131+
t.Errorf("expected email domain codegroove.dev, got %q", cfg.Global.EmailDomain)
1132+
}
1133+
if cfg.Global.ReminderDMDelay != 1 {
1134+
t.Errorf("expected reminder delay 1 minute, got %d", cfg.Global.ReminderDMDelay)
1135+
}
1136+
if len(cfg.Channels) != 3 {
1137+
t.Errorf("expected 3 channels, got %d", len(cfg.Channels))
1138+
}
1139+
1140+
// Verify goose channel is muted
1141+
gooseChannel, exists := cfg.Channels["goose"]
1142+
if !exists {
1143+
t.Error("expected goose channel to exist")
1144+
}
1145+
if !gooseChannel.Mute {
1146+
t.Error("expected goose channel to be muted")
1147+
}
1148+
1149+
// Verify all-codegroove has wildcard
1150+
allChannel, exists := cfg.Channels["all-codegroove"]
1151+
if !exists {
1152+
t.Error("expected all-codegroove channel to exist")
1153+
}
1154+
if len(allChannel.Repos) != 1 || allChannel.Repos[0] != "*" {
1155+
t.Errorf("expected all-codegroove to have wildcard repo, got %v", allChannel.Repos)
1156+
}
1157+
1158+
// Verify social channel repos
1159+
socialChannel, exists := cfg.Channels["social"]
1160+
if !exists {
1161+
t.Error("expected social channel to exist")
1162+
}
1163+
expectedRepos := []string{"goose", "sprinkler", "slacker"}
1164+
if len(socialChannel.Repos) != len(expectedRepos) {
1165+
t.Errorf("expected %d repos in social channel, got %d", len(expectedRepos), len(socialChannel.Repos))
1166+
}
1167+
for i, repo := range expectedRepos {
1168+
if i >= len(socialChannel.Repos) || socialChannel.Repos[i] != repo {
1169+
t.Errorf("expected repo %q at index %d in social channel, got %v", repo, i, socialChannel.Repos)
1170+
}
1171+
}
1172+
1173+
// Verify ReminderDMDelay returns correct value
1174+
delay := m.ReminderDMDelay("codeGROOVE-dev", "social")
1175+
if delay != 1 {
1176+
t.Errorf("expected ReminderDMDelay to return 1 minute, got %d", delay)
1177+
}
1178+
}
1179+
10741180
func TestManager_LoadConfigEmptyContent(t *testing.T) {
10751181
handler := func(w http.ResponseWriter, r *http.Request) {
10761182
// Return a response with nil Content

pkg/notify/notify.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,15 @@ func emojiFromWorkflowState(workflowState string, nextActions map[string]turn.Ac
145145
return ":test_tube:", "?st=tests_running"
146146

147147
case string(turn.StateTestedWaitingForAssignment):
148-
// Waiting for reviewers to be assigned
148+
// Check if tests are actually broken despite "TESTED" state
149+
// This can happen if new commits pushed after tests passed
150+
if len(nextActions) > 0 {
151+
action := PrimaryAction(nextActions)
152+
if action == string(turn.ActionFixTests) {
153+
return ":cockroach:", "?st=tests_broken"
154+
}
155+
}
156+
// Tests passed, waiting for reviewers to be assigned
149157
return ":shrug:", "?st=awaiting_assignment"
150158

151159
case string(turn.StateAssignedWaitingForReview):

pkg/notify/prefix_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ func TestPrefixForAnalysis(t *testing.T) {
6060
},
6161
expectedEmoji: ":shrug:",
6262
},
63+
{
64+
name: "TESTED_WAITING_FOR_ASSIGNMENT with broken tests shows :cockroach:",
65+
workflowState: string(turn.StateTestedWaitingForAssignment),
66+
nextAction: map[string]turn.Action{
67+
"author": {Kind: turn.ActionFixTests},
68+
},
69+
expectedEmoji: ":cockroach:",
70+
},
6371
{
6472
name: "ASSIGNED_WAITING_FOR_REVIEW shows :hourglass:",
6573
workflowState: string(turn.StateAssignedWaitingForReview),

0 commit comments

Comments
 (0)