Skip to content

Commit

Permalink
Generate tinyurl for openapi-to-cadl
Browse files Browse the repository at this point in the history
  • Loading branch information
Jose Mauel Heredia Hidalgo committed May 26, 2023
1 parent 0354d7f commit a6ad684
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
5 changes: 4 additions & 1 deletion eng/pipelines/resources/tryit-comment-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ Add the following CLI flags
| @autorest/core | `--version:{{AUTOREST_CORE_DOWNLOAD_URL}}` | For changes to autorest core. |
| @autorest/modelerfour | `--use:{{AUTOREST_MODELERFOUR_DOWNLOAD_URL}}` | For changes to modelerfour. |

<!-- CONFIG_EXTENSIONS -->

Or with all

```bash
autorest --version:{{AUTOREST_CORE_DOWNLOAD_URL}} --use:{{AUTOREST_MODELERFOUR_DOWNLOAD_URL}}
autorest --version:{{AUTOREST_CORE_DOWNLOAD_URL}} --use:{{AUTOREST_MODELERFOUR_DOWNLOAD_URL}} <!-- CLI_FLAGS -->
```

<hr>
Expand All @@ -24,6 +26,7 @@ version: "{{AUTOREST_CORE_DOWNLOAD_URL}}"
# For changes to modelerfour
use-extension:
"@autorest/modelerfour": "{{AUTOREST_MODELERFOUR_DOWNLOAD_URL}}"
{{AUTOREST_OPENAPI_TYPESPEC_EXTENSION}}
```

<hr>
Expand Down
44 changes: 39 additions & 5 deletions eng/pipelines/scripts/get-tryit-github-comment.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,36 @@ function Get-PackageVersion([string] $packageRoot) {
return $version;
}

function Format-Comment([string] $coreDownloadUrl, [string] $modelerfourDownloadUrl) {
function Format-Comment([string] $coreDownloadUrl, [string] $modelerfourDownloadUrl, [hashtable] $extensions = @{}) {
$template = get-content -raw -encoding utf8 "$root/eng/pipelines/resources/tryit-comment-template.md";
$AUTOREST_CORE_DOWNLOAD_URL = $coreDownloadUrl
$AUTOREST_MODELERFOUR_DOWNLOAD_URL = $modelerfourDownloadUrl

return $template `
-replace "{{AUTOREST_CORE_DOWNLOAD_URL}}", $coreDownloadUrl `
-replace "{{AUTOREST_MODELERFOUR_DOWNLOAD_URL}}", $modelerfourDownloadUrl
# Figure out if there are any other extensions to include in the comment
$extensionTableRow, $cliFlags = ProcessExtensionsForComment $extensions

# Replace placeholders in the template
$template = $template -replace "{{AUTOREST_CORE_DOWNLOAD_URL}}", $coreDownloadUrl
$template = $template -replace "{{AUTOREST_MODELERFOUR_DOWNLOAD_URL}}", $modelerfourDownloadUrl
$template = $template -replace "\n<!-- CONFIG_EXTENSIONS -->", $extensionTableRow
$template = $template -replace "<!-- CLI_FLAGS -->", $cliFlags

return $template
}

function ProcessExtensionsForComment([hashtable] $extensions) {
$extensionTableRow = ""
$cliFlags= ""

foreach ($extension in $extensions.GetEnumerator()) {
$extensionName = $extension.Key
$extensionDownloadUrl = $extension.Value

$extensionTableRow += "| $extensionName | `--use:$extensionName@$extensionDownloadUrl` | For changes to $extensionName. |`n"
$cliFlags += " --use:$extensionName@$extensionDownloadUrl `n"
}

return $cliFlags, $extensionTableRow
}

function Run() {
Expand All @@ -44,11 +66,23 @@ function Run() {

$coreVersion = Get-PackageVersion -packageRoot $root/packages/extensions/core
$m4Version = Get-PackageVersion -packageRoot $root/packages/extensions/modelerfour
$openApiToTypespecVersion = Get-PackageVersion -packageRoot $root/packages/extensions/openapi-to-cadl

$coreDownloadUrl = Create-TinyUrlForArtifact -baseDownloadUrl $baseDownloadUrl -filename "autorest-core-$coreVersion.tgz";
$modelerfourDownloadUrl = Create-TinyUrlForArtifact -baseDownloadUrl $baseDownloadUrl -filename "autorest-modelerfour-$m4Version.tgz";
$openApiToTypespecDownloadUrl = Create-TinyUrlForArtifact -baseDownloadUrl $baseDownloadUrl -filename "openapi-to-cadl-$coreVersion.tgz";

$extensions = @{
# Add more extensions as needed
#"@autorest/extension-name" = "extension-name"
}

if (![string]::IsNullOrEmpty($openApiToTypespecDownloadUrl)) {
$extensions["@autorest/openapi-to-cadl"] = $openApiToTypespecDownloadUrl
}


$comment = Format-Comment -coreDownloadUrl $coreDownloadUrl -modelerfourDownloadUrl $modelerfourDownloadUrl
$comment = Format-Comment -coreDownloadUrl $coreDownloadUrl -modelerfourDownloadUrl $modelerfourDownloadUrl -extensions $extensions

Write-Host "Github comment content:"
Write-Host "-----------------------"
Expand Down

0 comments on commit a6ad684

Please sign in to comment.