Skip to content

Commit 9d9363f

Browse files
smw-msCopilot
andauthored
Add pr link validation for get_release_plan_for_spec_pr (#11984)
* Add pr link validation for get_release_plan_for_spec_pr * Update tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/ReleasePlan/ReleasePlanTool.cs Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent b0232b5 commit 9d9363f

2 files changed

Lines changed: 37 additions & 9 deletions

File tree

tools/azsdk-cli/Azure.Sdk.Tools.Cli.Tests/Tools/ReleasePlanToolTests.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ public async Task Test_Create_releasePlan_with_valid_inputs()
100100
Assert.IsNotNull(releaseplan);
101101
Assert.True(releaseplan.Contains("Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem"));
102102

103-
releaseplan = await releasePlanTool.CreateReleasePlan(testCodeFilePath, "July 2025", "12345678-1234-5678-9012-123456789012", "12345678-1234-5678-9012-123456789012", "2025-01-01-preview", "https://github.com/Azure/azure-rest-api-specs/pull/35446", "beta", isTestReleasePlan: true);
103+
releaseplan = await releasePlanTool.CreateReleasePlan(testCodeFilePath, "July 2025", "12345678-1234-5678-9012-123456789012", "12345678-1234-5678-9012-123456789012", "2025-01-01-preview", "https://github.com/Azure/azure-rest-api-specs-pr/pull/35446", "beta", isTestReleasePlan: true);
104104
Assert.IsNotNull(releaseplan);
105105
Assert.True(releaseplan.Contains("Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem"));
106106
}
@@ -179,6 +179,25 @@ public async Task Test_Create_releasePlan_with_AZSDKTOOLS_AGENT_TESTING_false_re
179179
environmentHelperMock.Verify(x => x.GetBooleanVariable("AZSDKTOOLS_AGENT_TESTING", false), Times.Once);
180180
}
181181

182+
[Test]
183+
public async Task Test_Get_Release_Plan_For_Pull_Request_with_valid_inputs()
184+
{
185+
var releaseplan = await releasePlanTool.GetReleasePlanForPullRequest("https://github.com/Azure/azure-rest-api-specs/pull/35446");
186+
Assert.True(releaseplan.Contains("Status: Success"));
187+
Assert.True(releaseplan.Contains("Release Plan"));
188+
189+
releaseplan = await releasePlanTool.GetReleasePlanForPullRequest("https://github.com/Azure/azure-rest-api-specs-pr/pull/35446");
190+
Assert.True(releaseplan.Contains("Status: Success"));
191+
Assert.True(releaseplan.Contains("Release Plan"));
192+
}
193+
194+
[Test]
195+
public async Task Test_Get_Release_Plan_For_Pull_Request_with_invalid_pr_link()
196+
{
197+
var releaseplan = await releasePlanTool.GetReleasePlanForPullRequest("invalid-pr-link");
198+
Assert.True(releaseplan.Contains("Failed to get release plan details"));
199+
}
200+
182201
[Test]
183202
public async Task Test_Update_SDK_Details_In_Release_Plan()
184203
{

tools/azsdk-cli/Azure.Sdk.Tools.Cli/Tools/ReleasePlan/ReleasePlanTool.cs

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -59,18 +59,22 @@ public partial class ReleasePlanTool(IDevOpsService devOpsService, ITypeSpecHelp
5959
[McpServerTool(Name = "azsdk_get_release_plan_for_spec_pr"), Description("Get release plan for API spec pull request. This tool should be used only if work item Id is unknown.")]
6060
public async Task<string> GetReleasePlanForPullRequest(string pullRequestLink)
6161
{
62+
var response = new GenericResponse();
63+
6264
try
6365
{
64-
List<string> releasePlanList = [];
65-
var releasePlan = await devOpsService.GetReleasePlanAsync(pullRequestLink);
66-
var _out = releasePlan == null ? "Failed to get release plan details." :
67-
$"Release Plan: {JsonSerializer.Serialize(releasePlan)}";
68-
return output.Format(_out);
66+
ValidatePullRequestUrl(pullRequestLink);
67+
var releasePlan = await devOpsService.GetReleasePlanAsync(pullRequestLink) ?? throw new Exception("No release plan associated with pull request link");
68+
response.Status = "Success";
69+
response.Details.Add($"Release Plan: {JsonSerializer.Serialize(releasePlan)}");
70+
return output.Format(response);
6971
}
7072
catch (Exception ex)
7173
{
7274
logger.LogError("Failed to get release plan details: {exception}", ex.Message);
73-
return output.Format($"Failed to get release plan details: {ex.Message}");
75+
response.Status = "Failed";
76+
response.Details.Add($"Failed to get release plan details: {ex.Message}");
77+
return output.Format(response);
7478
}
7579
}
7680

@@ -152,9 +156,8 @@ public async Task<string> GetReleasePlan(int workItem = 0, int releasePlanId = 0
152156
}
153157
}
154158

155-
private async Task ValidateCreateReleasePlanInputAsync(string typeSpecProjectPath, string serviceTreeId, string productTreeId, string specPullRequestUrl, string sdkReleaseType, string specApiVersion)
159+
private void ValidatePullRequestUrl(string specPullRequestUrl)
156160
{
157-
// Check for existing release plan for the given pull request URL.
158161
if (string.IsNullOrEmpty(specPullRequestUrl))
159162
{
160163
throw new Exception("API spec pull request URL is required to create a release plan.");
@@ -167,6 +170,12 @@ private async Task ValidateCreateReleasePlanInputAsync(string typeSpecProjectPat
167170
throw new Exception($"Invalid spec pull request URL '{specPullRequestUrl}' It should be a valid GitHub pull request to azure-rest-api-specs or azure-rest-api-specs-pr repo.");
168171
}
169172

173+
}
174+
175+
private async Task ValidateCreateReleasePlanInputAsync(string typeSpecProjectPath, string serviceTreeId, string productTreeId, string specPullRequestUrl, string sdkReleaseType, string specApiVersion)
176+
{
177+
ValidatePullRequestUrl(specPullRequestUrl);
178+
// Check for existing release plan for the given pull request URL.
170179
logger.LogInformation("Checking for existing release plan for pull request URL: {specPullRequestUrl}", specPullRequestUrl);
171180
var existingReleasePlan = await devOpsService.GetReleasePlanAsync(specPullRequestUrl);
172181
if (existingReleasePlan != null && existingReleasePlan.WorkItemId > 0)

0 commit comments

Comments
 (0)