Skip to content

Commit d2fbb74

Browse files
authored
Update the logic of get commit id in autorest generation (#20827)
* Update the logic of get commit id in autorest generation * Update the logic of get commit id in autorest generation
1 parent bc01fa8 commit d2fbb74

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

tools/Gen2Master/MoveFromGeneration2Master.ps1

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,9 +121,14 @@ Function Move-Generation2Master {
121121

122122
#Region generate-info.json Here have a issue that user may not use latest version to generate the code.
123123
$generateInfo = [ordered]@{}
124-
$repo = "https://github.com/Azure/azure-rest-api-specs"
125-
$commit = git ls-remote $repo HEAD
126-
$generateInfo.Add("swagger_commit", $commit.Substring(0, 40))
124+
$content = Get-Content README.md
125+
$commitId = [System.Text.RegularExpressions.Regex]::New("(?i)\bbranch\b:[ \t]*([0-9a-zA-Z]+)").Matches($content) | % {$_.groups[1].Value}
126+
if ($commitId -eq $null -or $commitId -eq "main")
127+
{
128+
$repo = "https://github.com/Azure/azure-rest-api-specs"
129+
$commitId = git ls-remote $repo HEAD
130+
}
131+
$generateInfo.Add("swagger_commit", $commitId.Substring(0, 40))
127132
$generateInfo.Add("node", (node --version))
128133
$autorest_info = (npm ls -g @autorest/autorest).Split('@')
129134
$generateInfo.Add("autorest", ($autorest_info[$autorest_info.count - 2]).trim())

0 commit comments

Comments
 (0)