({
projectId,
workspaceId,
message,
}: {
projectId: string;
workspaceId?: string;
message: string;
})
| 2329 | } |
| 2330 | |
| 2331 | export const commitToGitRepoAction = async ({ |
| 2332 | projectId, |
| 2333 | workspaceId, |
| 2334 | message, |
| 2335 | }: { |
| 2336 | projectId: string; |
| 2337 | workspaceId?: string; |
| 2338 | message: string; |
| 2339 | }): Promise<CommitToGitRepoResult> => { |
| 2340 | try { |
| 2341 | const gitRepository = await getGitRepository({ workspaceId, projectId }); |
| 2342 | // Flush DB changes to disk before committing |
| 2343 | await repoFileWatcherRegistry.flushNow(gitRepository._id); |
| 2344 | await GitVCS.setAuthor(); |
| 2345 | await GitVCS.commit(message); |
| 2346 | |
| 2347 | let providerName = 'custom'; |
| 2348 | if (gitRepository?.credentialsId) { |
| 2349 | const credentials = await services.gitCredentials.getById(gitRepository.credentialsId); |
| 2350 | invariant(credentials, 'Git Credentials not found'); |
| 2351 | providerName = credentials.provider; |
| 2352 | } |
| 2353 | |
| 2354 | trackAnalyticsEvent(AnalyticsEvent.vcsAction, { |
| 2355 | ...vcsEventProperties('git', 'commit'), |
| 2356 | providerName, |
| 2357 | repoId: gitRepository._id, |
| 2358 | }); |
| 2359 | |
| 2360 | const hasUnpushedChanges = await GitVCS.canPush(gitRepository.credentialsId); |
| 2361 | // update workspace meta with git sync data, use for show unpushed changes on collection card |
| 2362 | await services.gitRepository.update(gitRepository, { |
| 2363 | hasUnpushedChanges, |
| 2364 | cachedGitLastCommitTime: Date.now(), |
| 2365 | }); |
| 2366 | } catch (e) { |
| 2367 | const message = e instanceof Error ? e.message : 'Error while committing changes'; |
| 2368 | return { errors: [message] }; |
| 2369 | } |
| 2370 | |
| 2371 | return { |
| 2372 | errors: [], |
| 2373 | }; |
| 2374 | }; |
| 2375 | |
| 2376 | export const multipleCommitToGitRepoAction = async ({ |
| 2377 | projectId, |
no test coverage detected