Skip to content

Commit 1ed7ad7

Browse files
committed
Fix SyncStatus not being reset on connect/disconnect
- Reset SyncStatus and SyncError to null on connect (both OAuth and PAT) - Change disconnect to set SyncStatus to null instead of 'pending'
1 parent c14bd9e commit 1ed7ad7

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

cloud/src/LrmCloud.Api/Controllers/GitHubController.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,11 +211,13 @@ public async Task<ActionResult<ApiResponse<GitHubSyncStatus>>> ConnectRepository
211211
if (repository == null)
212212
return NotFound("repo_not_found", "Repository not found or you don't have access to it");
213213

214-
// Update project
214+
// Update project - reset sync state for fresh connection
215215
project.GitHubRepo = request.RepoFullName;
216216
project.GitHubDefaultBranch = request.DefaultBranch;
217217
project.GitHubBasePath = request.BasePath;
218218
project.GitHubConnectedByUserId = userId;
219+
project.SyncStatus = null; // Reset sync status
220+
project.SyncError = null;
219221
project.UpdatedAt = DateTime.UtcNow;
220222

221223
await _db.SaveChangesAsync();
@@ -231,7 +233,7 @@ public async Task<ActionResult<ApiResponse<GitHubSyncStatus>>> ConnectRepository
231233
BasePath: project.GitHubBasePath,
232234
LastSyncedAt: project.LastSyncedAt,
233235
LastPrUrl: null,
234-
SyncStatus: project.SyncStatus,
236+
SyncStatus: null,
235237
ConnectionMethod: "oauth",
236238
ConnectedByUsername: user?.Username
237239
));
@@ -264,11 +266,14 @@ public async Task<ActionResult<ApiResponse<GitHubSyncStatus>>> ConnectRepository
264266
// Encrypt and store the PAT
265267
var encryptedToken = TokenEncryption.Encrypt(request.PersonalAccessToken, _config.Encryption.TokenKey);
266268

269+
// Reset sync state for fresh connection
267270
project.GitHubRepo = request.RepoFullName;
268271
project.GitHubDefaultBranch = request.DefaultBranch;
269272
project.GitHubBasePath = request.BasePath;
270273
project.GitHubAccessTokenEncrypted = encryptedToken;
271274
project.GitHubConnectedByUserId = userId;
275+
project.SyncStatus = null; // Reset sync status
276+
project.SyncError = null;
272277
project.UpdatedAt = DateTime.UtcNow;
273278

274279
await _db.SaveChangesAsync();
@@ -284,7 +289,7 @@ public async Task<ActionResult<ApiResponse<GitHubSyncStatus>>> ConnectRepository
284289
BasePath: project.GitHubBasePath,
285290
LastSyncedAt: project.LastSyncedAt,
286291
LastPrUrl: null,
287-
SyncStatus: project.SyncStatus,
292+
SyncStatus: null,
288293
ConnectionMethod: "pat",
289294
ConnectedByUsername: user?.Username
290295
));
@@ -313,7 +318,7 @@ public async Task<ActionResult<ApiResponse<bool>>> DisconnectRepository(int proj
313318
project.GitHubConnectedByUserId = null;
314319
project.LastSyncedAt = null;
315320
project.LastSyncedCommit = null;
316-
project.SyncStatus = "pending";
321+
project.SyncStatus = null; // Clear sync status on disconnect
317322
project.SyncError = null;
318323
project.UpdatedAt = DateTime.UtcNow;
319324

0 commit comments

Comments
 (0)