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

Function commitAndPushToGitRepoAction

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

Source from the content-addressed store, hash-verified

2447};
2448
2449export const commitAndPushToGitRepoAction = async ({
2450 projectId,
2451 workspaceId,
2452 message,
2453}: {
2454 projectId: string;
2455 workspaceId?: string;
2456 message: string;
2457}): Promise<CommitToGitRepoResult> => {
2458 await assertBranchOnOrigin('push');
2459 const repo = await getGitRepository({ workspaceId, projectId });
2460
2461 // Validate credentials before committing to prevent orphaned local commits
2462 // when the subsequent push would fail due to authentication issues.
2463 try {
2464 await validateGitCredentials({ credentialsId: repo.credentialsId, uri: repo.uri });
2465 } catch (e) {
2466 const errorMessage = e instanceof Error ? e.message : 'Authentication failed';
2467 return { errors: [errorMessage] };
2468 }
2469
2470 try {
2471 // Flush DB changes to disk before committing
2472 await repoFileWatcherRegistry.flushNow(repo._id);
2473 await GitVCS.setAuthor();
2474 await GitVCS.commit(message);
2475
2476 let providerName = 'custom';
2477 if (repo.credentialsId) {
2478 const credentials = await services.gitCredentials.getById(repo.credentialsId);
2479 invariant(credentials, 'Git Credentials not found');
2480 providerName = credentials.provider;
2481 }
2482
2483 trackAnalyticsEvent(AnalyticsEvent.vcsAction, {
2484 ...vcsEventProperties('git', 'commit'),
2485 providerName,
2486 repoId: repo._id,
2487 });
2488 } catch (e) {
2489 const message = e instanceof Error ? e.message : 'Error while committing changes';
2490 return { errors: [message] };
2491 }
2492
2493 let canPush = false;
2494 try {
2495 canPush = await GitVCS.canPush(repo.credentialsId);
2496 } catch (err) {
2497 // The commit above already succeeded — a failure here is just the
2498 // pushability check, so persist that the commit is still unpushed.
2499 await services.gitRepository.update(repo, {
2500 hasUnpushedChanges: true,
2501 });
2502
2503 if (err instanceof Errors.HttpError) {
2504 return {
2505 errors: [`${err.message}, ${err.data.response}`],
2506 pushFailedAfterCommit: true,

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