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: use picocolors and tinyglobby and biome check fix #375

Merged
merged 3 commits into from
Jan 28, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
Binary file modified bun.lockb
Binary file not shown.
10 changes: 4 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"build": "bun run ./scripts/build.ts",
"postbuild": "bun run ./scripts/shebang.ts && chmod +x ./dist/index.js",
"publish:build": "bun run build && bun publish --access public",
"check": "biome check .",
"check": "biome check . --fix",
wChenonly marked this conversation as resolved.
Show resolved Hide resolved
"format": "biome format --write ."
},
"keywords": [
Expand All @@ -47,11 +47,11 @@
"@langchain/core": "^0.3.29",
"@langchain/openai": "^0.3.17",
"azure-devops-node-api": "^12.3.0",
"chalk": "^4.1.2",
"dotenv": "^16.3.1",
"glob": "^10.3.10",
"langchain": "^0.3.11",
"octokit": "^3.1.0",
"picocolors": "^1.1.1",
"tinyglobby": "^0.2.10",
"tslog": "^4.8.2",
"yargs": "^17.7.2",
"zod": "^3.24.1"
Expand All @@ -65,7 +65,5 @@
"npm-dts": "^1.3.12",
"typescript": "^5.1.6"
},
"files": [
"dist/*"
]
"files": ["dist/*"]
}
1 change: 1 addition & 0 deletions src/common/git/specs/getChangedFileLines.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, test } from 'bun:test';
import { escapeFileName } from '../getChangedFileLines';

describe('escapeFileName', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from 'bun:test';
mattzcarey marked this conversation as resolved.
Show resolved Hide resolved
import { extractPullRequestIdentifier } from './extractPullRequestIdentifier';
import { PullRequestIdentifier } from './types';

Expand Down
29 changes: 29 additions & 0 deletions src/configure/findTemplateFile.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { afterAll, beforeAll, describe, expect, it } from 'bun:test';
import { mkdirSync, rmSync, writeFileSync } from 'fs';
import { join } from 'path';
import { findTemplateFile } from './findTemplateFile';

const testDir = join(import.meta.dir, 'test-glob');

describe('findTemplateFile', () => {
beforeAll(() => {
mkdirSync(testDir, { recursive: true });
writeFileSync(join(testDir, 'template1.txt'), 'Test File 1');
mkdirSync(join(testDir, 'subdir'));
});

afterAll(() => {
rmSync(testDir, { recursive: true, force: true });
});

it('should find a template file matching the pattern', async () => {
const pattern = join(testDir, '*.txt');
const file = await findTemplateFile(pattern);
expect(file).toMatchInlineSnapshot(`"src/configure/test-glob/template1.txt"`);
});

it('should throw an error when no files match the pattern', async () => {
const pattern = join(testDir, '*.md');
expect(findTemplateFile(pattern)).rejects.toThrow('No template file found for pattern');
});
});
4 changes: 2 additions & 2 deletions src/configure/findTemplateFile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { glob } from 'glob';
import { glob } from 'tinyglobby';

// Helper function to find the template file using glob
export const findTemplateFile = async (pattern: string): Promise<string> => {
const files = await glob(pattern, { nodir: true });
const files = await glob(pattern, { onlyFiles: true });

if (files.length === 0) {
throw new Error(`No template file found for pattern: ${pattern}`);
Expand Down
1 change: 1 addition & 0 deletions src/review/prompt/filterFiles/specs/filterFiles.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { afterEach, describe, expect, jest, test } from 'bun:test';
import { join } from 'path';
import { readFile, readdir } from 'fs/promises';

Expand Down
14 changes: 7 additions & 7 deletions src/test/run/generateTestReport.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import chalk from 'chalk';
import c from 'picocolors';

import { testThreshold } from '../constants';
import type { TestCase } from '../types';
Expand Down Expand Up @@ -34,11 +34,11 @@ const determineTestResult = (similarity: number): testResult => {
const formatTestResult = (result: testResult, message: string): string => {
switch (result) {
case testResult.PASS:
return chalk.green(`✅ [PASS] - ${message}`);
return c.green(`✅ [PASS] - ${message}`);
case testResult.WARN:
return chalk.yellow(`⚠️ [WARN] - ${message}`);
return c.yellow(`⚠️ [WARN] - ${message}`);
case testResult.FAIL:
return chalk.red(`❌ [FAIL] - ${message}`);
return c.red(`❌ [FAIL] - ${message}`);
}
};

Expand Down Expand Up @@ -102,7 +102,7 @@ export const generateTestResultsSummary = (testResults: {
}): string => {
const summary = Object.entries(testResults).reduce((summary, [testCaseName, result]) => {
return `${summary + formatTestResult(result, `Test case: ${testCaseName}`)}\n`;
}, chalk.blue('\n### Test results summary:\n'));
}, c.blue('\n### Test results summary:\n'));

const counts = Object.values(testResults).reduce(
(counts, result) => {
Expand All @@ -113,7 +113,7 @@ export const generateTestResultsSummary = (testResults: {
Object.fromEntries(Object.values(testResult).map((result) => [result, 0]))
);

return `${summary}\n**SUMMARY: ${chalk.green(`✅ PASS: ${counts.PASS}`)} - ${chalk.yellow(
return `${summary}\n**SUMMARY: ${c.green(`✅ PASS: ${counts.PASS}`)} - ${c.yellow(
`⚠️ WARN: ${counts.WARN}`
)} - ${chalk.red(`❌ FAIL: ${counts.FAIL}`)}**\n`;
)} - ${c.red(`❌ FAIL: ${counts.FAIL}`)}**\n`;
};
4 changes: 2 additions & 2 deletions src/test/run/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk';
import type { MemoryVectorStore } from 'langchain/vectorstores/memory';
import c from 'picocolors';

import { logger } from '../../common/utils/logger';
import { askAI } from '../../review/llm/askAI';
Expand Down Expand Up @@ -36,7 +36,7 @@ const runTest = async (
throw new Error(`Test case ${testCase.name} does not have a snippet.`);
}

logger.info(chalk.blue(`Running test case ${testCase.name}...`));
logger.info(c.blue(`Running test case ${testCase.name}...`));

// First step: run the review on the code snippet.
const prompts = constructPromptsArray(
Expand Down