@@ -186,22 +186,53 @@ stages:
186186 $newContent = ($updatedLines -join "`n")
187187 $contentBytes = [System.Text.Encoding]::UTF8.GetBytes($newContent)
188188 $contentBase64 = [System.Convert]::ToBase64String($contentBytes)
189- $commitMessage = "Add $versionKey to Telemetry JSON via Azure Pipeline"
190-
189+ $commitMessage = "Add $versionKey to Telemetry JSON via Azure Pipelines"
190+ $newBranch = "telemetry-update-$($versionKey.Replace('.', '-'))"
191+
192+ ### Create a new branch and open a PR
193+ # Fetch latest commit SHA for the base branch
194+ Write-Host "Fetching latest commit SHA for branch $branch..."
195+ $refUrl = "https://api.github.com/repos/$repo/git/refs/heads/$branch"
196+ $refInfo = Invoke-RestMethod -Uri $refUrl -Headers $headers -Method Get
197+ $latestCommitSha = $refInfo.object.sha
198+ Write-Host "Latest commit SHA: $latestCommitSha"
199+
200+ # Create new branch from latest commit
201+ Write-Host "Creating new branch $newBranch..."
202+ $newRefBody = @{
203+ ref = "refs/heads/$newBranch"
204+ sha = $latestCommitSha
205+ } | ConvertTo-Json
206+ Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/git/refs" -Headers $headers -Method Post -Body $newRefBody -ContentType "application/json"
207+ Write-Host "✓ Created branch $newBranch"
208+
209+ # Update the file in the new branch
191210 $updateBody = @{
192211 message = $commitMessage
193212 content = $contentBase64
194213 sha = $fileInfo.sha
195- branch = $branch
214+ branch = $newBranch
196215 } | ConvertTo-Json -Depth 10
197216
198- Write-Host "Pushing changes to GitHub ..."
217+ Write-Host "Pushing changes to $newBranch ..."
199218 $putUrl = "https://api.github.com/repos/$repo/contents/$filePath"
200- $response = Invoke-RestMethod -Uri $putUrl -Headers $headers -Method Put -Body $updateBody -ContentType "application/json"
219+ Invoke-RestMethod -Uri $putUrl -Headers $headers -Method Put -Body $updateBody -ContentType "application/json"
220+ Write-Host "✓ Pushed changes to $newBranch"
221+
222+ # Create a pull request
223+ Write-Host "Creating pull request from $newBranch to $branch..."
224+ $prBody = @{
225+ title = $commitMessage
226+ head = $newBranch
227+ base = $branch
228+ body = "This PR was automatically generated by Azure Pipelines to add $versionKey to the Telemetry JSON file."
229+ } | ConvertTo-Json
230+ $pr = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/pulls" -Headers $headers -Method Post -Body $prBody -ContentType "application/json"
201231
202232 Write-Host ""
203233 Write-Host "================================================"
204- Write-Host "✅ Successfully added $versionKey to Telemetry JSON"
234+ Write-Host "✅ Successfully created PR #$($pr.number) for $versionKey"
235+ Write-Host "PR URL: $($pr.html_url)"
205236 Write-Host "================================================"
206237
207238 } catch {
0 commit comments