Skip to content

Commit 1a279ed

Browse files
committed
Scripts to use for creating undocumented API issues
1 parent 19906e7 commit 1a279ed

File tree

3 files changed

+637
-0
lines changed

3 files changed

+637
-0
lines changed

issues/README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# .NET API Documentation Issue Generator
2+
3+
This project automates the creation of GitHub issues for documenting undocumented .NET APIs. It processes Excel compliance data and generates markdown templates for both individual namespace issues and a main tracking issue.
4+
5+
## Prerequisites
6+
7+
1. **PowerShell 7+** - Modern PowerShell version
8+
2. **ImportExcel Module** - For reading Excel files: `Install-Module ImportExcel`
9+
3. **GitHub CLI** - For creating issues: Install from [cli.github.com](https://cli.github.com)
10+
4. **Excel Data File** - Compliance spreadsheet with API data
11+
12+
## Quick Start
13+
14+
### Step 1: Generate Markdown Issues
15+
16+
```powershell
17+
pwsh generate_markdown_issues.ps1 -ExcelFile UndocAPIReport_github.com_dotnet_dotnet-api-docs_main_dotnet-api-docs.xlsx -DotNetVersion 10.0
18+
```
19+
20+
This creates:
21+
- `artifacts/namespace_issues/*.md` - Individual namespace issues
22+
- `artifacts/main_issue.md` - Main tracking issue template
23+
- `artifacts/issue_data.json` - Summary data
24+
25+
### Step 2: Create GitHub Issues
26+
27+
```powershell
28+
pwsh create_github_issues.ps1 -Repo "owner/repo"
29+
```
30+
31+
This creates:
32+
- 1 main tracking issue from the generated template
33+
- Individual namespace issues (count varies by .NET version)
34+
35+
## Generated Outputs
36+
37+
## File Structure
38+
39+
```
40+
undocAPI/
41+
├── generate_markdown_issues.ps1 # Generate markdown from Excel data
42+
├── create_github_issues.ps1 # Create GitHub issues from markdown
43+
├── templates/ # Issue templates (editable)
44+
│ ├── main_issue_template.md # Main tracking issue template
45+
│ └── namespace_issue_template.md # Namespace issue template
46+
├── artifacts/ # Generated files (safe to delete)
47+
│ ├── namespace_issues/ # Individual namespace markdown files
48+
│ ├── main_issue.md # Main tracking issue template
49+
│ └── issue_data.json # Summary data
50+
└── UndocAPIReport_*.xlsx # Source Excel compliance data
51+
```
52+
53+
## Template System
54+
55+
The system uses editable template files in the `templates/` directory:
56+
57+
### Template Variables
58+
Templates use `{{VARIABLE_NAME}}` syntax for replacements:
59+
- `{{DOTNET_VERSION}}` - .NET version (e.g., "10.0")
60+
- `{{TOTAL_APIS}}` - Total API count
61+
- `{{TOTAL_NAMESPACES}}` - Total namespace count
62+
- `{{NAMESPACE}}` - Namespace name
63+
- `{{API_COUNT}}` - APIs in namespace
64+
- `{{API_LIST}}` - Generated API list
65+
- `{{NAMESPACE_CHECKLIST}}` - Generated namespace checklist
66+
67+
### Template Comments
68+
Comments in templates (between `<!-- -->`) are automatically removed during processing and can contain documentation about variables and formatting.
69+
70+
## Configuration
71+
72+
### .NET Version
73+
Use the `-DotNetVersion` parameter:
74+
```powershell
75+
pwsh generate_markdown_issues.ps1 -DotNetVersion "11.0"
76+
```
77+
78+
### Repository
79+
Use the `-Repo` parameter:
80+
```powershell
81+
pwsh create_github_issues.ps1 -Repo "ericstj/scratch"
82+
```
83+
84+
## Linking Workflow
85+
86+
The system creates bidirectional links between issues:
87+
88+
1. **Main Tracking Issue**: Created first with placeholders for namespace issue numbers
89+
2. **Namespace Issues**: Created with links back to the main tracking issue
90+
3. **Link Updates**: Main tracking issue is automatically updated with actual namespace issue numbers
91+
92+
### Issue Cross-References
93+
- Each namespace issue links to the main tracking issue: "Please follow the instructions in the main tracking issue (#123)"
94+
- The main tracking issue links to each namespace issue: "- [ ] **Namespace** (X APIs) - #456"
95+
96+
## Data Sources
97+
98+
The system reads from the Excel compliance spreadsheet and filters for:
99+
- APIs matching the specified .NET version
100+
- Non-null API links with proper formatting
101+
- Grouped by namespace for organization
102+
103+
## Clean Workflow
104+
105+
1. **Generate**`pwsh generate_markdown_issues.ps1 -DotNetVersion "X.X"`
106+
2. **Review** → Check `artifacts/` directory contents
107+
3. **Deploy**`pwsh create_github_issues.ps1 -Repo "owner/repo"`
108+
109+
The `artifacts/` directory can be safely deleted and regenerated at any time.

issues/create_github_issues.ps1

Lines changed: 204 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,204 @@
1+
# Create GitHub issues from generated markdown files
2+
#
3+
# This script reads markdown files from artifacts/namespace_issues/ and creates:
4+
# - 1 main tracking issue from artifacts/main_issue.md
5+
# - Individual namespace issues from artifacts/namespace_issues/
6+
#
7+
# Prerequisites:
8+
# - GitHub CLI (gh) installed and authenticated
9+
# - Generated markdown files from generate_markdown_issues.ps1
10+
#
11+
# Usage:
12+
# pwsh create_github_issues.ps1 -Repo "owner/repo"
13+
14+
param(
15+
[Parameter(Mandatory=$true)]
16+
[string]$Repo
17+
)
18+
19+
# Parse repository owner and name from format "owner/repo"
20+
if ($Repo -notmatch '^([^/]+)/([^/]+)$') {
21+
Write-Error "❌ Invalid repository format. Use: owner/repo (e.g., 'ericstj/scratch')"
22+
exit 1
23+
}
24+
25+
$RepoOwner = $Matches[1]
26+
$RepoName = $Matches[2]
27+
28+
Write-Host "🎯 Target repository: $RepoOwner/$RepoName" -ForegroundColor Cyan
29+
30+
# Read summary data to get .NET version and counts
31+
$SummaryFile = "artifacts\issue_data.json"
32+
if (-not (Test-Path $SummaryFile)) {
33+
Write-Error "❌ Summary file not found: $SummaryFile"
34+
Write-Host "Please run generate_markdown_issues.ps1 first to create the artifacts." -ForegroundColor Yellow
35+
exit 1
36+
}
37+
38+
$SummaryData = Get-Content $SummaryFile | ConvertFrom-Json
39+
$DotNetVersion = $SummaryData.dotnet_version
40+
$TotalAPIs = $SummaryData.total_apis
41+
$TotalNamespaces = $SummaryData.total_namespaces
42+
43+
Write-Host "🔄 Creating .NET $DotNetVersion documentation issues..." -ForegroundColor Green
44+
Write-Host "📊 Will create $TotalNamespaces namespace issues for $TotalAPIs APIs" -ForegroundColor White
45+
46+
# Create main tracking issue
47+
Write-Host "📝 Creating main tracking issue..."
48+
$MainIssueFile = "artifacts\main_issue.md"
49+
50+
if (-not (Test-Path $MainIssueFile)) {
51+
Write-Error "❌ Main issue template not found: $MainIssueFile"
52+
Write-Host "Please run generate_markdown_issues.ps1 first to create the template." -ForegroundColor Yellow
53+
exit 1
54+
}
55+
56+
# Create the main tracking issue
57+
Write-Host "📝 Creating main tracking issue..."
58+
$MainIssueTitle = ".NET $DotNetVersion API Documentation Tracking Issue"
59+
$MainIssueUrl = gh issue create --repo "$RepoOwner/$RepoName" --title $MainIssueTitle --body-file $MainIssueFile
60+
61+
if ($LASTEXITCODE -eq 0 -and -not [string]::IsNullOrEmpty($MainIssueUrl)) {
62+
Write-Host "✅ Created main tracking issue: $MainIssueUrl" -ForegroundColor Green
63+
64+
# Extract the main issue number from the URL
65+
$MainIssueNumber = ($MainIssueUrl -split '/')[-1]
66+
Write-Host "📋 Main tracking issue number: #$MainIssueNumber" -ForegroundColor White
67+
} else {
68+
Write-Host "❌ Failed to create main tracking issue" -ForegroundColor Red
69+
Write-Host "Please check your GitHub CLI authentication and repository permissions." -ForegroundColor Yellow
70+
exit 1
71+
}
72+
73+
# Create individual namespace issues
74+
Write-Host "📚 Creating namespace issues..."
75+
$NamespaceFiles = Get-ChildItem "artifacts\namespace_issues\*.md" | Where-Object { $_.Name -notlike "*_part*.md" } | Sort-Object Name
76+
$CreatedCount = 0
77+
$NamespaceIssueMap = @{}
78+
79+
foreach ($File in $NamespaceFiles) {
80+
$Namespace = $File.BaseName.Replace('_', '.')
81+
$Title = "$Namespace docs for .NET $DotNetVersion APIs"
82+
83+
Write-Host " Creating: $Title"
84+
85+
try {
86+
# Read the template and replace the main tracking issue placeholder
87+
$TemplateContent = Get-Content $File.FullName -Raw
88+
$UpdatedContent = $TemplateContent -replace '#MAIN_TRACKING_ISSUE_NUMBER', "#$MainIssueNumber"
89+
90+
# Create a temporary file with updated content
91+
$TempFile = [System.IO.Path]::GetTempFileName()
92+
$UpdatedContent | Out-File -FilePath $TempFile -Encoding UTF8
93+
94+
$IssueUrl = gh issue create --repo "$RepoOwner/$RepoName" --title $Title --body-file $TempFile
95+
96+
# Clean up temp file
97+
Remove-Item $TempFile -Force
98+
99+
if ($LASTEXITCODE -eq 0 -and -not [string]::IsNullOrEmpty($IssueUrl)) {
100+
Write-Host " ✅ Created: $IssueUrl" -ForegroundColor Green
101+
$CreatedCount++
102+
103+
# Extract issue number and store mapping
104+
$IssueNumber = ($IssueUrl -split '/')[-1]
105+
$NamespaceIssueMap[$Namespace] = $IssueNumber
106+
107+
# Check for split parts and add them as comments
108+
$SafeName = $File.BaseName
109+
$PartFiles = Get-ChildItem "artifacts\namespace_issues\$($SafeName)_part*.md" -ErrorAction SilentlyContinue
110+
111+
if ($PartFiles.Count -gt 0) {
112+
Write-Host " 📝 Adding $($PartFiles.Count) comment parts..." -ForegroundColor Cyan
113+
114+
foreach ($PartFile in ($PartFiles | Sort-Object Name)) {
115+
$PartContent = Get-Content $PartFile.FullName -Raw
116+
117+
try {
118+
# Create a temporary file for the comment body to avoid command line length limits
119+
$TempCommentFile = [System.IO.Path]::GetTempFileName()
120+
$PartContent | Out-File -FilePath $TempCommentFile -Encoding UTF8
121+
122+
gh issue comment $IssueNumber --repo "$RepoOwner/$RepoName" --body-file $TempCommentFile | Out-Null
123+
124+
# Clean up temp file
125+
Remove-Item $TempCommentFile -Force
126+
127+
if ($LASTEXITCODE -eq 0) {
128+
Write-Host " ✅ Added comment from $($PartFile.Name)" -ForegroundColor Green
129+
} else {
130+
Write-Host " ❌ Failed to add comment from $($PartFile.Name)" -ForegroundColor Red
131+
}
132+
}
133+
catch {
134+
Write-Host " ❌ Error adding comment from $($PartFile.Name): $_" -ForegroundColor Red
135+
}
136+
137+
# Small delay between comments
138+
Start-Sleep -Milliseconds 100
139+
}
140+
}
141+
} else {
142+
Write-Host " ❌ Failed to create issue for $Namespace" -ForegroundColor Red
143+
}
144+
145+
# Small delay to avoid rate limiting
146+
Start-Sleep -Milliseconds 250
147+
}
148+
catch {
149+
Write-Host " ❌ Failed to create issue for $Namespace : $_" -ForegroundColor Red
150+
}
151+
}
152+
153+
# Update the main tracking issue with actual namespace issue links
154+
if ($NamespaceIssueMap.Count -gt 0) {
155+
Write-Host "🔗 Updating main tracking issue with namespace issue links..."
156+
157+
try {
158+
# Read the main issue template
159+
$MainIssueContent = Get-Content $MainIssueFile -Raw
160+
161+
# Replace each namespace placeholder with actual issue number
162+
# Sort by namespace length (longest first) to avoid substring matching issues
163+
$SortedEntries = $NamespaceIssueMap.GetEnumerator() | Sort-Object { $_.Key.Length } -Descending
164+
165+
foreach ($NamespaceEntry in $SortedEntries) {
166+
$Namespace = $NamespaceEntry.Key
167+
$IssueNumber = $NamespaceEntry.Value
168+
$SafeName = $Namespace -replace '\.', '_' -replace ' ', '_'
169+
170+
# Find and replace the exact placeholder with GitHub issue reference
171+
$Pattern = "NAMESPACE_ISSUE_PLACEHOLDER_$([regex]::Escape($SafeName))\b"
172+
$Replacement = "#$IssueNumber"
173+
$MainIssueContent = $MainIssueContent -replace $Pattern, $Replacement
174+
}
175+
176+
# Create temp file with updated content
177+
$TempMainFile = [System.IO.Path]::GetTempFileName()
178+
$MainIssueContent | Out-File -FilePath $TempMainFile -Encoding UTF8
179+
180+
# Update the main issue
181+
gh issue edit $MainIssueNumber --repo "$RepoOwner/$RepoName" --body-file $TempMainFile | Out-Null
182+
183+
# Clean up temp file
184+
Remove-Item $TempMainFile -Force
185+
186+
if ($LASTEXITCODE -eq 0) {
187+
Write-Host "✅ Updated main tracking issue with namespace links" -ForegroundColor Green
188+
} else {
189+
Write-Host "⚠️ Failed to update main tracking issue with links" -ForegroundColor Yellow
190+
}
191+
}
192+
catch {
193+
Write-Host "⚠️ Failed to update main tracking issue: $_" -ForegroundColor Yellow
194+
}
195+
}
196+
197+
Write-Host "`n🎉 GitHub Issue Creation Complete!" -ForegroundColor Green
198+
Write-Host "📊 Summary:" -ForegroundColor Yellow
199+
Write-Host " - .NET version: $DotNetVersion" -ForegroundColor White
200+
Write-Host " - Main tracking issue created" -ForegroundColor White
201+
Write-Host " - Namespace issues created: $CreatedCount" -ForegroundColor White
202+
Write-Host " - Total APIs to be documented: $TotalAPIs" -ForegroundColor White
203+
Write-Host " - Repository: https://github.com/$RepoOwner/$RepoName/issues" -ForegroundColor White
204+
Write-Host "`n✅ All issues created with properly formatted API links!" -ForegroundColor Green

0 commit comments

Comments
 (0)