Skip to content

Commit bf141df

Browse files
authored
refactor(scripts): combine external issues and PRs into single priority items script (#72)
1 parent 029d1e0 commit bf141df

3 files changed

Lines changed: 113 additions & 192 deletions

File tree

scripts/show-external-issues.ps1

Lines changed: 0 additions & 102 deletions
This file was deleted.

scripts/show-open-prs.ps1

Lines changed: 0 additions & 90 deletions
This file was deleted.

scripts/show-priority-items.ps1

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
# Show priority items across CodingWithCalvin organization's public repositories:
2+
# - Open issues from external contributors
3+
# - Open PRs from external contributors
4+
#
5+
# Usage:
6+
# .\show-priority-items.ps1
7+
#
8+
9+
$ErrorActionPreference = "Stop"
10+
$Org = "CodingWithCalvin"
11+
12+
# Get the authenticated user's login
13+
$me = gh api user --jq '.login'
14+
15+
# Column widths
16+
$colRepo = 30
17+
$colTitle = 50
18+
$colAuthor = 15
19+
$colAge = 10
20+
$colURL = 60
21+
22+
# Helper to truncate/pad strings with 1 char padding on each side
23+
function Format-Cell([string]$text, [int]$width) {
24+
$innerWidth = $width - 2 # Account for padding
25+
if ($text.Length -gt $innerWidth) {
26+
return " " + $text.Substring(0, $innerWidth - 3) + "..." + " "
27+
}
28+
return " " + $text.PadRight($innerWidth) + " "
29+
}
30+
31+
# Render a table of items
32+
function Show-Table([array]$items, [string]$label) {
33+
Write-Host ""
34+
Write-Host "=== $label ===" -ForegroundColor Magenta
35+
Write-Host ""
36+
37+
if (-not $items -or $items.Count -eq 0) {
38+
Write-Host " None found." -ForegroundColor Yellow
39+
return
40+
}
41+
42+
$hLine = "+" + ("-" * $colRepo) + "+" + ("-" * $colTitle) + "+" + ("-" * $colAuthor) + "+" + ("-" * $colAge) + "+" + ("-" * $colURL) + "+"
43+
$totalInnerWidth = $colRepo + $colTitle + $colAuthor + $colAge + $colURL + 4 # +4 for inner separators
44+
45+
Write-Host $hLine
46+
Write-Host "|" -NoNewline
47+
Write-Host (Format-Cell "Repo" $colRepo) -NoNewline -ForegroundColor Green
48+
Write-Host "|" -NoNewline
49+
Write-Host (Format-Cell "Title" $colTitle) -NoNewline -ForegroundColor Green
50+
Write-Host "|" -NoNewline
51+
Write-Host (Format-Cell "Author" $colAuthor) -NoNewline -ForegroundColor Green
52+
Write-Host "|" -NoNewline
53+
Write-Host (Format-Cell "Age" $colAge) -NoNewline -ForegroundColor Green
54+
Write-Host "|" -NoNewline
55+
Write-Host (Format-Cell "URL" $colURL) -NoNewline -ForegroundColor Green
56+
Write-Host "|"
57+
Write-Host $hLine
58+
59+
foreach ($item in $items | Sort-Object { $_.repository.name }, number) {
60+
$age = [math]::Max(0, [math]::Floor(((Get-Date) - [datetime]$item.createdAt).TotalDays))
61+
$ageText = if ($age -eq 0) { "today" } elseif ($age -eq 1) { "1 day" } else { "$age days" }
62+
63+
$row = "|" + (Format-Cell $item.repository.name $colRepo) + "|" + (Format-Cell $item.title $colTitle) + "|" + (Format-Cell $item.author.login $colAuthor) + "|" + (Format-Cell $ageText $colAge) + "|" + (Format-Cell $item.url $colURL) + "|"
64+
Write-Host $row
65+
66+
# Description rows spanning all columns (up to 3 lines)
67+
$desc = if ($item.body) { ($item.body -replace "`r?`n", " " -replace "\s+", " ").Trim() } else { "(no description)" }
68+
$descWidth = $totalInnerWidth - 5 # Account for padding (1) + indent (3) + padding (1)
69+
$maxLines = 3
70+
$emptyRow = "|" + (" " * $totalInnerWidth) + "|"
71+
72+
# Top padding
73+
Write-Host $emptyRow
74+
75+
for ($i = 0; $i -lt $maxLines -and $desc.Length -gt 0; $i++) {
76+
$isLastLine = ($i -eq $maxLines - 1) -or ($desc.Length -le $descWidth)
77+
if ($isLastLine -and $desc.Length -gt $descWidth) {
78+
$lineText = $desc.Substring(0, $descWidth - 3) + "..."
79+
} elseif ($desc.Length -gt $descWidth) {
80+
$lineText = $desc.Substring(0, $descWidth)
81+
$desc = $desc.Substring($descWidth)
82+
} else {
83+
$lineText = $desc
84+
$desc = ""
85+
}
86+
Write-Host "|" -NoNewline
87+
Write-Host (" " + " " + $lineText.PadRight($descWidth) + " ") -NoNewline -ForegroundColor DarkGray
88+
Write-Host "|"
89+
}
90+
91+
# Bottom padding
92+
Write-Host $emptyRow
93+
Write-Host $hLine
94+
}
95+
}
96+
97+
# --- External Issues ---
98+
Write-Host "Fetching priority items across $Org public repositories (excluding yours, $me)..." -ForegroundColor Cyan
99+
100+
$issues = gh search issues --owner $Org --state open --json repository,number,title,author,createdAt,url,body --limit 500 | ConvertFrom-Json
101+
if ($issues) {
102+
$issues = $issues | Where-Object { $_.author.login -ne $me }
103+
}
104+
105+
Show-Table $issues "External Issues"
106+
107+
# --- External PRs ---
108+
$prs = gh search prs --owner $Org --state open --json repository,number,title,author,createdAt,url,body --limit 500 | ConvertFrom-Json
109+
if ($prs) {
110+
$prs = $prs | Where-Object { $_.author.login -ne $me }
111+
}
112+
113+
Show-Table $prs "External PRs"

0 commit comments

Comments
 (0)