-
Notifications
You must be signed in to change notification settings - Fork 11
Feature/afshin/add sync GitHub #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
afshinalizadeh
wants to merge
26
commits into
develop
Choose a base branch
from
feature/afshin/add-sync-github
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
1b836d7
Add CrystaDocument
afshinalizadeh 8d444f9
Initial plan
Copilot 5e98104
Implement GithubSyncService with interface and tests
Copilot 41f0887
Update documentation to reflect GithubSyncService implementation
Copilot b720477
Merge pull request #112 from cs-internship/copilot/add-github-sync-se…
afshinalizadeh 72586da
Refactor document sync to use ICrystaDocumentService
afshinalizadeh b3b5210
Add DisplayCode To CrystaDocument
afshinalizadeh d268acf
Enhance document content loading from GitHub URLs
afshinalizadeh 583159f
Update document sync logic and indexing for consistency
afshinalizadeh 440c938
Add document retrieval by CrystaUrl and program code
afshinalizadeh f363a65
Update src/Core/CrystaLearn.Core.Test/Sync/GithubSyncServiceTests.cs
afshinalizadeh 74c23f2
Update src/Core/CrystaLearn.Core/Services/Sync/GithubSyncService.cs
afshinalizadeh e2f4c5c
Standardize GitHub sync service naming; add doc retrieval
afshinalizadeh 8ff53a4
Update .vscode/tasks.json
afshinalizadeh 8f764a6
Initial plan
Copilot 702d8ed
Add null checks for SyncId in GithubSyncService
Copilot 5d50b94
Make null check logic consistent using IsNullOrWhiteSpace
Copilot 9db3a1f
Merge pull request #114 from cs-internship/copilot/sub-pr-113
afshinalizadeh 543a77a
Initial plan
Copilot 9f0628a
Fix static field modification in instance constructor
Copilot ffae89b
Add thread-safety and improve code quality
Copilot f74ef3e
Add CancellationToken support to UpdateSyncModuleAsync
Copilot e7b5014
Implement IDisposable for proper resource cleanup
Copilot 482ee1d
Add CancellationToken to EnsureInitializedAsync in Fake service
Copilot dd2de65
Merge pull request #115 from cs-internship/copilot/sub-pr-113-again
afshinalizadeh 3e48a20
Register CrystaDocumentServiceFake in SyncGithubDocuments_WithValidMo…
afshinalizadeh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,46 +1,46 @@ | ||
| { | ||
| "version": "2.0.0", | ||
| "tasks": [ | ||
| { | ||
| "label": "before-build", | ||
| "type": "shell", | ||
| "command": "dotnet build src/Client/CrystaLearn.Client.Core/CrystaLearn.Client.Core.csproj -t:BeforeBuildTasks", | ||
| "runOptions": { | ||
| "runOn": "folderOpen" | ||
| } | ||
| }, | ||
| { | ||
| "label": "build", | ||
| "type": "shell", | ||
| "command": "dotnet build src/Server/CrystaLearn.Server.Web/CrystaLearn.Server.Web.csproj" | ||
| }, | ||
| { | ||
| "label": "generate-resx-files", | ||
| "type": "shell", | ||
| "command": "dotnet build src/Shared/CrystaLearn.Shared.csproj -t:PrepareResources" | ||
| }, | ||
| { | ||
| "label": "run", | ||
| "type": "shell", | ||
| "command": "dotnet", | ||
| "args": [ | ||
| "run" | ||
| ], | ||
| "options": { | ||
| "cwd": "${workspaceFolder}/src/Server/CrystaLearn.Server.Web" | ||
| }, | ||
| "isBackground": true | ||
| }, | ||
| { | ||
| "label": "run-tests", | ||
| "type": "shell", | ||
| "command": "dotnet", | ||
| "args": [ | ||
| "test" | ||
| ], | ||
| "options": { | ||
| "cwd": "${workspaceFolder}/src/Tests" | ||
| } | ||
| } | ||
| ] | ||
| "version": "2.0.0", | ||
| "tasks": [ | ||
| { | ||
| "label": "before-build", | ||
| "type": "shell", | ||
| "command": "dotnet build src/Client/CrystaLearn.Client.Core/CrystaLearn.Client.Core.csproj -t:BeforeBuildTasks", | ||
| "runOptions": { | ||
| "runOn": "folderOpen" | ||
| } | ||
| }, | ||
| { | ||
| "label": "build", | ||
| "type": "shell", | ||
| "command": "dotnet build src/Server/CrystaLearn.Server.Web/CrystaLearn.Server.Web.csproj" | ||
| }, | ||
| { | ||
| "label": "generate-resx-files", | ||
| "type": "shell", | ||
| "command": "dotnet build src/Shared/CrystaLearn.Shared.csproj -t:PrepareResources" | ||
| }, | ||
| { | ||
| "label": "run", | ||
| "type": "shell", | ||
| "command": "dotnet", | ||
| "args": [ | ||
| "run" | ||
| ], | ||
| "options": { | ||
| "cwd": "${workspaceFolder}/src/Server/CrystaLearn.Server.Web" | ||
| }, | ||
| "isBackground": true | ||
| }, | ||
| { | ||
| "label": "run-tests", | ||
| "type": "shell", | ||
| "command": "dotnet", | ||
| "args": [ | ||
| "test" | ||
| ], | ||
| "options": { | ||
| "cwd": "${workspaceFolder}/src/Tests" | ||
| } | ||
| } | ||
| ] | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
src/Core/CrystaLearn.Core.Test/Sync/GithubSyncServiceTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| using CrystaLearn.Core.Extensions; | ||
| using CrystaLearn.Core.Models.Crysta; | ||
| using CrystaLearn.Core.Services; | ||
| using CrystaLearn.Core.Services.Contracts; | ||
| using CrystaLearn.Core.Services.Sync; | ||
| using CrystaLearn.Core.Tests.Infra; | ||
|
|
||
| namespace CrystaLearn.Core.Tests.Sync; | ||
|
|
||
| public class GitHubSyncServiceTests : TestBase | ||
| { | ||
| [Fact] | ||
| public async Task SyncGithubDocuments_WithValidModule_MustWork() | ||
| { | ||
| // Arrange | ||
| var services = CreateServiceProvider(configServices: (sc) => | ||
| { | ||
| sc.AddTransient<ICrystaProgramSyncModuleService, CrystaProgramSyncModuleServiceFake>(); | ||
| sc.AddTransient<ICrystaProgramRepository, CrystaProgramServiceFake>(); | ||
| sc.AddTransient<ICrystaDocumentService, CrystaDocumentServiceFake>(); | ||
| sc.AddSingleton<IDocumentRepository, DocumentRepositoryInMemory>(); | ||
| }); | ||
|
|
||
| using var scope = services.CreateScope(); | ||
| var service = scope.ServiceProvider.GetRequiredService<IGitHubSyncService>(); | ||
| var programRepo = scope.ServiceProvider.GetRequiredService<ICrystaProgramRepository>(); | ||
|
|
||
| // Get a test program | ||
| var programs = await programRepo.GetCrystaProgramsAsync(CancellationToken.None); | ||
| var testProgram = programs.FirstOrDefault(); | ||
|
|
||
| if (testProgram == null) | ||
| { | ||
| // Skip test if no programs available | ||
| return; | ||
| } | ||
|
|
||
| var module = new CrystaProgramSyncModule | ||
| { | ||
| Id = Guid.NewGuid(), | ||
| CrystaProgramId = testProgram.Id, | ||
| CrystaProgram = testProgram, | ||
| ModuleType = SyncModuleType.GitHubDocument, | ||
| SyncInfo = new SyncInfo | ||
| { | ||
| LastSyncDateTime = DateTimeOffset.Now.AddYears(-1), | ||
| LastSyncOffset = "0" | ||
| } | ||
| }; | ||
|
|
||
| // Act | ||
| var result = await service.SyncAsync(module); | ||
|
|
||
| // Assert | ||
| Assert.NotNull(result); | ||
| Assert.True(result.AddCount >= 0); | ||
| Assert.True(result.UpdateCount >= 0); | ||
| Assert.True(result.SameCount >= 0); | ||
| Assert.True(result.DeleteCount >= 0); | ||
| } | ||
|
|
||
| [Fact] | ||
| public async Task SyncGithubDocuments_WithInvalidModuleType_MustThrowException() | ||
| { | ||
| // Arrange | ||
| var services = CreateServiceProvider(configServices: (sc) => | ||
| { | ||
| sc.AddTransient<ICrystaProgramSyncModuleService, CrystaProgramSyncModuleServiceFake>(); | ||
| sc.AddSingleton<IDocumentRepository, DocumentRepositoryInMemory>(); | ||
| }); | ||
|
|
||
| using var scope = services.CreateScope(); | ||
| var service = scope.ServiceProvider.GetRequiredService<IGitHubSyncService>(); | ||
|
|
||
| var module = new CrystaProgramSyncModule | ||
| { | ||
| Id = Guid.NewGuid(), | ||
| ModuleType = SyncModuleType.AzureBoard, // Wrong type | ||
| SyncInfo = new SyncInfo() | ||
| }; | ||
|
|
||
| // Act & Assert | ||
| await Assert.ThrowsAsync<InvalidOperationException>(async () => | ||
| await service.SyncAsync(module)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
src/Core/CrystaLearn.Core/Data/Configurations/Crysta/CrystaDocumentConfiguration.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| using CrystaLearn.Core.Models.Crysta; | ||
|
|
||
| namespace CrystaLearn.Core.Data.Configurations.Crysta; | ||
|
|
||
| public class CrystaDocumentConfiguration : IEntityTypeConfiguration<CrystaDocument> | ||
| { | ||
| public void Configure(EntityTypeBuilder<CrystaDocument> builder) | ||
| { | ||
| //builder.HasIndex(d => d.Code).IsUnique(); | ||
| builder.HasIndex(d => d.IsActive); | ||
| builder.HasIndex(d => d.CrystaProgramId); | ||
|
|
||
| builder.HasOne(d => d.CrystaProgram) | ||
| .WithMany() | ||
| .HasForeignKey(d => d.CrystaProgramId); | ||
|
|
||
| builder.OwnsOne(d => d.SyncInfo, sync => | ||
| { | ||
| sync.HasIndex(s => s.SyncId).IsUnique(); | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Inconsistent naming: the service is named "GithubSyncService" but the documentation refers to it as "GithubSyncService" (lowercase 'h'). The standard casing should be "GitHub" with a capital 'H'. This inconsistency appears throughout the codebase.