This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user