({
projectId,
workspaceId,
message,
}: {
projectId: string;
workspaceId?: string;
message: string;
})
| 2006 | } |
| 2007 | |
| 2008 | export const commitToGitRepoAction = async ({ |
| 2009 | projectId, |
| 2010 | workspaceId, |
| 2011 | message, |
| 2012 | }: { |
| 2013 | projectId: string; |
| 2014 | workspaceId?: string; |
| 2015 | message: string; |
| 2016 | }): Promise<CommitToGitRepoResult> => { |
| 2017 | try { |
| 2018 | const gitRepository = await getGitRepository({ workspaceId, projectId }); |
| 2019 | // Flush DB changes to disk before committing |
| 2020 | await repoFileWatcherRegistry.flushNow(gitRepository._id); |
| 2021 | await GitVCS.setAuthor(); |
| 2022 | await GitVCS.commit(message); |
| 2023 | |
| 2024 | let providerName = 'custom'; |
| 2025 | if (gitRepository?.credentialsId) { |
| 2026 | const credentials = await services.gitCredentials.getById(gitRepository.credentialsId); |
| 2027 | invariant(credentials, 'Git Credentials not found'); |
| 2028 | providerName = credentials.provider; |
| 2029 | } |
| 2030 | |
| 2031 | trackAnalyticsEvent(AnalyticsEvent.vcsAction, { |
| 2032 | ...vcsEventProperties('git', 'commit'), |
| 2033 | providerName, |
| 2034 | repoId: gitRepository._id, |
| 2035 | }); |
| 2036 | |
| 2037 | const hasUnpushedChanges = await GitVCS.canPush(gitRepository.credentialsId); |
| 2038 | // update workspace meta with git sync data, use for show unpushed changes on collection card |
| 2039 | await services.gitRepository.update(gitRepository, { |
| 2040 | hasUnpushedChanges, |
| 2041 | cachedGitLastCommitTime: Date.now(), |
| 2042 | }); |
| 2043 | } catch (e) { |
| 2044 | const message = e instanceof Error ? e.message : 'Error while committing changes'; |
| 2045 | return { errors: [message] }; |
| 2046 | } |
| 2047 | |
| 2048 | return { |
| 2049 | errors: [], |
| 2050 | }; |
| 2051 | }; |
| 2052 | |
| 2053 | export const multipleCommitToGitRepoAction = async ({ |
| 2054 | projectId, |
no test coverage detected