Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- Add `extra-install-packages` input to install additional apt packages required by custom dangerfiles
- Custom dangerfiles receive full Danger API access (`fail`, `warn`, `message`, `markdown`, `danger`)
- Enables repositories to extend Danger checks without overwriting shared workflow comments
- Sentry-CLI integration test action - Add `InvokeSentryResult::Events()` method to extract events from envelopes ([#137](https://github.com/getsentry/github-workflows/pull/137))

## 3.1.0

Expand Down
30 changes: 30 additions & 0 deletions sentry-cli/integration-test/action.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,36 @@ class InvokeSentryResult
return $envelopes
}

# Events are extracted from envelopes, each event body as single item.
# Note: Unlike Envelopes(), this method discards potential duplicates based on event_id.
[string[]]Events()
{
$ids = @()
$events = @()
foreach ($envelope in $this.Envelopes())
{
$lines = @($envelope -split "\\n")
try
{
$header = $lines[0].Trim() | ConvertFrom-Json
if ($header.event_id -and $ids -notcontains $header.event_id)
{
$body = $lines | Select-Object -Skip 1 | Where-Object {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes single event in an envelope - is that OK?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. According to the docs, "event" items may occur at most once per envelope: https://develop.sentry.dev/sdk/data-model/envelope-items/#event

try { ($_ | ConvertFrom-Json).event_id -eq $header.event_id }
catch { $false }
} | Select-Object -First 1
if ($body)
{
$ids += $header.event_id
$events += $body
}
}
}
catch { }
Copy link
Contributor

@vaind vaind Jan 5, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to swallow exceptions here? If it's because of the access to event_id, you could use for example $header | Select-Object -ExpandProperty event_id -ErrorAction SilentlyContinue or $header.PsObject.Properties['event_id']?.Value

}
return $events
}

[bool]HasErrors()
{
return $this.ServerStdErr.Length -gt 0
Expand Down
21 changes: 21 additions & 0 deletions sentry-cli/integration-test/tests/action.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,25 @@ helloworld
$result.Envelopes().Length | Should -Be 1
$result.Envelopes()[0].Length | Should -Be 357
}

It "discards duplicate events" {
$result = Invoke-SentryServer {
param([string]$url)
Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @'
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:53:38.929Z"}
{"type":"event","length":47,"content_type":"application/json"}
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"}
'@
Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @'
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:53:41.505Z"}
{"type":"event","length":47,"content_type":"application/json"}
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"}
'@
}

Should -ActualValue $result.HasErrors() -BeFalse
$result.Envelopes().Length | Should -Be 2
$result.Events().Length | Should -Be 1
$result.Events()[0].Length | Should -Be 47
}
}
Loading