MCPcopy Index your code
hub / github.com/di-sukharev/opencommit / generateCommitMessageFromGitDiff

Function generateCommitMessageFromGitDiff

src/commands/commit.ts:75–264  ·  view source on GitHub ↗
({
  diff,
  extraArgs,
  context = '',
  fullGitMojiSpec = false,
  skipCommitConfirmation = false
}: GenerateCommitMessageFromGitDiffParams)

Source from the content-addressed store, hash-verified

73}
74
75const generateCommitMessageFromGitDiff = async ({
76 diff,
77 extraArgs,
78 context = '',
79 fullGitMojiSpec = false,
80 skipCommitConfirmation = false
81}: GenerateCommitMessageFromGitDiffParams): Promise<void> => {
82 await assertGitRepo();
83 const commitGenerationSpinner = spinner();
84 commitGenerationSpinner.start('Generating the commit message');
85
86 try {
87 let commitMessage = await generateCommitMessageByDiff(
88 diff,
89 fullGitMojiSpec,
90 context
91 );
92
93 const messageTemplate = checkMessageTemplate(extraArgs);
94 if (
95 config.OCO_MESSAGE_TEMPLATE_PLACEHOLDER &&
96 typeof messageTemplate === 'string'
97 ) {
98 const messageTemplateIndex = extraArgs.indexOf(messageTemplate);
99 extraArgs.splice(messageTemplateIndex, 1);
100
101 commitMessage = messageTemplate.replace(
102 config.OCO_MESSAGE_TEMPLATE_PLACEHOLDER,
103 commitMessage
104 );
105 }
106
107 commitGenerationSpinner.stop('📝 Commit message generated');
108
109 outro(
110 `Generated commit message:
111${chalk.grey('——————————————————')}
112${commitMessage}
113${chalk.grey('——————————————————')}`
114 );
115
116 const userAction = skipCommitConfirmation
117 ? 'Yes'
118 : await select({
119 message: 'Confirm the commit message?',
120 options: [
121 { value: 'Yes', label: 'Yes' },
122 { value: 'No', label: 'No' },
123 { value: 'Edit', label: 'Edit' }
124 ]
125 });
126
127 if (isCancel(userAction)) process.exit(1);
128
129 if (userAction === 'Edit') {
130 const textResponse = await text({
131 message: 'Please edit the commit message: (press Enter to continue)',
132 initialValue: commitMessage

Callers 1

commitFunction · 0.70

Calls 15

assertGitRepoFunction · 0.90
getConfigFunction · 0.90
formatUserFriendlyErrorFunction · 0.90
printFormattedErrorFunction · 0.90
isCancelFunction · 0.85
textFunction · 0.85
execaFunction · 0.85
checkMessageTemplateFunction · 0.70
getGitRemotesFunction · 0.70
hasUpstreamBranchFunction · 0.70
getCurrentBranchFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…