Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,15 @@ func main() {
}

[Test]
public void TestGetSDKPackagePath()
public async Task TestGetSDKPackageName()
{
Assert.That(
LangService.GetSDKPackagePath(Path.Combine("/hello", "world", "az") + Path.DirectorySeparatorChar, Path.Combine("/hello", "world", "az", "sdk", "messaging", "azservicebus")),
await LangService.GetSDKPackageName(Path.Combine("/hello", "world", "az") + Path.DirectorySeparatorChar, Path.Combine("/hello", "world", "az", "sdk", "messaging", "azservicebus")),
Is.EqualTo(Path.Combine("sdk", "messaging", "azservicebus"))
);

Assert.That(
LangService.GetSDKPackagePath(Path.Combine("/hello", "world", "az"), Path.Combine("/hello", "world", "az", "sdk", "messaging", "azservicebus")),
await LangService.GetSDKPackageName(Path.Combine("/hello", "world", "az"), Path.Combine("/hello", "world", "az", "sdk", "messaging", "azservicebus")),
Is.EqualTo(Path.Combine("sdk", "messaging", "azservicebus")));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<NoWarn>ASP0000;CS8603;CS8618;CS8625;CS8604</NoWarn>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<AssemblyName>azsdk</AssemblyName>
<VersionPrefix>0.5.2</VersionPrefix>
<VersionPrefix>0.5.3</VersionPrefix>
<VersionSuffix></VersionSuffix>
<!-- Package metadata -->
<PackageReleaseNotes>See CHANGELOG.md for release notes</PackageReleaseNotes>
Expand Down
6 changes: 6 additions & 0 deletions tools/azsdk-cli/Azure.Sdk.Tools.Cli/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release History

## 0.5.3 (Unreleased)

### Bugs Fixed

- Added a language specific way to get package name for validation checks, to account for different language naming (JS uses package.json name)

## 0.5.2 (2025-10-13)

### Features
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,15 +149,17 @@ public async Task<CLICheckResponse> BuildProjectAsync(string packagePath, Cancel
}
}

public string GetSDKPackagePath(string repo, string packagePath)
public async Task<string> GetSDKPackageName(string repo, string packagePath, CancellationToken cancellationToken = default)
{
if (!repo.EndsWith(Path.DirectorySeparatorChar))
{
repo += Path.DirectorySeparatorChar;
}

// ex: sdk/messaging/azservicebus/
return packagePath.Replace(repo, "");
var relativePath = packagePath.Replace(repo, "");
// Ensure forward slashes for Go package names
return await Task.FromResult(relativePath.Replace(Path.DirectorySeparatorChar, '/'));
}

public async Task<CLICheckResponse> UpdateSnippetsAsync(string packagePath, bool fixCheckErrors = false, CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,4 +54,17 @@ Task<CLICheckResponse> FormatCodeAsync(string packagePath, bool fixCheckErrors =
{
return Task.FromResult(new CLICheckResponse(1, "", "Not implemented for this language."));
}

/// <summary>
/// Gets the SDK package name.
/// </summary>
/// <param name="repo">Repository root path</param>
/// <param name="packagePath">Package path</param>
/// <param name="cancellationToken">Cancellation token</param>
/// <returns>SDK package name</returns>
Task<string> GetSDKPackageName(string repo, string packagePath, CancellationToken cancellationToken = default)
{
// Default implementation: use the directory name as the package path
return Task.FromResult(Path.GetFileName(packagePath));
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Text.Json;
using Azure.Sdk.Tools.Cli.Helpers;
using Azure.Sdk.Tools.Cli.Models;

Expand Down Expand Up @@ -132,4 +133,33 @@ public async Task<CLICheckResponse> FormatCodeAsync(string packagePath, bool fix
return new CLICheckResponse(1, "", $"Error formatting code: {ex.Message}");
}
}
}

public async Task<string> GetSDKPackageName(string repo, string packagePath, CancellationToken cancellationToken = default)
{
// For JavaScript packages, read the package name from package.json
var packageJsonPath = Path.Combine(packagePath, "package.json");
if (File.Exists(packageJsonPath))
{
try
{
var packageJsonContent = await File.ReadAllTextAsync(packageJsonPath, cancellationToken);
using var document = JsonDocument.Parse(packageJsonContent);
if (document.RootElement.TryGetProperty("name", out var nameProperty))
{
var packageName = nameProperty.GetString();
if (!string.IsNullOrEmpty(packageName))
{
return packageName;
}
}
}
catch (Exception ex)
{
_logger.LogWarning(ex, "Failed to parse package.json at {PackageJsonPath}. Falling back to directory name.", packageJsonPath);
}
}

// Fallback to directory name if package.json reading fails
return Path.GetFileName(packagePath);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,6 @@ public interface ILanguageChecks
/// <param name="ct">Cancellation token</param>
/// <returns>Result of the code formatting operation</returns>
Task<CLICheckResponse> FormatCodeAsync(string packagePath, bool fixCheckErrors = false, CancellationToken ct = default);

/// <summary>
/// Gets the SDK package path for the given repository and package path.
/// </summary>
/// <param name="repo">Repository root path</param>
/// <param name="packagePath">Package path</param>
/// <returns>SDK package path</returns>
string GetSDKPackagePath(string repo, string packagePath);
}

/// <summary>
Expand Down Expand Up @@ -233,6 +225,12 @@ protected async Task<CLICheckResponse> ValidateChangelogCommonAsync(string packa
return errorResponse;
}

var languageSpecificCheck = await _languageSpecificChecks.Resolve(packagePath);
if (languageSpecificCheck == null)
{
return new CLICheckResponse(1, "", $"No language-specific check handler found for package at {packagePath}. Supported languages may not include this package type.");
}

// Construct the path to the PowerShell script in the SDK repository
var scriptPath = Path.Combine(packageRepoRoot, "eng", "common", "scripts", "Verify-ChangeLog.ps1");

Expand All @@ -242,7 +240,7 @@ protected async Task<CLICheckResponse> ValidateChangelogCommonAsync(string packa
}

var command = "pwsh";
var args = new[] { "-File", scriptPath, "-PackageName", this.GetSDKPackagePath(packageRepoRoot, packagePath) };
var args = new[] { "-File", scriptPath, "-PackageName", await languageSpecificCheck.GetSDKPackageName(packageRepoRoot, packagePath, ct) };

// Use a longer timeout for changelog validation - 5 minutes should be sufficient
var timeout = TimeSpan.FromMinutes(5);
Expand Down Expand Up @@ -370,11 +368,6 @@ protected async Task<CLICheckResponse> CheckSpellingCommonAsync(string packagePa
}
}

public virtual string GetSDKPackagePath(string repo, string packagePath)
{
return Path.GetFileName(packagePath);
}

/// <summary>
/// Result of the spelling fix microagent operation.
/// </summary>
Expand Down