Skip to content

Commit

Permalink
formatting and fixed type error
Browse files Browse the repository at this point in the history
  • Loading branch information
Nutlope committed Jan 26, 2024
1 parent 723c171 commit 604def8
Show file tree
Hide file tree
Showing 8 changed files with 165 additions and 113 deletions.
1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

33 changes: 16 additions & 17 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,22 @@ jobs:
contents: write

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Checkout
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'

- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 7
run_install: true

- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm dlx semantic-release
- name: Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
run: pnpm dlx semantic-release
2 changes: 1 addition & 1 deletion src/utils/openai.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const generateCommitMessage = async (
return deduplicateMessages(
completion.choices
.filter((choice) => choice.message?.content)
.map((choice) => sanitizeMessage(choice.message!.content))
.map((choice) => sanitizeMessage(choice.message!.content as string))
);
} catch (error) {
const errorAsAny = error as any;
Expand Down
118 changes: 84 additions & 34 deletions tests/specs/cli/commits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ import {
export default testSuite(({ describe }) => {
if (process.platform === 'win32') {
// https://github.com/nodejs/node/issues/31409
console.warn('Skipping tests on Windows because Node.js spawn cant open TTYs');
console.warn(
'Skipping tests on Windows because Node.js spawn cant open TTYs'
);
return;
}

Expand All @@ -21,10 +23,15 @@ export default testSuite(({ describe }) => {
const git = await createGit(fixture.path);

await git('add', ['data.json']);
const statusBefore = await git('status', ['--porcelain', '--untracked-files=no']);
const statusBefore = await git('status', [
'--porcelain',
'--untracked-files=no',
]);
expect(statusBefore.stdout).toBe('A data.json');

const { stdout, exitCode } = await aicommits(['--exclude', 'data.json'], { reject: false });
const { stdout, exitCode } = await aicommits(['--exclude', 'data.json'], {
reject: false,
});
expect(exitCode).toBe(1);
expect(stdout).toMatch('No staged changes found.');
await fixture.rm();
Expand All @@ -47,10 +54,15 @@ export default testSuite(({ describe }) => {

await committing;

const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
const statusAfter = await git('status', [
'--porcelain',
'--untracked-files=no',
]);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
const { stdout: commitMessage } = await git('log', [
'--pretty=format:%s',
]);
console.log({
commitMessage,
length: commitMessage.length,
Expand Down Expand Up @@ -81,7 +93,9 @@ export default testSuite(({ describe }) => {

await committing;

const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
const { stdout: commitMessage } = await git('log', [
'--pretty=format:%s',
]);
console.log({
commitMessage,
length: commitMessage.length,
Expand Down Expand Up @@ -118,7 +132,10 @@ export default testSuite(({ describe }) => {
const statusAfter = await git('status', ['--short']);
expect(statusAfter.stdout).toBe('?? .aicommits');

const { stdout: commitMessage } = await git('log', ['-n1', '--pretty=format:%s']);
const { stdout: commitMessage } = await git('log', [
'-n1',
'--pretty=format:%s',
]);
console.log({
commitMessage,
length: commitMessage.length,
Expand All @@ -128,7 +145,9 @@ export default testSuite(({ describe }) => {
await fixture.rm();
});

test('Accepts --generate flag, overriding config', async ({ onTestFail }) => {
test('Accepts --generate flag, overriding config', async ({
onTestFail,
}) => {
const { fixture, aicommits } = await createFixture({
...files,
'.aicommits': `${files['.aicommits']}\ngenerate=4`,
Expand All @@ -138,9 +157,7 @@ export default testSuite(({ describe }) => {
await git('add', ['data.json']);

// Generate flag should override generate config
const committing = aicommits([
'--generate', '2',
]);
const committing = aicommits(['--generate', '2']);

// Hit enter to accept the commit message
committing.stdout!.on('data', function onPrompt(buffer: Buffer) {
Expand All @@ -158,10 +175,15 @@ export default testSuite(({ describe }) => {
onTestFail(() => console.log({ stdout }));
expect(countChoices).toBe(2);

const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
const statusAfter = await git('status', [
'--porcelain',
'--untracked-files=no',
]);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
const { stdout: commitMessage } = await git('log', [
'--pretty=format:%s',
]);
console.log({
commitMessage,
length: commitMessage.length,
Expand All @@ -173,7 +195,8 @@ export default testSuite(({ describe }) => {

test('Generates Japanese commit message via locale config', async () => {
// https://stackoverflow.com/a/15034560/911407
const japanesePattern = /[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFF9F\u4E00-\u9FAF\u3400-\u4DBF]/;
const japanesePattern =
/[\u3000-\u303F\u3040-\u309F\u30A0-\u30FF\uFF00-\uFF9F\u4E00-\u9FAF\u3400-\u4DBF]/;

const { fixture, aicommits } = await createFixture({
...files,
Expand All @@ -195,10 +218,15 @@ export default testSuite(({ describe }) => {

await committing;

const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
const statusAfter = await git('status', [
'--porcelain',
'--untracked-files=no',
]);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
const { stdout: commitMessage } = await git('log', [
'--pretty=format:%s',
]);
console.log({
commitMessage,
length: commitMessage.length,
Expand All @@ -211,7 +239,8 @@ export default testSuite(({ describe }) => {

describe('commit types', ({ test }) => {
test('Should not use conventional commits by default', async () => {
const conventionalCommitPattern = /(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
const conventionalCommitPattern =
/(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
const { fixture, aicommits } = await createFixture({
...files,
});
Expand All @@ -231,7 +260,10 @@ export default testSuite(({ describe }) => {

await committing;

const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
const statusAfter = await git('status', [
'--porcelain',
'--untracked-files=no',
]);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', ['--oneline']);
Expand All @@ -242,7 +274,8 @@ export default testSuite(({ describe }) => {
});

test('Conventional commits', async () => {
const conventionalCommitPattern = /(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
const conventionalCommitPattern =
/(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
const { fixture, aicommits } = await createFixture({
...files,
'.aicommits': `${files['.aicommits']}\ntype=conventional`,
Expand All @@ -263,7 +296,10 @@ export default testSuite(({ describe }) => {

await committing;

const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
const statusAfter = await git('status', [
'--porcelain',
'--untracked-files=no',
]);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', ['--oneline']);
Expand All @@ -274,7 +310,8 @@ export default testSuite(({ describe }) => {
});

test('Accepts --type flag, overriding config', async () => {
const conventionalCommitPattern = /(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
const conventionalCommitPattern =
/(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
const { fixture, aicommits } = await createFixture({
...files,
'.aicommits': `${files['.aicommits']}\ntype=other`,
Expand All @@ -284,9 +321,7 @@ export default testSuite(({ describe }) => {
await git('add', ['data.json']);

// Generate flag should override generate config
const committing = aicommits([
'--type', 'conventional',
]);
const committing = aicommits(['--type', 'conventional']);

committing.stdout!.on('data', (buffer: Buffer) => {
const stdout = buffer.toString();
Expand All @@ -298,7 +333,10 @@ export default testSuite(({ describe }) => {

await committing;

const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
const statusAfter = await git('status', [
'--porcelain',
'--untracked-files=no',
]);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', ['--oneline']);
Expand All @@ -309,7 +347,8 @@ export default testSuite(({ describe }) => {
});

test('Accepts empty --type flag', async () => {
const conventionalCommitPattern = /(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
const conventionalCommitPattern =
/(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test):\s/;
const { fixture, aicommits } = await createFixture({
...files,
'.aicommits': `${files['.aicommits']}\ntype=conventional`,
Expand All @@ -318,9 +357,7 @@ export default testSuite(({ describe }) => {

await git('add', ['data.json']);

const committing = aicommits([
'--type', '',
]);
const committing = aicommits(['--type', '']);

committing.stdout!.on('data', (buffer: Buffer) => {
const stdout = buffer.toString();
Expand All @@ -332,7 +369,10 @@ export default testSuite(({ describe }) => {

await committing;

const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
const statusAfter = await git('status', [
'--porcelain',
'--untracked-files=no',
]);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', ['--oneline']);
Expand Down Expand Up @@ -394,10 +434,15 @@ export default testSuite(({ describe }) => {

await committing;

const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
const statusAfter = await git('status', [
'--porcelain',
'--untracked-files=no',
]);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
const { stdout: commitMessage } = await git('log', [
'--pretty=format:%s',
]);
console.log({
commitMessage,
length: commitMessage.length,
Expand Down Expand Up @@ -429,10 +474,15 @@ export default testSuite(({ describe }) => {

await committing;

const statusAfter = await git('status', ['--porcelain', '--untracked-files=no']);
const statusAfter = await git('status', [
'--porcelain',
'--untracked-files=no',
]);
expect(statusAfter.stdout).toBe('');

const { stdout: commitMessage } = await git('log', ['--pretty=format:%s']);
const { stdout: commitMessage } = await git('log', [
'--pretty=format:%s',
]);
console.log({
commitMessage,
length: commitMessage.length,
Expand Down
4 changes: 3 additions & 1 deletion tests/specs/cli/error-cases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ export default testSuite(({ describe }) => {

const { stdout, exitCode } = await aicommits([], { reject: false });
expect(exitCode).toBe(1);
expect(stdout).toMatch('No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.');
expect(stdout).toMatch(
'No staged changes found. Stage your changes manually, or automatically stage all changes with the `--all` flag.'
);
await fixture.rm();
});
});
Expand Down
13 changes: 9 additions & 4 deletions tests/specs/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ export default testSuite(({ describe }) => {
reject: false,
});

expect(stderr).toMatch('Invalid config property OPENAI_KEY: Must start with "sk-"');
expect(stderr).toMatch(
'Invalid config property OPENAI_KEY: Must start with "sk-"'
);
});

await test('set config file', async () => {
Expand Down Expand Up @@ -71,9 +73,12 @@ export default testSuite(({ describe }) => {

await describe('max-length', ({ test }) => {
test('must be an integer', async () => {
const { stderr } = await aicommits(['config', 'set', 'max-length=abc'], {
reject: false,
});
const { stderr } = await aicommits(
['config', 'set', 'max-length=abc'],
{
reject: false,
}
);

expect(stderr).toMatch('Must be an integer');
});
Expand Down
Loading

0 comments on commit 604def8

Please sign in to comment.