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
1 change: 1 addition & 0 deletions src/Microsoft.DotNet.Darc/DarcLib/AzureDevOpsClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2004,6 +2004,7 @@ public async Task<IReadOnlyCollection<string>> GetGitTreeNames(string path, stri
},
UpdatedAt = DateTimeOffset.UtcNow,
HeadBranchSha = pr.LastMergeSourceCommit.CommitId,
CreationDate = pr.CreationDate,
};

public async Task<List<string>> ListFilesAtCommitAsync(string repoUri, string commit, string path)
Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.DotNet.Darc/DarcLib/GitHubClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1491,6 +1491,7 @@ private static PullRequest ToDarcLibPullRequest(Octokit.PullRequest pr)
Status = status,
UpdatedAt = pr.UpdatedAt,
HeadBranchSha = pr.Head.Sha,
CreationDate = pr.CreatedAt,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/Microsoft.DotNet.Darc/DarcLib/IRemoteGitRepo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,5 @@ public class PullRequest
public PrStatus Status { get; set; }
public DateTimeOffset UpdatedAt { get; set; }
public string HeadBranchSha { get; set; }
public DateTimeOffset CreationDate { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,8 @@ public TrackedPullRequest(bool sourceEnabled, DateTimeOffset lastUpdate, DateTim

[JsonProperty("nextBuildsToApply")]
public Dictionary<Guid, int> NextBuildsToApply { get; set; }

[JsonProperty("creationDate")]
public DateTimeOffset CreationDate { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,8 @@ [.. pr.ContainedSubscriptions
csu.SubscriptionId,
csu.BuildId))],
pr.HeadBranch,
pr.NextBuildsToProcess);
pr.NextBuildsToProcess,
pr.CreationDate);
}

private record TrackedPullRequest(
Expand All @@ -253,7 +254,8 @@ private record TrackedPullRequest(
DateTime? NextCheck,
List<PullRequestUpdate> Updates,
string HeadBranch,
Dictionary<Guid, int> NextBuildsToApply);
Dictionary<Guid, int> NextBuildsToApply,
DateTime CreationDate);

private record PullRequestUpdate(
string SourceRepository,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@
<TemplateColumn Title="Target branch" Sortable="true" SortBy="SortBy(pr => pr.TargetBranch)" Align="Align.Center">
<FluentLabel>@(context.TargetBranch ?? "N/A")</FluentLabel>
</TemplateColumn>
<TemplateColumn Title="Created" Sortable="true" SortBy="@SortBy(pr => pr.CreationDate.ToString("o"))" Align="Align.Center">
<FluentLabel Title="@(context.CreationDate == default ? "N/A" : context.CreationDate.ToString("f"))">
@(context.CreationDate == default ? "N/A" : (DateTime.UtcNow - context.CreationDate).ToTimeAgo())
</FluentLabel>
</TemplateColumn>
<TemplateColumn Title="Last Update" Sortable="true" SortBy="@SortBy(pr => pr.LastUpdate.ToString("o"))" Align="Align.Center">
<FluentLabel Title="@(context.LastUpdate == default ? "N/A" : context.LastUpdate.ToString("f"))">
@(context.LastUpdate == default ? "N/A" : (DateTime.UtcNow - context.LastUpdate).ToTimeAgo())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,6 @@ public class InProgressPullRequest : DependencyFlowWorkItem
public CodeFlowDirection CodeFlowDirection { get; set; }

public bool BlockedFromFutureUpdates { get; set; } = false;

public DateTime CreationDate { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,11 @@ public async Task ProcessPendingUpdatesAsync(SubscriptionUpdateWorkItem update,
return;
}

var pullRequest = await GetPullRequestStatusAsync(pr, isCodeFlow, tryingToUpdate: true);
prInfo = pullRequest.PrInfo;
switch (pullRequest.Status)
(var status, prInfo) = await GetPullRequestStatusAsync(pr, isCodeFlow, tryingToUpdate: true);

await UpdatePullRequestCreationDateAsync(pr, prInfo.CreationDate.UtcDateTime);

switch (status)
{
case PullRequestStatus.Completed:
case PullRequestStatus.Invalid:
Expand All @@ -202,7 +204,7 @@ public async Task ProcessPendingUpdatesAsync(SubscriptionUpdateWorkItem update,
await ScheduleUpdateForLater(pr, update, isCodeFlow);
return;
default:
throw new NotImplementedException($"Unknown PR status {pullRequest.Status}");
throw new NotImplementedException($"Unknown PR status {status}");
}
}

Expand Down Expand Up @@ -267,11 +269,22 @@ public async Task<bool> CheckPullRequestAsync(PullRequestCheck pullRequestCheck)
return await CheckInProgressPullRequestAsync(inProgressPr, pullRequestCheck.IsCodeFlow);
}

protected virtual async Task<bool> CheckInProgressPullRequestAsync(InProgressPullRequest pullRequestCheck, bool isCodeFlow)
protected virtual async Task<bool> CheckInProgressPullRequestAsync(InProgressPullRequest pr, bool isCodeFlow)
{
_logger.LogInformation("Checking in-progress pull request {url}", pullRequestCheck.Url);
var pr = await GetPullRequestStatusAsync(pullRequestCheck, isCodeFlow, tryingToUpdate: false);
return pr.Status != PullRequestStatus.Invalid;
_logger.LogInformation("Checking in-progress pull request {url}", pr.Url);
(var status, var prInfo) = await GetPullRequestStatusAsync(pr, isCodeFlow, tryingToUpdate: false);
await UpdatePullRequestCreationDateAsync(pr, prInfo.CreationDate.UtcDateTime);
return status != PullRequestStatus.Invalid;
}

private async Task UpdatePullRequestCreationDateAsync(InProgressPullRequest pr, DateTime creationDate)
{
//todo this is a temporary solution to update existing PRs, it can be removed after all existing PRs get a creation date
if (pr.CreationDate == creationDate)
{
pr.CreationDate = creationDate;
await _pullRequestState.SetAsync(pr);
}
}

protected virtual Task TagSourceRepositoryGitHubContactsIfPossibleAsync(InProgressPullRequest pr)
Expand Down Expand Up @@ -617,6 +630,7 @@ private async Task AddDependencyFlowEventsAsync(
CoherencyCheckSuccessful = false,
CoherencyErrors = aggregatedCoherencyErrors.Count > 0 ? aggregatedCoherencyErrors : null,
CodeFlowDirection = CodeFlowDirection.None,
CreationDate = DateTime.UtcNow,
};

await SetPullRequestCheckReminder(inProgressPr, pr, isCodeFlow);
Expand Down Expand Up @@ -671,6 +685,7 @@ private async Task AddDependencyFlowEventsAsync(
CoherencyCheckSuccessful = repoDependencyUpdates.CoherencyCheckSuccessful,
CoherencyErrors = aggregatedCoherencyErrors.Count > 0 ? aggregatedCoherencyErrors : null,
CodeFlowDirection = CodeFlowDirection.None,
CreationDate = DateTime.UtcNow,
};

if (!string.IsNullOrEmpty(pr?.Url))
Expand Down Expand Up @@ -1389,6 +1404,7 @@ private async Task UpdateCodeFlowPullRequestAsync(
CodeFlowDirection = subscription.IsForwardFlow()
? CodeFlowDirection.ForwardFlow
: CodeFlowDirection.BackFlow,
CreationDate = DateTime.UtcNow,
};

await AddDependencyFlowEventsAsync(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public void UpdaterTests_TearDown()
pr.LastCheck = (ExpectedPRCacheState[pair.Key] as InProgressPullRequest)!.LastCheck;
pr.LastUpdate = (ExpectedPRCacheState[pair.Key] as InProgressPullRequest)!.LastUpdate;
pr.NextCheck = (ExpectedPRCacheState[pair.Key] as InProgressPullRequest)!.NextCheck;
pr.CreationDate = (ExpectedPRCacheState[pair.Key] as InProgressPullRequest)!.CreationDate;
}
}
Cache.Data.Where(pair => pair.Value is InProgressPullRequest).Should().BeEquivalentTo(ExpectedPRCacheState);
Expand Down