Skip to content

Fix PR links to use web URLs instead of API URLs#5454

Merged
premun merged 5 commits intomainfrom
copilot/fix-active-pr-links
Nov 10, 2025
Merged

Fix PR links to use web URLs instead of API URLs#5454
premun merged 5 commits intomainfrom
copilot/fix-active-pr-links

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 10, 2025

PR links on the subscriptions page were displaying GitHub API URLs (https://api.github.com/repos/dotnet/dotnet/pulls/3205) instead of web URLs (https://github.com/dotnet/dotnet/pull/3205).

Changes:

  • Modified ToTrackedPullRequest in PullRequestController.cs to apply the existing TurnApiUrlToWebsite method to PR URLs before returning them
  • Check the PR URL type directly using AzdoApiPrUrlRegex().IsMatch(pr.Url) to determine if org/repoName extraction is needed for Azure DevOps URLs
  • Added comprehensive unit tests for URL conversion (GitHub, Azure DevOps, and pass-through cases)
  • Refactored tests to use SetUp method and helper method with named parameters for better maintainability and clarity

The TurnApiUrlToWebsite method was already being used for source repository URLs but wasn't applied to the PR URL field itself.

Fixes #5453

Original prompt

This section details on the original issue you should resolve

<issue_title>Active PR links in subscription page lead to PR API links</issue_title>
<issue_description>The links from the subscriptions page lead to URI like this: https://api.github.com/repos/dotnet/dotnet/pulls/3205.
We'd rather they go to dotnet/dotnet#3205.

There is code somewhere already changing these formats so please re-use it.</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@premun premun marked this pull request as ready for review November 10, 2025 10:21
Copilot AI review requested due to automatic review settings November 10, 2025 10:21
@premun premun changed the title [WIP] Fix active PR links in subscription page Make active PR links in subscription page go to HTML URI Nov 10, 2025
Copilot AI changed the title Make active PR links in subscription page go to HTML URI Fix PR links to use web URLs instead of API URLs Nov 10, 2025
Copilot AI requested a review from premun November 10, 2025 10:23
Address review feedback to check if the PR URL itself is an Azure DevOps URL before extracting org/repoName, rather than checking the subscription's target repository type.

Co-authored-by: premun <[email protected]>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds test coverage for the TurnApiUrlToWebsite private method in PullRequestController and updates the ToTrackedPullRequest method to use this URL conversion function. The changes ensure that API URLs for pull requests are converted to their web equivalents for both GitHub and Azure DevOps.

  • Adds comprehensive unit tests for URL conversion from API format to web format
  • Updates ToTrackedPullRequest to convert PR URLs using organization and repository information
  • Extracts Azure DevOps organization and repository names to support proper URL conversion

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 10 comments.

File Description
test/ProductConstructionService.Api.Tests/PullRequestUrlConversionTests.cs Adds new test file with three test methods covering GitHub API URL conversion, Azure DevOps API URL conversion, and handling of non-API URLs
src/ProductConstructionService/ProductConstructionService.Api/Api/v2020_02_20/Controllers/PullRequestController.cs Updates ToTrackedPullRequest to extract org/repo information and use TurnApiUrlToWebsite for PR URL conversion
Comments suppressed due to low confidence (2)

src/ProductConstructionService/ProductConstructionService.Api/Api/v2020_02_20/Controllers/PullRequestController.cs:196

  • Missing space before concatenation operator. The line should be orgName + \"-\" + repoName for consistent formatting. Additionally, there's a critical bug: orgName can be null (line 213), but it's used here without null checking when concatenating strings. This will result in a literal "null-" prefix in the URL instead of a proper null check.
                WellKnownIds[match.Groups["repo"].Value] = orgName + "-" +repoName;

src/ProductConstructionService/ProductConstructionService.Api/Api/v2020_02_20/Controllers/PullRequestController.cs:224

  • Generic catch clause.
            catch
            {
                // Repos which do not conform to usual naming will not be handled
            }

Comment thread test/ProductConstructionService.Api.Tests/PullRequestUrlConversionTests.cs Outdated
Comment thread test/ProductConstructionService.Api.Tests/PullRequestUrlConversionTests.cs Outdated
Comment thread test/ProductConstructionService.Api.Tests/PullRequestUrlConversionTests.cs Outdated
Comment thread test/ProductConstructionService.Api.Tests/PullRequestUrlConversionTests.cs Outdated
Comment thread test/ProductConstructionService.Api.Tests/PullRequestUrlConversionTests.cs Outdated
Comment thread test/ProductConstructionService.Api.Tests/PullRequestUrlConversionTests.cs Outdated
Comment thread test/ProductConstructionService.Api.Tests/PullRequestUrlConversionTests.cs Outdated
- Extract reflection-based method lookup to SetUp method
- Add helper method InvokeTurnApiUrlToWebsite with named parameters for clarity
- Add XML documentation explaining the parameters

Co-authored-by: premun <[email protected]>
@premun premun merged commit 69a0a0b into main Nov 10, 2025
4 of 9 checks passed
@premun premun deleted the copilot/fix-active-pr-links branch November 10, 2025 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Active PR links in subscription page lead to PR API links

4 participants