Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
50 changes: 25 additions & 25 deletions src/classes/public/Workflows/GitHubWorkflowRun.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -103,34 +103,34 @@

GitHubWorkflowRun([PSCustomObject] $Object) {
# From GitHubNode
$this.ID = $_.id
$this.NodeID = $_.node_id
$this.ID = $Object.id
$this.NodeID = $Object.node_id

# From GitHubWorkflowRun
$this.Name = $_.name
$this.Name = $Object.name
$this.Owner = [GitHubOwner]::new($Object.repository.owner)
$this.Repository = [GitHubRepository]::new($Object.repository)
$this.CheckSuiteID = $_.check_suite_id
$this.CheckSuiteNodeID = $_.check_suite_node_id
$this.HeadBranch = $_.head_branch
$this.HeadSha = $_.head_sha
$this.Path = $_.path
$this.RunNumber = $_.run_number
$this.RunAttempt = $_.run_attempt
$this.ReferencedWorkflows = $_.referenced_workflows
$this.Event = $_.event
$this.Status = $_.status
$this.Conclusion = $_.conclusion
$this.WorkflowID = $_.workflow_id
$this.Url = $_.html_url
$this.PullRequests = $_.pull_requests
$this.CreatedAt = $_.created_at
$this.UpdatedAt = $_.updated_at
$this.StartedAt = $_.run_started_at
$this.Actor = [GitHubUser]::new($_.actor)
$this.TriggeringActor = [GitHubUser]::new($_.triggering_actor)
$this.HeadCommit = $_.head_commit
$this.HeadRepository = [GitHubRepository]::new($_.head_repository)
$this.DisplayTitle = $_.display_title
$this.CheckSuiteID = $Object.check_suite_id
$this.CheckSuiteNodeID = $Object.check_suite_node_id
$this.HeadBranch = $Object.head_branch
$this.HeadSha = $Object.head_sha
$this.Path = $Object.path
$this.RunNumber = $Object.run_number
$this.RunAttempt = $Object.run_attempt
$this.ReferencedWorkflows = $Object.referenced_workflows
$this.Event = $Object.event
$this.Status = $Object.status
$this.Conclusion = $Object.conclusion
$this.WorkflowID = $Object.workflow_id
$this.Url = $Object.html_url
$this.PullRequests = $Object.pull_requests
$this.CreatedAt = $Object.created_at
$this.UpdatedAt = $Object.updated_at
$this.StartedAt = $Object.run_started_at
$this.Actor = [GitHubUser]::new($Object.actor)
$this.TriggeringActor = [GitHubUser]::new($Object.triggering_actor)
$this.HeadCommit = $Object.head_commit
$this.HeadRepository = [GitHubRepository]::new($Object.head_repository)
Comment thread
MariusStorhaug marked this conversation as resolved.
$this.DisplayTitle = $Object.display_title
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,12 @@
}

if ($PSCmdlet.ShouldProcess("$Owner/$Repository/$ID", 'Delete workflow run')) {
Write-Verbose "Deleted workflow run [$ID] in [$Owner/$Repository]"
$null = Invoke-GitHubAPI @apiParams
try {
$null = Invoke-GitHubAPI @apiParams
Write-Verbose "Deleted workflow run [$ID] in [$Owner/$Repository]"
} catch {
Write-Error "Failed to delete workflow run [$ID] in [$Owner/$Repository]: $_"
Comment thread
MariusStorhaug marked this conversation as resolved.
}
Comment thread
MariusStorhaug marked this conversation as resolved.
}
}

Expand Down
82 changes: 82 additions & 0 deletions tests/Actions.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,88 @@ BeforeAll {
Describe 'Actions' {
$authCases = . "$PSScriptRoot/Data/AuthCases.ps1"

Context 'GitHubWorkflowRun' {
It 'Constructor should populate properties from $Object parameter, not from $_' {
# Build a minimal mock object matching the GitHub REST API workflow-run response shape.
# The constructor is called outside ForEach-Object so $_ is $null.
# If the constructor incorrectly references $_ instead of $Object, scalar properties will be empty.
$mockOwner = [PSCustomObject]@{
id = 1
node_id = 'MDQ6VXNlcjE='
login = 'octocat'
avatar_url = 'https://github.com/images/error/octocat_happy.gif'
html_url = 'https://github.com/octocat'
type = 'User'
}

$mockRepo = [PSCustomObject]@{
id = 100
node_id = 'MDEwOlJlcG9zaXRvcnkxMDA='
name = 'hello-world'
full_name = 'octocat/hello-world'
owner = $mockOwner
html_url = 'https://github.com/octocat/hello-world'
}

$mockUser = [PSCustomObject]@{
id = 1
node_id = 'MDQ6VXNlcjE='
login = 'octocat'
avatar_url = 'https://github.com/images/error/octocat_happy.gif'
html_url = 'https://github.com/octocat'
type = 'User'
}

$mockRun = [PSCustomObject]@{
id = 42
node_id = 'MDExOldvcmtmbG93UnVuNDI='
name = 'CI Build'
check_suite_id = 99
check_suite_node_id = 'MDEwOkNoZWNrU3VpdGU5OQ=='
head_branch = 'main'
head_sha = '009b8a3a9ccbb128af87f9b1c0f4c62e8a304f6d'
path = '.github/workflows/ci.yml'
run_number = 106
run_attempt = 1
event = 'push'
status = 'completed'
conclusion = 'success'
workflow_id = 5
html_url = 'https://github.com/octocat/hello-world/actions/runs/42'
display_title = 'CI Build'
created_at = '2023-01-01T12:00:00Z'
updated_at = '2023-01-01T12:05:00Z'
run_started_at = '2023-01-01T12:01:00Z'
pull_requests = @()
referenced_workflows = @()
repository = $mockRepo
head_repository = $mockRepo
actor = $mockUser
triggering_actor = $mockUser
head_commit = [PSCustomObject]@{ id = 'abc123'; message = 'Test commit' }
}

$result = [GitHubWorkflowRun]::new($mockRun)

$result.ID | Should -Be 42
$result.NodeID | Should -Be 'MDExOldvcmtmbG93UnVuNDI='
$result.Name | Should -Be 'CI Build'
$result.CheckSuiteID | Should -Be 99
$result.CheckSuiteNodeID | Should -Be 'MDEwOkNoZWNrU3VpdGU5OQ=='
$result.HeadBranch | Should -Be 'main'
$result.HeadSha | Should -Be '009b8a3a9ccbb128af87f9b1c0f4c62e8a304f6d'
$result.Path | Should -Be '.github/workflows/ci.yml'
$result.RunNumber | Should -Be 106
$result.RunAttempt | Should -Be 1
$result.Event | Should -Be 'push'
$result.Status | Should -Be 'completed'
$result.Conclusion | Should -Be 'success'
$result.WorkflowID | Should -Be 5
$result.Url | Should -Be 'https://github.com/octocat/hello-world/actions/runs/42'
$result.DisplayTitle | Should -Be 'CI Build'
}
}

Context 'OIDC' {
Context 'Get-GitHubOidcClaim' {
It 'Get-GitHubOidcClaim - No context - Returns claim keys for github.com' {
Expand Down
Loading