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