OPC # 0006: OPC Git Trunk-Based management
Co-authored-by: Copilot <copilot@github.com>
This commit is contained in:
@@ -787,6 +787,64 @@ public class PromotionService(IConfiguration config, ILogger<PromotionService> l
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns distinct, sorted OPC numbers for commits reachable from <paramref name="toSha"/>
|
||||
/// that are NOT reachable from <paramref name="fromSha"/> — i.e. the exact delta for this release.
|
||||
/// Falls back to <see cref="ExtractOpcNumbersAsync"/> (last 50 commits) when <paramref name="fromSha"/>
|
||||
/// is null (first-ever release for this environment).
|
||||
/// </summary>
|
||||
public Task<List<string>> ExtractOpcNumbersDeltaAsync(
|
||||
string repoName,
|
||||
string toSha,
|
||||
string? fromSha,
|
||||
CancellationToken ct = default) =>
|
||||
fromSha is null
|
||||
? ExtractOpcNumbersAsync(repoName, ct: ct)
|
||||
: Task.Run(() => ExtractOpcNumbersDeltaCore(repoName, toSha, fromSha), ct);
|
||||
|
||||
private List<string> ExtractOpcNumbersDeltaCore(string repoName, string toSha, string fromSha)
|
||||
{
|
||||
var repoPath = GetRepoPath(repoName);
|
||||
if (string.IsNullOrWhiteSpace(repoPath) || !Directory.Exists(repoPath))
|
||||
return [];
|
||||
try
|
||||
{
|
||||
using var repo = new Repository(repoPath);
|
||||
var toCommit = repo.Lookup<Commit>(toSha);
|
||||
var fromCommit = repo.Lookup<Commit>(fromSha);
|
||||
if (toCommit is null) return [];
|
||||
|
||||
var filter = fromCommit is null
|
||||
? new CommitFilter { IncludeReachableFrom = toCommit }
|
||||
: new CommitFilter { IncludeReachableFrom = toCommit, ExcludeReachableFrom = fromCommit };
|
||||
|
||||
var set = new HashSet<string>(StringComparer.Ordinal);
|
||||
foreach (var commit in repo.Commits.QueryBy(filter))
|
||||
foreach (System.Text.RegularExpressions.Match m in OpcTagPattern.Matches(commit.Message))
|
||||
set.Add($"OPC # {m.Groups[1].Value.PadLeft(4, '0')}");
|
||||
|
||||
return [.. set.OrderBy(x => x)];
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogWarning(ex, "ExtractOpcNumbersDelta failed for {Repo} {From}..{To}", repoName, fromSha[..7], toSha[..7]);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Returns the full HEAD SHA of <paramref name="branch"/> in <paramref name="repoName"/>, or null.</summary>
|
||||
public string? GetBranchTipSha(string repoName, string branch)
|
||||
{
|
||||
var repoPath = GetRepoPath(repoName);
|
||||
if (string.IsNullOrWhiteSpace(repoPath) || !Directory.Exists(repoPath)) return null;
|
||||
try
|
||||
{
|
||||
using var repo = new Repository(repoPath);
|
||||
return (repo.Branches[$"origin/{branch}"] ?? repo.Branches[branch])?.Tip?.Sha;
|
||||
}
|
||||
catch { return null; }
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>A single unreleased commit — carries full SHA for cherry-pick operations.</summary>
|
||||
|
||||
Reference in New Issue
Block a user