Skip to content

Instantly share code, notes, and snippets.

@jpogran
Created March 10, 2022 18:30
Show Gist options
  • Save jpogran/2dc6cd36e098a85bc436ad8ff16b03e3 to your computer and use it in GitHub Desktop.
Save jpogran/2dc6cd36e098a85bc436ad8ff16b03e3 to your computer and use it in GitHub Desktop.
$user = 'jpogran'
$today = [DateTime]::Now.date
$yesterday = [DateTime]::Now.AddDays(-1).date
function convert-state {
[CmdletBinding()]
param (
[Parameter()]
[string]
$state
)
switch ($state) {
"open" { "Opened" }
"closed" { "Closed" }
Default {}
}
}
function Get-PullRequestEvents {
param (
[Parameter()]$PullRequestEvents
)
$PullRequestEvents | Where-Object { $_.type -eq 'PullRequestEvent' } |
Select-Object @{ n = 'action'; e = { $_.payload.action } },
@{ n = 'state'; e = { $_.payload.pull_request.state } },
@{ n = 'number'; e = { $_.payload.number } },
@{ n = 'repo'; e = { $_.repo.name } },
@{ n = 'created'; e = { $_.payload.pull_request.created_at } },
@{ n = 'updated'; e = { $_.payload.pull_request.updated_at } },
@{ n = 'closed'; e = { $_.payload.pull_request.closed_at } },
@{ n = 'merged'; e = { $_.payload.pull_request.merged_at } },
@{ n = 'url'; e = { $_.payload.pull_request.html_url } },
@{ n = 'title'; e = { $_.payload.pull_request.title } }
}
function Get-IssueEvents {
param (
[Parameter()]$IssueEvents
)
$IssueEvents | Where-Object { $_.type -eq 'IssuesEvent' } |
Select-Object @{ n = 'action'; e = { $_.payload.action } },
@{ n = 'state'; e = { $_.payload.issue.state } },
@{ n = 'number'; e = { $_.payload.issue.number } },
@{ n = 'repo'; e = { $_.repo.name } },
@{ n = 'created'; e = { $_.payload.issue.created_at } },
@{ n = 'updated'; e = { $_.payload.issue.updated_at } },
@{ n = 'closed'; e = { $_.payload.issue.closed_at } },
@{ n = 'url'; e = { $_.payload.issue.html_url } },
@{ n = 'title'; e = { $_.payload.issue.title } }
}
function Get-CommentEvents{
param (
[Parameter()]$CommentEvents
)
$CommentEvents | Where-Object { $_.type -eq 'IssueCommentEvent' } |
Select-Object @{ n = 'action'; e = { $_.payload.action } },
@{ n = 'state'; e = { $_.payload.issue.state } },
@{ n = 'number'; e = { $_.payload.issue.number } },
@{ n = 'repo'; e = { $_.repo.name } },
@{ n = 'created'; e = { $_.payload.comment.created_at } },
@{ n = 'updated'; e = { $_.payload.comment.updated_at } },
@{ n = 'url'; e = { $_.payload.comment.html_url } }
}
function Get-GithubEventReport{
param (
[Parameter()][string]$user,
[Parameter()][DateTime]$date
)
$ghEvents = gh api "users/$user/events" |
ConvertFrom-Json -Depth 100 |
Where-Object { ([datetime]$_.created_at).date -eq $date }
$prEvents = Get-PullRequestEvents $ghEvents
$issues = Get-IssueEvents $ghEvents
$comments = Get-CommentEvents $ghEvents
$prEvents | ForEach-Object {
" - $(Convert-State -state $_.state) [$($_.repo)#$($_.number)]($($_.url))"
}
$issues | ForEach-Object {
" - $(Convert-State -state $_.state) [$($_.repo)#$($_.number)]($($_.url))"
}
$comments | ForEach-Object {
" - Commented on [$($_.repo)#$($_.number)]($($_.url))"
}
}
@"
## Yesterday
gh$(Get-GithubEventReport -User $user -Date $yesterday)
## Today
$(Get-GithubEventReport -User $user -Date $today)
"@
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment