diff options
Diffstat (limited to 'src/marlin.web/Services/VersionControlSyncService.cs')
| -rw-r--r-- | src/marlin.web/Services/VersionControlSyncService.cs | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/src/marlin.web/Services/VersionControlSyncService.cs b/src/marlin.web/Services/VersionControlSyncService.cs index bf189b0..cd75ed6 100644 --- a/src/marlin.web/Services/VersionControlSyncService.cs +++ b/src/marlin.web/Services/VersionControlSyncService.cs @@ -207,8 +207,9 @@ public class VersionControlSyncService : BackgroundService foreach (VersionControlledCommit commit in refs.Select(x => x.Commit)) { - var blobNames = await client.ListTree(localPath, commit.Hash, "."); - + var blobNames = await client.ListTree(localPath, commit.Hash, ".marlin"); + var workflowFiles = new List<string>(); + foreach (string blobName in blobNames) { var content = await client.CatFile(localPath, commit.Hash, blobName); @@ -219,9 +220,40 @@ public class VersionControlSyncService : BackgroundService Path = blobName, Content = content }); + + if (blobName.EndsWith(".yml", StringComparison.OrdinalIgnoreCase) || + blobName.EndsWith(".yaml", StringComparison.OrdinalIgnoreCase)) + workflowFiles.Add(Encoding.UTF8.GetString(content)); } - + commit.BlobsFetched = true; + + this.ScanWorkflow(dbContext, commit, workflowFiles); + } + } + + private void ScanWorkflow(ApplicationDbContext dbContext, VersionControlledCommit commit, List<string> workflowFiles) + { + try + { + var builder = new WorkflowBuilder(); + foreach (var file in workflowFiles) + builder.LoadFromString(file); + + dbContext.WorkflowSnapshots.Add(new WorkflowSnapshot + { + Commit = commit, + ScannedAt = DateTime.UtcNow, + Workflow = builder.Build() + }); + } + catch (Exception ex) + { + this._logger.LogWarning(ex, "Failed to parse workflow for commit '{hash}'", commit.Hash); + } + finally + { + commit.WorkflowScanned = true; } } }
\ No newline at end of file |
