Created
January 9, 2023 19:05
-
-
Save SeeminglyScience/82bbb49f7e53444dd812a1118f27ac6e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Configuration> | |
<ViewDefinitions> | |
<View> | |
<Name>Utility.PullRequest</Name> | |
<ViewSelectedBy> | |
<TypeName>Utility.PullRequest</TypeName> | |
</ViewSelectedBy> | |
<CustomControl> | |
<CustomEntries> | |
<CustomEntry> | |
<CustomItem> | |
<ExpressionBinding> | |
<ScriptBlock> | |
$today = [datetime]::Today | |
$updatedAt = if ($today -eq $_.updatedAt.Date) { | |
" `u{fbae} {0} " -f $_.updatedAt.ToString( | |
[cultureinfo]::CurrentCulture.DateTimeFormat.ShortTimePattern) | |
} else { | |
$days = ($today - $_.updatedAt.Date).TotalDays | |
$str = if ($days -gt 1) { 'days' } else { 'day' } | |
" `u{fbae} {0} {1} ago " -f $days, $str | |
} | |
$suffix = "`u{2500}" * 5 | |
$bb = $PSStyle.Foreground.BrightBlack | |
$bw = $PSStyle.Foreground.BrightWhite | |
$re = $PSStyle.Reset | |
"$bb$("`u{2500}" * ($Host.UI.RawUI.WindowSize.Width - 2 - $suffix.Length - $updatedAt.Length))$bw$updatedAt$bb$suffix$re" | |
</ScriptBlock> | |
</ExpressionBinding> | |
<NewLine /> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
'{0}{2, 5}{1}' -f ( | |
$PSStyle.Foreground.BrightBlack, | |
$PSStyle.Reset, | |
"`u{ea6b} $($_.commentsCount)") | |
</ScriptBlock> | |
</ExpressionBinding> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
if ($_.state -eq 'open') { | |
return "$($PSStyle.Foreground.Green)`u{ea64}$($PSStyle.Reset)" | |
} | |
if ($_.state -eq 'closed') { | |
return "$($PSStyle.Foreground.Red)`u{ebda}$($PSStyle.Reset)" | |
} | |
if ($_.state -eq 'merged') { | |
return "$($PSStyle.Foreground.BrightMagenta)`u{eafe}$($PSStyle.Reset)" | |
} | |
if ($_.state -eq 'draft') { | |
return "$($PSStyle.Foreground.BrightBlack)`u{ebdb}$($PSStyle.Reset)" | |
} | |
return "$($PSStyle.Foreground.Red)?$($PSStyle.Reset)" | |
</ScriptBlock> | |
</ExpressionBinding> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
$PSStyle.FormatHyperlink( | |
"$($PSStyle.Foreground.White)$($_.repository.nameWithOwner)$($PSStyle.Reset)", | |
"https://github.com/$($_.repository.nameWithOwner)") | |
</ScriptBlock> | |
</ExpressionBinding> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
$PSStyle.FormatHyperlink( | |
(($_.title | Show-Markdown | % TrimEnd) -join "`n"), | |
$_.url) | |
</ScriptBlock> | |
</ExpressionBinding> | |
<NewLine /> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
"{3}#{0} opened on {1:yyyy/MM/dd} by {2}{4}" -f ( | |
$_.number, | |
$_.createdAt, | |
$PSStyle.FormatHyperlink( | |
$_.author.login, | |
"https://github.com/$($_.author.login)"), | |
$PSStyle.Foreground.BrightBlack, | |
$PSStyle.Reset) | |
</ScriptBlock> | |
</ExpressionBinding> | |
<NewLine /> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
($_.Labels | Get-GithubLabelDisplay) -join ' ' | |
</ScriptBlock> | |
</ExpressionBinding> | |
</CustomItem> | |
</CustomEntry> | |
</CustomEntries> | |
</CustomControl> | |
</View> | |
<View> | |
<Name>Utility.Issue</Name> | |
<ViewSelectedBy> | |
<TypeName>Utility.Issue</TypeName> | |
</ViewSelectedBy> | |
<CustomControl> | |
<CustomEntries> | |
<CustomEntry> | |
<CustomItem> | |
<ExpressionBinding> | |
<ScriptBlock> | |
$today = [datetime]::Today | |
$updatedAt = if ($today -eq $_.updatedAt.Date) { | |
" `u{fbae} {0} " -f $_.updatedAt.ToString( | |
[cultureinfo]::CurrentCulture.DateTimeFormat.ShortTimePattern) | |
} else { | |
$days = ($today - $_.updatedAt.Date).TotalDays | |
$str = if ($days -gt 1) { 'days' } else { 'day' } | |
" `u{fbae} {0} {1} ago " -f $days, $str | |
} | |
$suffix = "`u{2500}" * 5 | |
$bb = $PSStyle.Foreground.BrightBlack | |
$bw = $PSStyle.Foreground.BrightWhite | |
$re = $PSStyle.Reset | |
"$bb$("`u{2500}" * ($Host.UI.RawUI.WindowSize.Width - 2 - $suffix.Length - $updatedAt.Length))$bw$updatedAt$bb$suffix$re" | |
</ScriptBlock> | |
</ExpressionBinding> | |
<NewLine /> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
'{0}{2, 5}{1}' -f ( | |
$PSStyle.Foreground.BrightBlack, | |
$PSStyle.Reset, | |
"`u{ea6b} $($_.commentsCount)") | |
</ScriptBlock> | |
</ExpressionBinding> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
if ($_.state -eq 'open') { | |
return "$($PSStyle.Foreground.Green)`u{eb0c}$($PSStyle.Reset)" | |
} | |
if ($_.state -eq 'closed') { | |
return "$($PSStyle.Foreground.Red)`u{f41d}$($PSStyle.Reset)" | |
} | |
return "$($PSStyle.Foreground.Red)?$($PSStyle.Reset)" | |
</ScriptBlock> | |
</ExpressionBinding> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
$PSStyle.FormatHyperlink( | |
"$($PSStyle.Foreground.White)$($_.repository.nameWithOwner)$($PSStyle.Reset)", | |
"https://github.com/$($_.repository.nameWithOwner)") | |
</ScriptBlock> | |
</ExpressionBinding> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
$PSStyle.FormatHyperlink( | |
(($_.title | Show-Markdown | % TrimEnd) -join "`n"), | |
$_.url) | |
</ScriptBlock> | |
</ExpressionBinding> | |
<NewLine /> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
"{3}#{0} opened on {1:yyyy/MM/dd} by {2}{4}" -f ( | |
$_.number, | |
$_.createdAt, | |
$PSStyle.FormatHyperlink( | |
$_.author.login, | |
"https://github.com/$($_.author.login)"), | |
$PSStyle.Foreground.BrightBlack, | |
$PSStyle.Reset) | |
</ScriptBlock> | |
</ExpressionBinding> | |
<NewLine /> | |
<Text> </Text> | |
<ExpressionBinding> | |
<ScriptBlock> | |
($_.Labels | Get-GithubLabelDisplay) -join ' ' | |
</ScriptBlock> | |
</ExpressionBinding> | |
</CustomItem> | |
</CustomEntry> | |
</CustomEntries> | |
</CustomControl> | |
</View> | |
</ViewDefinitions> | |
</Configuration> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Get-GithubLabelDisplay { | |
[CmdletBinding()] | |
param( | |
[Parameter(ValueFromPipelineByPropertyName)] | |
[ValidateNotNullOrEmpty()] | |
[string] $Color, | |
[Parameter(ValueFromPipelineByPropertyName)] | |
[ValidateNotNullOrEmpty()] | |
[string] $Name | |
) | |
begin { | |
$re = $PSStyle.Reset | |
} | |
process { | |
$color = [int]('0x' + $Color) | |
$b = [byte]($color -band 0xFF) | |
$g = [byte]($color -shr 8 -band 0xFF) | |
$r = [byte]($color -shr 16 -band 0xFF) | |
$primaryR = [Math]::Min(($r * 1.8), 255) | |
$primaryG = [Math]::Min(($g * 1.8), 255) | |
$primaryB = [Math]::Min(($b * 1.8), 255) | |
$secondaryR = [Math]::Min(($r * 0.33), 255) | |
$secondaryG = [Math]::Min(($g * 0.33), 255) | |
$secondaryB = [Math]::Min(($b * 0.33), 255) | |
$bgPrimary = $PSStyle.Background.FromRgb($primaryR, $primaryG, $primaryB) | |
$fgPrimary = $PSStyle.Foreground.FromRgb($primaryR, $primaryG, $primaryB) | |
$bgSecondary = $PSStyle.Background.FromRgb($secondaryR, $secondaryG, $secondaryB) | |
$fgSecondary = $PSStyle.Foreground.FromRgb($secondaryR, $secondaryG, $secondaryB) | |
return "$fgSecondary`u{e0d4}$fgPrimary$bgSecondary $Name $re$fgSecondary`u{e0b0}$re" | |
} | |
} | |
function Find-Issue { | |
[Alias('fiis')] | |
[CmdletBinding(PositionalBinding = $false)] | |
param( | |
[Parameter(ValueFromRemainingArguments)] | |
[string[]] $ArgumentList, | |
[Parameter()] | |
[ValidateSet('Open', 'Closed')] | |
[string] $State, | |
[Parameter()] | |
[string[]] $Filter, | |
[Parameter()] | |
[datetime] $UpdatedSince, | |
[Parameter()] | |
[switch] $Involved | |
) | |
end { | |
$PSNativeCommandArgumentPassing = 'Legacy' | |
$properties = | |
'assignees', 'author', 'authorAssociation', 'body', | |
'closedAt', 'commentsCount', 'createdAt', 'id', 'isLocked', | |
'isPullRequest', 'labels', 'number', 'repository', 'state', | |
'title', 'updatedAt', 'url' | |
$argList = ('--json', ($properties -join ','), '--sort', 'updated') | |
$queries = @($Filter) | |
$queryTemplate = 'map(select({0}))' | |
if ($PSBoundParameters.ContainsKey((nameof{$UpdatedSince}))) { | |
$queries += ('((.updatedAt | fromdate) > ("{0}" | fromdate))' -f ( | |
$UpdatedSince.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"))) | |
} | |
if ($Involved) { | |
$argList += '--involves=@me' | |
} | |
if ($State) { | |
$argList += '--state={0}' -f $State.ToLowerInvariant() | |
} | |
if ($queries) { | |
$fullQuery = ($queries -match '.') -join ' and ' -replace '"', '\"' | |
$argList += '--jq', ($queryTemplate -f $fullQuery) | |
} | |
$argList += $ArgumentList | |
# gh search issues @argList | |
gh search issues @argList | ConvertFrom-Json | & { process { | |
$PSItem.updatedAt = $PSItem.updatedAt.ToLocalTime() | |
$PSItem.createdAt = $PSItem.createdAt.ToLocalTime() | |
$PSItem.closedAt = $PSItem.closedAt.ToLocalTime() | |
$PSItem.pstypenames.Insert(0, 'Utility.Issue') | |
$PSItem | |
}} | |
} | |
} | |
function Find-PullRequest { | |
[Alias('fipr')] | |
[CmdletBinding(PositionalBinding = $false)] | |
param( | |
[Parameter(ValueFromRemainingArguments)] | |
[string[]] $ArgumentList, | |
[Parameter()] | |
[ValidateSet('Open', 'Closed', 'Merged', 'Draft')] | |
[string] $State, | |
[Parameter()] | |
[string[]] $Filter, | |
[Parameter()] | |
[datetime] $UpdatedSince, | |
[Parameter()] | |
[switch] $ReviewRequested, | |
[Parameter()] | |
[switch] $IncludeBots | |
) | |
end { | |
$PSNativeCommandArgumentPassing = 'Legacy' | |
$properties = | |
'assignees', 'author', 'authorAssociation', 'body', 'closedAt', | |
'commentsCount', 'createdAt', 'id', 'isLocked', 'labels', 'number', | |
'repository', 'state', 'title', 'updatedAt', 'url' | |
$argList = ('--json', ($properties -join ','), '--sort', 'updated') | |
$queries = @($Filter) | |
$queryTemplate = 'map(select({0}))' | |
if (-not $IncludeBots) { | |
$queries += '.author.type != "Bot"' | |
} | |
if ($PSBoundParameters.ContainsKey((nameof{$UpdatedSince}))) { | |
$queries += ('((.updatedAt | fromdate) > ("{0}" | fromdate))' -f ( | |
$UpdatedSince.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'"))) | |
} | |
if ($State -eq 'merged') { | |
$argList += '--merged' | |
} elseif ($State -eq 'draft') { | |
$argList += '--draft' | |
} elseif ($State) { | |
$argList += '--state={0}' -f $State.ToLowerInvariant() | |
} | |
if ($ReviewRequested) { | |
$argList += '--review-requested=@me' | |
} | |
if ($queries) { | |
$fullQuery = ($queries -match '.') -join ' and ' -replace '"', '\"' | |
$argList += '--jq', ($queryTemplate -f $fullQuery) | |
} | |
$argList += $ArgumentList | |
# gh search prs @argList | |
gh search prs @argList | ConvertFrom-Json | & { process { | |
$PSItem.updatedAt = $PSItem.updatedAt.ToLocalTime() | |
$PSItem.createdAt = $PSItem.createdAt.ToLocalTime() | |
$PSItem.closedAt = $PSItem.closedAt.ToLocalTime() | |
$PSItem.pstypenames.Insert(0, 'Utility.PullRequest') | |
$PSItem | |
}} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment