From a6ad684c3c8b1a7c82527bf4ac7e665f8569fd73 Mon Sep 17 00:00:00 2001
From: Jose Mauel Heredia Hidalgo <>
Date: Fri, 26 May 2023 12:43:46 -0700
Subject: [PATCH] Generate tinyurl for openapi-to-cadl
---
.../resources/tryit-comment-template.md | 5 ++-
.../scripts/get-tryit-github-comment.ps1 | 44 ++++++++++++++++---
2 files changed, 43 insertions(+), 6 deletions(-)
diff --git a/eng/pipelines/resources/tryit-comment-template.md b/eng/pipelines/resources/tryit-comment-template.md
index 64a8afcb4a..72cabdc992 100644
--- a/eng/pipelines/resources/tryit-comment-template.md
+++ b/eng/pipelines/resources/tryit-comment-template.md
@@ -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. |
+
+
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}}
```
@@ -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}}
```
diff --git a/eng/pipelines/scripts/get-tryit-github-comment.ps1 b/eng/pipelines/scripts/get-tryit-github-comment.ps1
index d679a8d905..feb23198dd 100644
--- a/eng/pipelines/scripts/get-tryit-github-comment.ps1
+++ b/eng/pipelines/scripts/get-tryit-github-comment.ps1
@@ -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", $extensionTableRow
+ $template = $template -replace "", $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() {
@@ -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 "-----------------------"