|
5 | 5 | "context" |
6 | 6 | "fmt" |
7 | 7 | "log/slog" |
8 | | - "sort" |
9 | | - "strings" |
10 | 8 | "time" |
11 | 9 |
|
12 | 10 | "github.com/codeGROOVE-dev/slacker/pkg/home" |
@@ -224,146 +222,40 @@ func randomGreeting() string { |
224 | 222 | } |
225 | 223 |
|
226 | 224 | // Pick greeting based on time for variety |
227 | | - greetingIdx := (now.Hour()*60 + now.Minute()) % len(greetings) |
228 | | - return greetings[greetingIdx] |
| 225 | + i := (now.Hour()*60 + now.Minute()) % len(greetings) |
| 226 | + return greetings[i] |
229 | 227 | } |
230 | 228 |
|
231 | | -// formatPRLine formats a single PR as a line of text (goose-inspired format). |
232 | | -// Returns a string like: "■ repo#123 • title — action" or " repo#456 • title". |
233 | | -func formatPRLine(pr *home.PR) string { |
234 | | - // Extract repo name from "org/repo" format |
235 | | - parts := strings.SplitN(pr.Repository, "/", 2) |
236 | | - repo := pr.Repository |
237 | | - if len(parts) == 2 { |
238 | | - repo = parts[1] |
239 | | - } |
240 | | - |
241 | | - // Determine bullet character based on blocking status |
242 | | - var bullet string |
243 | | - switch { |
244 | | - case pr.IsBlocked || pr.NeedsReview: |
245 | | - // Critical: blocked on user |
246 | | - bullet = "■" |
247 | | - case pr.ActionKind != "": |
248 | | - // Non-critical: has action but not blocking |
249 | | - bullet = "•" |
250 | | - default: |
251 | | - // No action for user - use 2-space indent to align with bullets |
252 | | - bullet = " " |
253 | | - } |
254 | | - |
255 | | - // Build PR reference with link |
256 | | - ref := fmt.Sprintf("<%s|%s#%d>", pr.URL, repo, pr.Number) |
257 | | - |
258 | | - // Build line: bullet repo#123 • title |
259 | | - line := fmt.Sprintf("%s %s • %s", bullet, ref, pr.Title) |
260 | | - |
261 | | - // Add action kind if present (only show user's next action) |
262 | | - if pr.ActionKind != "" { |
263 | | - action := strings.ReplaceAll(pr.ActionKind, "_", " ") |
264 | | - line = fmt.Sprintf("%s — %s", line, action) |
265 | | - } |
266 | | - |
267 | | - return line |
268 | | -} |
269 | | - |
270 | | -// BuildReportBlocks creates Block Kit blocks for a daily report. |
271 | | -// Format inspired by goose - simple, minimal, action-focused. |
| 229 | +// BuildReportBlocks creates Block Kit blocks for a daily report with greeting. |
| 230 | +// Uses home.BuildPRSections for consistent formatting with the dashboard. |
272 | 231 | func BuildReportBlocks(incoming, outgoing []home.PR) []slack.Block { |
273 | | - // Sort PRs by most recently updated first (make copies to avoid modifying input) |
274 | | - incomingSorted := make([]home.PR, len(incoming)) |
275 | | - copy(incomingSorted, incoming) |
276 | | - sort.Slice(incomingSorted, func(i, j int) bool { |
277 | | - return incomingSorted[i].UpdatedAt.After(incomingSorted[j].UpdatedAt) |
278 | | - }) |
279 | | - |
280 | | - outgoingSorted := make([]home.PR, len(outgoing)) |
281 | | - copy(outgoingSorted, outgoing) |
282 | | - sort.Slice(outgoingSorted, func(i, j int) bool { |
283 | | - return outgoingSorted[i].UpdatedAt.After(outgoingSorted[j].UpdatedAt) |
284 | | - }) |
| 232 | + slog.Info("building report blocks", |
| 233 | + "incoming_count", len(incoming), |
| 234 | + "outgoing_count", len(outgoing)) |
| 235 | + |
| 236 | + // Log outgoing PRs to debug blocking detection |
| 237 | + for i := range outgoing { |
| 238 | + slog.Info("outgoing PR for report", |
| 239 | + "pr", outgoing[i].URL, |
| 240 | + "title", outgoing[i].Title, |
| 241 | + "is_blocked", outgoing[i].IsBlocked, |
| 242 | + "action_kind", outgoing[i].ActionKind, |
| 243 | + "action_reason", outgoing[i].ActionReason) |
| 244 | + } |
285 | 245 |
|
286 | 246 | var blocks []slack.Block |
287 | 247 |
|
288 | 248 | // Greeting |
289 | | - greeting := randomGreeting() |
290 | 249 | blocks = append(blocks, |
291 | 250 | slack.NewSectionBlock( |
292 | | - slack.NewTextBlockObject("mrkdwn", fmt.Sprintf("%s Here is your daily report:", greeting), false, false), |
| 251 | + slack.NewTextBlockObject("mrkdwn", fmt.Sprintf("%s Here is your daily report:", randomGreeting()), false, false), |
293 | 252 | nil, |
294 | 253 | nil, |
295 | 254 | ), |
296 | 255 | ) |
297 | 256 |
|
298 | | - // Incoming PRs section (only if there are incoming PRs) |
299 | | - if len(incomingSorted) > 0 { |
300 | | - // Count blocked PRs |
301 | | - n := 0 |
302 | | - for i := range incomingSorted { |
303 | | - if incomingSorted[i].IsBlocked || incomingSorted[i].NeedsReview { |
304 | | - n++ |
305 | | - } |
306 | | - } |
307 | | - |
308 | | - // Section header |
309 | | - header := "*Incoming*" |
310 | | - if n > 0 { |
311 | | - if n == 1 { |
312 | | - header = "*Incoming — 1 blocked on you*" |
313 | | - } else { |
314 | | - header = fmt.Sprintf("*Incoming — %d blocked on you*", n) |
315 | | - } |
316 | | - } |
317 | | - |
318 | | - // Build PR list |
319 | | - var prLines []string |
320 | | - for i := range incomingSorted { |
321 | | - prLines = append(prLines, formatPRLine(&incomingSorted[i])) |
322 | | - } |
323 | | - |
324 | | - blocks = append(blocks, |
325 | | - slack.NewSectionBlock( |
326 | | - slack.NewTextBlockObject("mrkdwn", header+"\n\n"+strings.Join(prLines, "\n"), false, false), |
327 | | - nil, |
328 | | - nil, |
329 | | - ), |
330 | | - ) |
331 | | - } |
332 | | - |
333 | | - // Outgoing PRs section (only if there are outgoing PRs) |
334 | | - if len(outgoingSorted) > 0 { |
335 | | - // Count blocked PRs |
336 | | - n := 0 |
337 | | - for i := range outgoingSorted { |
338 | | - if outgoingSorted[i].IsBlocked { |
339 | | - n++ |
340 | | - } |
341 | | - } |
342 | | - |
343 | | - // Section header |
344 | | - header := "*Outgoing*" |
345 | | - if n > 0 { |
346 | | - if n == 1 { |
347 | | - header = "*Outgoing — 1 blocked on you*" |
348 | | - } else { |
349 | | - header = fmt.Sprintf("*Outgoing — %d blocked on you*", n) |
350 | | - } |
351 | | - } |
352 | | - |
353 | | - // Build PR list |
354 | | - var prLines []string |
355 | | - for i := range outgoingSorted { |
356 | | - prLines = append(prLines, formatPRLine(&outgoingSorted[i])) |
357 | | - } |
358 | | - |
359 | | - blocks = append(blocks, |
360 | | - slack.NewSectionBlock( |
361 | | - slack.NewTextBlockObject("mrkdwn", header+"\n\n"+strings.Join(prLines, "\n"), false, false), |
362 | | - nil, |
363 | | - nil, |
364 | | - ), |
365 | | - ) |
366 | | - } |
| 257 | + // Add PR sections (uses home.BuildPRSections for unified formatting) |
| 258 | + blocks = append(blocks, home.BuildPRSections(incoming, outgoing)...) |
367 | 259 |
|
368 | 260 | return blocks |
369 | 261 | } |
0 commit comments