@@ -142,12 +142,34 @@ extends:
142142 # Create emitter identifier from package path for disambiguation
143143 $emitterIdentifier = ""
144144 if (-not [string]::IsNullOrWhiteSpace($emitterPackagePath)) {
145- # Extract filename without extension and make it safe for branch names
146- $emitterIdentifier = [System.IO.Path]::GetFileNameWithoutExtension($emitterPackagePath)
147- # Replace any characters that aren't alphanumeric, hyphens, or underscores
148- $emitterIdentifier = $emitterIdentifier -replace '[^a-zA-Z0-9\-_]', '-'
149- # Remove any leading/trailing hyphens and convert to lowercase
145+ # Resolve emitterPackagePath to absolute path (it's relative to repo root)
146+ # EmitterPackagePath is a directory, so append package.json
147+ $absoluteEmitterPackagePath = Join-Path '$(Build.SourcesDirectory)' $emitterPackagePath
148+ $packageJsonPath = Join-Path $absoluteEmitterPackagePath 'package.json'
149+
150+ # Read the package name from package.json
151+ if (Test-Path $packageJsonPath) {
152+ try {
153+ $packageJson = Get-Content $packageJsonPath -Raw | ConvertFrom-Json
154+ if ($packageJson.name) {
155+ $emitterIdentifier = $packageJson.name
156+ }
157+ } catch {
158+ Write-Host "Warning: Could not read package name from $packageJsonPath"
159+ }
160+ }
161+
162+ # If we still don't have an identifier, fall back to filename
163+ if ([string]::IsNullOrWhiteSpace($emitterIdentifier)) {
164+ Write-Host "Warning: Could not read emitter name from package.json, falling back to package path"
165+ $emitterIdentifier = [System.IO.Path]::GetFileNameWithoutExtension($emitterPackagePath)
166+ }
167+
168+ # Clean up the identifier: remove @ prefix, replace invalid chars
169+ $emitterIdentifier = $emitterIdentifier -replace '^@', ''
170+ $emitterIdentifier = $emitterIdentifier -replace '[^a-zA-Z0-9\-_/]', '-'
150171 $emitterIdentifier = $emitterIdentifier.Trim('-').ToLower()
172+
151173 if (-not [string]::IsNullOrWhiteSpace($emitterIdentifier)) {
152174 $emitterIdentifier = "-$emitterIdentifier"
153175 }
@@ -163,6 +185,8 @@ extends:
163185
164186 Write-Host "Setting variable 'branchName' to '$branchName'"
165187 Write-Host "##vso[task.setvariable variable=branchName;isOutput=true]$branchName"
188+ Write-Host "Setting variable 'emitterIdentifier' to '$emitterIdentifier'"
189+ Write-Host "##vso[task.setvariable variable=emitterIdentifier;isOutput=true]$emitterIdentifier"
166190 displayName: Set branch name
167191 name: set_branch_name
168192
@@ -383,15 +407,18 @@ extends:
383407 displayName : Create PR
384408 dependsOn :
385409 - Generate
410+ condition : succeededOrFailed()
386411 variables :
387412 generateJobResult : $[dependencies.Generate.result]
388413 emitterVersion : $[stageDependencies.Build.Build.outputs['initialize.emitterVersion']]
414+ emitterIdentifier : $[stageDependencies.Build.Build.outputs['set_branch_name.emitterIdentifier']]
389415 steps :
390416 - template : /eng/common/pipelines/templates/steps/sparse-checkout.yml
391417
392418 - pwsh : |
393419 $generateJobResult = '$(generateJobResult)'
394420 $emitterVersion = '$(emitterVersion)'
421+ $emitterIdentifier = '$(emitterIdentifier)'
395422 $collectionUri = '$(System.CollectionUri)'
396423 $project = '$(System.TeamProject)'
397424 $definitionName = '$(Build.DefinitionName)'
@@ -403,6 +430,12 @@ extends:
403430 $buildNumber = '$(Build.BuildNumber)'
404431 $preRelease = '${{ parameters.BuildPrereleaseVersion }}' -eq 'true'
405432
433+ # Use emitterIdentifier for PR title (remove leading dash if present)
434+ $emitterName = "TypeSpec emitter"
435+ if (-not [string]::IsNullOrWhiteSpace($emitterIdentifier)) {
436+ $emitterName = $emitterIdentifier.TrimStart('-')
437+ }
438+
406439 $prBody = "Generated by $definitionName build [$buildNumber]($collectionUri/$project/_build/results?buildId=$buildId)<br/>"
407440
408441 if ($sourceBranch -match "^refs/heads/(.+)$") {
@@ -419,9 +452,9 @@ extends:
419452 $prTitle = "Scheduled code regeneration test"
420453 } else {
421454 if ($preRelease) {
422- $prTitle = "Update TypeSpec emitter version to prerelease $emitterVersion"
455+ $prTitle = "Update $emitterName version to prerelease $emitterVersion"
423456 } else {
424- $prTitle = "Update TypeSpec emitter version to $emitterVersion"
457+ $prTitle = "Update $emitterName version to $emitterVersion"
425458 }
426459
427460 if ($generateJobResult -ne 'Succeeded') {
@@ -446,7 +479,8 @@ extends:
446479 Write-Error "Build.Repository.Name not in the expected {Owner}/{Name} format"
447480 }
448481
449- $openAsDraft = -not ($reason -eq 'IndividualCI' -and $sourceBranch -eq 'refs/heads/main')
482+ # Open PR as draft if generation failed, or if it's not an IndividualCI build from main
483+ $openAsDraft = ($generateJobResult -ne 'Succeeded') -or (-not ($reason -eq 'IndividualCI' -and $sourceBranch -eq 'refs/heads/main'))
450484 Write-Host "Setting OpenAsDraftBool = $openAsDraft"
451485 Write-Host "##vso[task.setvariable variable=OpenAsDraft]$openAsDraft"
452486 if ($openAsDraft) {
0 commit comments