Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1b836d7
Add CrystaDocument
afshinalizadeh Dec 20, 2025
8d444f9
Initial plan
Copilot Dec 20, 2025
5e98104
Implement GithubSyncService with interface and tests
Copilot Dec 20, 2025
41f0887
Update documentation to reflect GithubSyncService implementation
Copilot Dec 20, 2025
b720477
Merge pull request #112 from cs-internship/copilot/add-github-sync-se…
afshinalizadeh Dec 20, 2025
72586da
Refactor document sync to use ICrystaDocumentService
afshinalizadeh Dec 26, 2025
b3b5210
Add DisplayCode To CrystaDocument
afshinalizadeh Dec 26, 2025
d268acf
Enhance document content loading from GitHub URLs
afshinalizadeh Dec 26, 2025
583159f
Update document sync logic and indexing for consistency
afshinalizadeh Dec 26, 2025
440c938
Add document retrieval by CrystaUrl and program code
afshinalizadeh Dec 26, 2025
f363a65
Update src/Core/CrystaLearn.Core.Test/Sync/GithubSyncServiceTests.cs
afshinalizadeh Dec 26, 2025
74c23f2
Update src/Core/CrystaLearn.Core/Services/Sync/GithubSyncService.cs
afshinalizadeh Dec 26, 2025
e2f4c5c
Standardize GitHub sync service naming; add doc retrieval
afshinalizadeh Dec 26, 2025
8ff53a4
Update .vscode/tasks.json
afshinalizadeh Dec 26, 2025
8f764a6
Initial plan
Copilot Dec 26, 2025
702d8ed
Add null checks for SyncId in GithubSyncService
Copilot Dec 26, 2025
5d50b94
Make null check logic consistent using IsNullOrWhiteSpace
Copilot Dec 26, 2025
9db3a1f
Merge pull request #114 from cs-internship/copilot/sub-pr-113
afshinalizadeh Dec 26, 2025
543a77a
Initial plan
Copilot Dec 26, 2025
9f0628a
Fix static field modification in instance constructor
Copilot Dec 26, 2025
ffae89b
Add thread-safety and improve code quality
Copilot Dec 26, 2025
f74ef3e
Add CancellationToken support to UpdateSyncModuleAsync
Copilot Dec 26, 2025
e7b5014
Implement IDisposable for proper resource cleanup
Copilot Dec 26, 2025
482ee1d
Add CancellationToken to EnsureInitializedAsync in Fake service
Copilot Dec 26, 2025
dd2de65
Merge pull request #115 from cs-internship/copilot/sub-pr-113-again
afshinalizadeh Jan 8, 2026
3e48a20
Register CrystaDocumentServiceFake in SyncGithubDocuments_WithValidMo…
afshinalizadeh Jan 8, 2026
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
88 changes: 44 additions & 44 deletions .vscode/tasks.json
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"
}
}
]
}
4 changes: 2 additions & 2 deletions docs/architecture/sync-overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ graph TB

subgraph "CrystaLearn Sync Layer"
ABS[AzureBoardSyncService]
GHS[GitHubService]
GHS[GithubSyncService]
Copy link

Copilot AI Dec 26, 2025

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.

Suggested change
GHS[GithubSyncService]
GHS[GitHubSyncService]

Copilot uses AI. Check for mistakes.
LIS[LinkedInSyncService*]
TWS[TwitterSyncService*]
end
Expand Down Expand Up @@ -146,7 +146,7 @@ Each synced entity follows a consistent three-layer service architecture:
- Orchestrates synchronization between external source and local database
- Handles change detection via hash comparison
- Manages incremental sync using timestamps and offsets
- Example: `AzureBoardSyncService`
- Example: `AzureBoardSyncService`, `GithubSyncService`

3. **Provider Service Layer** (`[Provider]Service`)
- Low-level communication with external APIs
Expand Down
86 changes: 86 additions & 0 deletions src/Core/CrystaLearn.Core.Test/Sync/GithubSyncServiceTests.cs
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));
}
}
2 changes: 2 additions & 0 deletions src/Core/CrystaLearn.Core/Data/AppDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public partial class AppDbContext(DbContextOptions<AppDbContext> options)

public DbSet<CrystaProgramSyncModule> CrystaProgramSyncModules { get; set; } = default!;

public DbSet<CrystaDocument> CrystaDocument { get; set; } = default!;

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
Expand Down
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();
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ void AddDbContext(DbContextOptionsBuilder options)

builder.AddGitHubClient();

services.AddSingleton<IDocumentRepository, DocumentRepositoryInMemory>();
services.AddTransient<ICrystaProgramRepository, CrystaProgramRepositoryFake>();
services.AddTransient<IDocumentRepository, DocumentRepositoryDirectGitHub>();

services.AddTransient<ICrystaProgramRepository, CrystaProgramService>();
services.AddTransient<ICrystaDocumentService, CrystaDocumentService>();
services.AddTransient<IGitHubService, GitHubService>();
services.AddTransient<IAzureBoardService, AzureBoardService>();
services.AddTransient<ICrystaProgramSyncService, CrystaProgramSyncService>();
services.AddTransient<IAzureBoardSyncService, AzureBoardSyncService>();
services.AddTransient<ICrystaProgramSyncModuleService, CrystaProgramSyncModuleService>();
services.AddTransient<IGitHubSyncService, GitHubSyncService>();
services.AddSingleton<ICrystaProgramSyncModuleService, CrystaProgramSyncModuleService>();
services.AddTransient<ICrystaTaskService, CrystaTaskService>();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Core/CrystaLearn.Core/Mappers/DocumentMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ namespace CrystaLearn.Core.Mappers;
[Mapper]
public static partial class DocumentMapper
{
public static partial DocumentDto Map(this Document source);
public static partial DocumentDto Map(this CrystaDocument source);
}
Loading
Loading