Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public async Task Test_Create_releasePlan_with_valid_inputs()
Assert.IsNotNull(releaseplan);
Assert.True(releaseplan.Contains("Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem"));

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);
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);
Assert.IsNotNull(releaseplan);
Assert.True(releaseplan.Contains("Microsoft.TeamFoundation.WorkItemTracking.WebApi.Models.WorkItem"));
}
Expand Down Expand Up @@ -179,6 +179,25 @@ public async Task Test_Create_releasePlan_with_AZSDKTOOLS_AGENT_TESTING_false_re
environmentHelperMock.Verify(x => x.GetBooleanVariable("AZSDKTOOLS_AGENT_TESTING", false), Times.Once);
}

[Test]
public async Task Test_Get_Release_Plan_For_Pull_Request_with_valid_inputs()
{
var releaseplan = await releasePlanTool.GetReleasePlanForPullRequest("https://github.com/Azure/azure-rest-api-specs/pull/35446");
Assert.True(releaseplan.Contains("Status: Success"));
Assert.True(releaseplan.Contains("Release Plan"));

releaseplan = await releasePlanTool.GetReleasePlanForPullRequest("https://github.com/Azure/azure-rest-api-specs-pr/pull/35446");
Assert.True(releaseplan.Contains("Status: Success"));
Assert.True(releaseplan.Contains("Release Plan"));
}

[Test]
public async Task Test_Get_Release_Plan_For_Pull_Request_with_invalid_pr_link()
{
var releaseplan = await releasePlanTool.GetReleasePlanForPullRequest("invalid-pr-link");
Assert.True(releaseplan.Contains("Failed to get release plan details"));
}

[Test]
public async Task Test_Update_SDK_Details_In_Release_Plan()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,22 @@ public partial class ReleasePlanTool(IDevOpsService devOpsService, ITypeSpecHelp
[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.")]
public async Task<string> GetReleasePlanForPullRequest(string pullRequestLink)
{
var response = new GenericResponse();

try
{
List<string> releasePlanList = [];
var releasePlan = await devOpsService.GetReleasePlanAsync(pullRequestLink);
var _out = releasePlan == null ? "Failed to get release plan details." :
$"Release Plan: {JsonSerializer.Serialize(releasePlan)}";
return output.Format(_out);
ValidatePullRequestUrl(pullRequestLink);
var releasePlan = await devOpsService.GetReleasePlanAsync(pullRequestLink) ?? throw new Exception("No release plan associated with pull request link");
response.Status = "Success";
response.Details.Add($"Release Plan: {JsonSerializer.Serialize(releasePlan)}");
return output.Format(response);
}
catch (Exception ex)
{
logger.LogError("Failed to get release plan details: {exception}", ex.Message);
return output.Format($"Failed to get release plan details: {ex.Message}");
response.Status = "Failed";
response.Details.Add($"Failed to get release plan details: {ex.Message}");
return output.Format(response);
}
}

Expand Down Expand Up @@ -152,9 +156,8 @@ public async Task<string> GetReleasePlan(int workItem = 0, int releasePlanId = 0
}
}

private async Task ValidateCreateReleasePlanInputAsync(string typeSpecProjectPath, string serviceTreeId, string productTreeId, string specPullRequestUrl, string sdkReleaseType, string specApiVersion)
private void ValidatePullRequestUrl(string specPullRequestUrl)
{
// Check for existing release plan for the given pull request URL.
if (string.IsNullOrEmpty(specPullRequestUrl))
{
throw new Exception("API spec pull request URL is required to create a release plan.");
Expand All @@ -167,6 +170,12 @@ private async Task ValidateCreateReleasePlanInputAsync(string typeSpecProjectPat
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.");
}

}

private async Task ValidateCreateReleasePlanInputAsync(string typeSpecProjectPath, string serviceTreeId, string productTreeId, string specPullRequestUrl, string sdkReleaseType, string specApiVersion)
{
ValidatePullRequestUrl(specPullRequestUrl);
// Check for existing release plan for the given pull request URL.
logger.LogInformation("Checking for existing release plan for pull request URL: {specPullRequestUrl}", specPullRequestUrl);
var existingReleasePlan = await devOpsService.GetReleasePlanAsync(specPullRequestUrl);
if (existingReleasePlan != null && existingReleasePlan.WorkItemId > 0)
Expand Down
Loading