| 1 | using AgentForge.Data; |
| 2 | using AgentForge.Models; |
| 3 | using AgentForge.Options; |
| 4 | using AgentForge.Plugin.Ci.Data; |
| 5 | using Microsoft.Extensions.Options; |
| 6 | |
| 7 | namespace AgentForge.Plugin.Ci.Execution; |
| 8 | |
| 9 | internal static class ForgeCiKernelBridge |
| 10 | { |
| 11 | internal static void SyncAggregate( |
| 12 | ForgeRepository repository, |
| 13 | ForgeCiPipelineRunRecord run, |
| 14 | string repoName, |
| 15 | string status, |
| 16 | IOptions<ForgeOptions> options) |
| 17 | { |
| 18 | var kernelStatus = MapKernelStatus(status); |
| 19 | var baseUrl = options.Value.PublicBaseUrl.TrimEnd('/'); |
| 20 | var url = $"{baseUrl}/view/repos/{ForgeRepoNames.ToUrlPath(repoName)}/ci/runs/{Uri.EscapeDataString(run.Id)}"; |
| 21 | var commit = string.IsNullOrWhiteSpace(run.Commit) ? run.Ref : run.Commit; |
| 22 | repository.UpsertCiRun(run.RepoId, run.MrNumber, commit, kernelStatus, url); |
| 23 | } |
| 24 | |
| 25 | private static CiRunStatus MapKernelStatus(string status) => |
| 26 | status switch |
| 27 | { |
| 28 | ForgeCiRunStatusSlugs.Success => CiRunStatus.Success, |
| 29 | ForgeCiRunStatusSlugs.Failure => CiRunStatus.Failure, |
| 30 | ForgeCiRunStatusSlugs.Cancelled => CiRunStatus.Cancelled, |
| 31 | _ => CiRunStatus.Pending, |
| 32 | }; |
| 33 | } |
| 34 | |