Azure / Azure/azure-sdk-tools

[APIView] azsdk apiview should auto-detect environment from URL

Open
#13,655 0 comments 1 reaction 2 assignees Claimed by @swathipil View on GitHub
enhancement
Dominant language
C#
Stars
135
Forks
260
Avg merge
3d 1h
Merged PRs (30d)
144

Description

## Problem

The `azsdk_apiview_get_comments` tool currently uses the `APIVIEW_ENVIRONMENT` environment variable to determine which APIView backend to connect to (production, staging, or local). This means users must manually set the environment variable to match the URL they're querying.

For example, querying `https://spa.apiviewstagingtest.com/review/...` while `APIVIEW_ENVIRONMENT` defaults to `production` will hit the wrong backend and return empty results.

## Proposed Solution

Auto-detect the environment from the input URL:

```csharp
private static string GetEnvironmentFromUrl(string url)
{
if (url.Contains("apiviewstagingtest.com")) return "staging";
if (url.Contains("localhost")) return "local";
return "production"; // apiview.dev
}
```

## Files to Modify

1. **`tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/APIView/APIViewReviewTool.cs`** - Extract environment from the URL parameter
2. **`tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/APIView/APIViewService.cs`** - Accept environment as a parameter in `GetCommentsByRevisionAsync` and `GetRevisionContent`
3. **`tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/APIView/APIViewHttpService.cs`** - Accept environment as a parameter in `GetAsync` instead of reading from env var

## Current Behavior

- `APIVIEW_ENVIRONMENT` env var determines backend (defaults to `production`)
- URL domain is ignored
- Users must manually set env var for staging/local URLs

## Expected Behavior

- Environment is auto-detected from the URL domain
- `APIVIEW_ENVIRONMENT` can still be used as an override if needed
- Works seamlessly for production, staging, and local URLs

## Reference

Current configuration in `APIViewConfiguration.cs`:
```csharp
public static readonly Dictionary BaseUrlEndpoints = new()
{
{ "production", "https://apiview.dev" },
{ "staging", "https://apiviewstagingtest.com" },
{ "local", "http://localhost:5000" }
};
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.