({
projectId,
workspaceId,
message,
}: {
projectId: string;
workspaceId?: string;
message: string;
})
| 2386 | } |
| 2387 | |
| 2388 | export const commitToGitRepoAction = async ({ |
| 2389 | projectId, |
| 2390 | workspaceId, |
| 2391 | message, |
| 2392 | }: { |
| 2393 | projectId: string; |
| 2394 | workspaceId?: string; |
| 2395 | message: string; |
| 2396 | }): Promise<CommitToGitRepoResult> => { |
| 2397 | try { |
| 2398 | const gitRepository = await getGitRepository({ workspaceId, projectId }); |
| 2399 | // Flush DB changes to disk before committing |
| 2400 | await repoFileWatcherRegistry.flushNow(gitRepository._id); |
| 2401 | await GitVCS.setAuthor(); |
| 2402 | await GitVCS.commit(message); |
| 2403 | |
| 2404 | let providerName = 'custom'; |
| 2405 | if (gitRepository?.credentialsId) { |
| 2406 | const credentials = await services.gitCredentials.getById(gitRepository.credentialsId); |
| 2407 | invariant(credentials, 'Git Credentials not found'); |
| 2408 | providerName = credentials.provider; |
| 2409 | } |
| 2410 | |
| 2411 | trackAnalyticsEvent(AnalyticsEvent.vcsAction, { |
| 2412 | ...vcsEventProperties('git', 'commit'), |
| 2413 | providerName, |
| 2414 | repoId: gitRepository._id, |
| 2415 | }); |
| 2416 | |
| 2417 | const hasUnpushedChanges = await GitVCS.canPush(gitRepository.credentialsId); |
| 2418 | // update workspace meta with git sync data, use for show unpushed changes on collection card |
| 2419 | await services.gitRepository.update(gitRepository, { |
| 2420 | hasUnpushedChanges, |
| 2421 | cachedGitLastCommitTime: Date.now(), |
| 2422 | }); |
| 2423 | } catch (e) { |
| 2424 | const message = e instanceof Error ? e.message : 'Error while committing changes'; |
| 2425 | return { errors: [message] }; |
| 2426 | } |
| 2427 | |
| 2428 | return { |
| 2429 | errors: [], |
| 2430 | }; |
| 2431 | }; |
| 2432 | |
| 2433 | export const multipleCommitToGitRepoAction = async ({ |
| 2434 | projectId, |
no test coverage detected