Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/pre commit #449

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
🔧 Refactor commit output and logging for cleaner presentation
- Simplify commit message and output display using a consistent separator
- Remove duplicate logging and reduce verbosity in commit and cache processes
- Enhance test setup for commit cache by explicitly enabling cache
  • Loading branch information
majiayu000 committed Mar 11, 2025
commit 3e24502728dd70e27ef14ef950736a747be28f3f
19 changes: 6 additions & 13 deletions src/commands/commit.ts
Original file line number Diff line number Diff line change
@@ -84,7 +84,7 @@ const generateCommitMessageFromGitDiff = async ({
commitGenerationSpinner.stop('📝 Commit message generated');
Logger.spinnerSuccess('Commit message generated');

const separator = '——————————————————';
const separator = '─'.repeat(50);
const messageBox = `Generated commit message:\n│ ${chalk.grey(separator)}\n│ ${commitMessage}\n│ ${chalk.grey(separator)}`;
outro(messageBox);
// Remove duplicate logging
@@ -125,8 +125,8 @@ const generateCommitMessageFromGitDiff = async ({
await CommitCache.clearCache();
Logger.debug('Cleared commit cache');

outro(stdout);
Logger.info(stdout);
// Only output git commit result once
outro(`│ ${stdout}`);

const remotes = await getGitRemotes();

@@ -354,7 +354,7 @@ export async function commit(
Logger.spinner('Files counted');

Logger.info('Found cached commit message');
const separator = '——————————————————';
const separator = '─'.repeat(50);
const useCachedMessage = await confirm({
message: `Found cached commit message for the same files. Use it?\n│ ${chalk.grey(separator)}\n│ ${cachedCommit.message}\n│ ${chalk.grey(separator)}`
});
@@ -387,15 +387,8 @@ export async function commit(
await CommitCache.clearCache();
Logger.debug('Cleared commit cache');

// Combine the output into a single message
const commitOutput = [
stdout,
`Logs: ${Logger.getLogPath()}`
].join('\n│ ');
outro(commitOutput);

// Remove duplicate logging
Logger.debug('Commit output:', stdout);
// Only output git commit result once
outro(`│ ${stdout}`);

process.exit(0);
} catch (error: any) {
4 changes: 4 additions & 0 deletions test/unit/commitCache.test.ts
Original file line number Diff line number Diff line change
@@ -22,6 +22,9 @@ describe('CommitCache', () => {
echo "test" > test.txt
git add test.txt
`);

// Ensure cache is enabled for tests
process.env.OCO_ENABLE_CACHE = 'true';
});

beforeEach(() => {
@@ -37,6 +40,7 @@ describe('CommitCache', () => {
afterAll(() => {
// Clean up test repositories
execSync(`rm -rf "${TEST_DIR}"`);
delete process.env.OCO_ENABLE_CACHE;
});

it('should save and retrieve commit message', async () => {