Skip to content

Commit

Permalink
Remove cache entries for already merged PRs (#4239)
Browse files Browse the repository at this point in the history
  • Loading branch information
premun authored Dec 12, 2024
1 parent 0cf2c57 commit c9836e5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,21 @@ public partial class PullRequestController : ControllerBase
[GeneratedRegex(@"https://dev.azure.com/(?<org>[^/]+)/(?<project>[^/]+)/_apis/git/repositories/(?<repo>[^/]+)/pullRequests/(?<id>[0-9]+)/?")]
private static partial Regex AzdoApiPrUrlRegex();

private static readonly Dictionary<string, string> WellKnownIds = new()
{
["7ea9116e-9fac-403d-b258-b31fcf1bb293"] = "internal", // AzDO's dnceng/internal
};

private static string ResolveWellKnownIds(string str)
{
foreach (var pair in WellKnownIds)
{
str = str.Replace(pair.Key, pair.Value);
}

return str;
}

private readonly IRedisCacheFactory _cacheFactory;
private readonly BuildAssetRegistryContext _context;

Expand Down Expand Up @@ -88,7 +103,10 @@ private static string TurnApiUrlToWebsite(string url)
match = AzdoApiPrUrlRegex().Match(url);
if (match.Success)
{
return $"https://dev.azure.com/{match.Groups["org"]}/{match.Groups["project"]}/_git/{match.Groups["repo"]}/pullrequest/{match.Groups["id"]}";
var org = ResolveWellKnownIds(match.Groups["org"].Value);
var project = ResolveWellKnownIds(match.Groups["project"].Value);
var repo = ResolveWellKnownIds(match.Groups["repo"].Value);
return $"https://dev.azure.com/{org}/{project}/_git/{repo}/pullrequest/{match.Groups["id"]}";
}

return url;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ public async Task<bool> ProcessPendingUpdatesAsync(SubscriptionUpdateWorkItem up
case PullRequestStatus.Invalid:
// If the PR is completed, we will open a new one
pr = null;
await _pullRequestState.TryDeleteAsync();
await _pullRequestCheckReminders.UnsetReminderAsync(isCodeFlow);
break;
case PullRequestStatus.InProgressCanUpdate:
// If we can update it, we will do it below
Expand Down

0 comments on commit c9836e5

Please sign in to comment.