diff --git a/gitea-build-monitor-cache.json b/gitea-build-monitor-cache.json new file mode 100644 index 0000000..4ce216c --- /dev/null +++ b/gitea-build-monitor-cache.json @@ -0,0 +1,4 @@ +{ + "zaine/org_roam:job:11:state:failure": "2026-05-06T16:53:51.9326232+01:00", + "zaine/org_roam:job:12:state:success": "2026-05-06T16:53:52.0266348+01:00" +} diff --git a/gitea-build-monitor.log b/gitea-build-monitor.log index 310ad9a..de29187 100644 --- a/gitea-build-monitor.log +++ b/gitea-build-monitor.log @@ -1 +1,7 @@ 2026-05-06T16:46:05.3464989+01:00 [INFO] Validation mode completed: configuration and PowerShell runtime are valid. +2026-05-06T16:53:51.6056726+01:00 [INFO] Fetching recent Gitea Actions jobs for zaine/org_roam. +2026-05-06T16:53:51.9371399+01:00 [INFO] Analyzed job 11 for zaine/org_roam: severity=Critical, status=failure, duration=28s +2026-05-06T16:53:52.0270575+01:00 [INFO] Analyzed job 12 for zaine/org_roam: severity=Critical, status=success, duration=29s +2026-05-06T16:53:52.6590363+01:00 [INFO] Sent Discord notification with 2 embed(s). +2026-05-06T16:54:40.3683000+01:00 [INFO] Fetching recent Gitea Actions jobs for zaine/org_roam. +2026-05-06T16:54:40.4943993+01:00 [INFO] No new jobs found in the last 30 minute(s). diff --git a/gitea-build-monitor.ps1 b/gitea-build-monitor.ps1 index d7cb3ba..1ee79aa 100644 --- a/gitea-build-monitor.ps1 +++ b/gitea-build-monitor.ps1 @@ -386,7 +386,7 @@ function Get-LogSummary { } } - $matches = New-Object System.Collections.Generic.List[string] + $matchedLines = New-Object System.Collections.Generic.List[string] $hasErrors = $false $hasWarnings = $false @@ -414,13 +414,13 @@ function Get-LogSummary { } } - if (($isError -or $isWarning) -and $matches.Count -lt 8) { - $matches.Add($trimmed) + if (($isError -or $isWarning) -and $matchedLines.Count -lt 8) { + $matchedLines.Add($trimmed) } } - $summary = if ($matches.Count -gt 0) { - ($matches | Select-Object -First 8) -join "`n" + $summary = if ($matchedLines.Count -gt 0) { + ($matchedLines | Select-Object -First 8) -join "`n" } else { 'No matching warning or error lines found.' @@ -572,21 +572,28 @@ function Send-DiscordNotification { return } - $chunks = for ($i = 0; $i -lt $alerting.Count; $i += [int]$Config.MaxDiscordEmbeds) { - ,($alerting[$i..([Math]::Min($i + [int]$Config.MaxDiscordEmbeds - 1, $alerting.Count - 1))]) + $maxEmbeds = [int]$Config.MaxDiscordEmbeds + if ($maxEmbeds -lt 1) { + $maxEmbeds = 1 } - - foreach ($chunk in $chunks) { + for ($offset = 0; $offset -lt $alerting.Count; $offset += $maxEmbeds) { + $chunk = @($alerting | Select-Object -Skip $offset -First $maxEmbeds) $criticalCount = @($chunk | Where-Object { $_.Severity -eq 'Critical' }).Count $warningCount = @($chunk | Where-Object { $_.Severity -eq 'Warning' }).Count + $embeds = @($chunk | ForEach-Object { New-DiscordEmbed -Analysis $_ }) $payload = @{ username = 'Gitea Build Monitor' content = if ($criticalCount -gt 0) { "❌ Gitea build monitor found $criticalCount critical issue(s) and $warningCount warning(s)." } else { "⚠️ Gitea build monitor found $warningCount warning(s)." } - embeds = @($chunk | ForEach-Object { New-DiscordEmbed -Analysis $_ }) + embeds = $embeds } Invoke-DiscordWebhook -Payload $payload - Write-Log -Message "Sent Discord notification with $($chunk.Count) embed(s)." + if ($DryRun) { + Write-Log -Message "Prepared Discord notification with $($chunk.Count) embed(s) in dry-run mode." + } + else { + Write-Log -Message "Sent Discord notification with $($chunk.Count) embed(s)." + } } } @@ -673,7 +680,7 @@ function Start-BuildMonitor { } if ($analyses.Count -gt 0) { - Send-DiscordNotification -Analyses @($analyses) + Send-DiscordNotification -Analyses $analyses.ToArray() } else { Write-Log -Message "No new jobs found in the last $($Config.LookbackMinutes) minute(s)." @@ -689,5 +696,9 @@ try { } catch { Write-Log -Level 'ERROR' -Message "Build monitor failed: $($_.Exception.Message)" + Write-Log -Level 'ERROR' -Message "Exception type: $($_.Exception.GetType().FullName)" + if ($_.ScriptStackTrace) { + Write-Log -Level 'ERROR' -Message "Stack trace: $($_.ScriptStackTrace)" + } exit 1 }