MCPcopy Create free account
hub / github.com/Kong/insomnia / commitAndPushToGitRepoAction

Function commitAndPushToGitRepoAction

packages/insomnia/src/main/git-service.ts:2126–2250  ·  view source on GitHub ↗
({
  projectId,
  workspaceId,
  message,
}: {
  projectId: string;
  workspaceId?: string;
  message: string;
})

Source from the content-addressed store, hash-verified

2124};
2125
2126export const commitAndPushToGitRepoAction = async ({
2127 projectId,
2128 workspaceId,
2129 message,
2130}: {
2131 projectId: string;
2132 workspaceId?: string;
2133 message: string;
2134}): Promise<CommitToGitRepoResult> => {
2135 await assertBranchOnOrigin('push');
2136 const repo = await getGitRepository({ workspaceId, projectId });
2137
2138 // Validate credentials before committing to prevent orphaned local commits
2139 // when the subsequent push would fail due to authentication issues.
2140 try {
2141 await validateGitCredentials({ credentialsId: repo.credentialsId, uri: repo.uri });
2142 } catch (e) {
2143 const errorMessage = e instanceof Error ? e.message : 'Authentication failed';
2144 return { errors: [errorMessage] };
2145 }
2146
2147 try {
2148 // Flush DB changes to disk before committing
2149 await repoFileWatcherRegistry.flushNow(repo._id);
2150 await GitVCS.setAuthor();
2151 await GitVCS.commit(message);
2152
2153 let providerName = 'custom';
2154 if (repo.credentialsId) {
2155 const credentials = await services.gitCredentials.getById(repo.credentialsId);
2156 invariant(credentials, 'Git Credentials not found');
2157 providerName = credentials.provider;
2158 }
2159
2160 trackAnalyticsEvent(AnalyticsEvent.vcsAction, {
2161 ...vcsEventProperties('git', 'commit'),
2162 providerName,
2163 repoId: repo._id,
2164 });
2165 } catch (e) {
2166 const message = e instanceof Error ? e.message : 'Error while committing changes';
2167 return { errors: [message] };
2168 }
2169
2170 let canPush = false;
2171 try {
2172 canPush = await GitVCS.canPush(repo.credentialsId);
2173 } catch (err) {
2174 if (err instanceof Errors.HttpError) {
2175 return {
2176 errors: [`${err.message}, ${err.data.response}`],
2177 };
2178 }
2179 const errorMessage = getErrorMessage(err);
2180
2181 return { errors: [errorMessage] };
2182 }
2183 // If nothing to push, display that to the user

Callers 1

registerGitServiceAPIFunction · 0.85

Calls 15

invariantFunction · 0.90
trackAnalyticsEventFunction · 0.90
assertBranchOnOriginFunction · 0.85
getGitRepositoryFunction · 0.85
validateGitCredentialsFunction · 0.85
setAuthorMethod · 0.80
commitMethod · 0.80
canPushMethod · 0.80
bufferChangesMethod · 0.80
flushChangesMethod · 0.80
vcsEventPropertiesFunction · 0.70
getErrorMessageFunction · 0.70

Tested by

no test coverage detected