Skip to content
Closed
Show file tree
Hide file tree
Changes from 12 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
3 changes: 1 addition & 2 deletions .github/funding.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@

github: warengonzaga
buy_me_a_coffee: warengonzaga

# Your support means a lot to me to continue the development of open source project like this.
# Sponsoring this project means a lot to me. Your support helps me to continue building great open-source projects just like this.
# Sponsoring this project means a lot to me. Your support helps me to continue building great open-source projects just like this.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ This project is inspired by the following projects:
- [aicommits](https://github.com/Nutlope/aicommits) - A CLI that writes your git commit messages for you with AI.
- [ai-commit](https://github.com/insulineru/ai-commit) - Make commits easier with ChatGPT, Gitmoji and Conventional Commits.
- [opencommit](https://github.com/di-sukharev/opencommit) - About
Auto-generate impressive commits with AI in 1 second.
Auto-generate impressive commits with AI in 1 second.
- [tgpt](https://github.com/aandrew-me/tgpt) - AI Chatbots in terminal without needing API keys.

## βš™οΈ Project Activity

![activity](https://repobeats.axiom.co/api/embed/b89d4c52ac63656f8148143516edd0db0d85788d.svg "Repobeats analytics image")
![activity](https://repobeats.axiom.co/api/embed/b89d4c52ac63656f8148143516edd0db0d85788d.svg 'Repobeats analytics image')

## 🎯 Contributing

Expand Down
22 changes: 11 additions & 11 deletions code_of_conduct.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@ diverse, inclusive, and healthy community.
Examples of behavior that contributes to a positive environment for our
community include:

* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
- Demonstrating empathy and kindness toward other people
- Being respectful of differing opinions, viewpoints, and experiences
- Giving and gracefully accepting constructive feedback
- Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
- Focusing on what is best not just for us as individuals, but for the
overall community

Examples of unacceptable behavior include:

* The use of sexualized language or imagery, and sexual attention or
- The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
- Trolling, insulting or derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
- Other conduct which could reasonably be considered inappropriate in a
professional setting

## Enforcement Responsibilities
Expand Down Expand Up @@ -106,7 +106,7 @@ Violating these terms may lead to a permanent ban.
### 4. Permanent Ban

**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.

**Consequence**: A permanent ban from any sort of public interaction within
Expand Down
2 changes: 1 addition & 1 deletion contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ There are many ways to contribute to this open source project. Any contributions

### 🧬 Development

If you can write a code then create a pull request to this repo and I will review your code. Please consider to submit your pull request to the ```dev``` branch. I will auto reject if you submit your pull request to the ```main``` branch.
If you can write a code then create a pull request to this repo and I will review your code. Please consider to submit your pull request to the `dev` branch. I will auto reject if you submit your pull request to the `main` branch.

#### πŸ”§ Setup

Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@
],
"dependencies": {
"conf": "^12.0.0",
"dotenv": "^16.4.5",
"dotenv": "^16.5.0",
"execa": "^8.0.1",
"ink": "^5.0.1",
"ink": "^5.2.1",
"ink-big-text": "^2.0.0",
"ink-gradient": "^3.0.0",
"ink-select-input": "^6.0.0",
"ink-select-input": "^6.2.0",
"is-git-repository": "^2.0.0",
"meow": "^11.0.0",
"openai": "^4.28.4",
"openai": "^4.104.0",
"react": "^18.2.0",
"readline": "^1.3.0"
},
Expand Down
34 changes: 22 additions & 12 deletions source/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,27 @@ import isGit from 'is-git-repository';
import isCommitterSet from './utils/errors.js';
import info from './utils/info.js';
import askForCommitMessage from './utils/commit.js';
import { getOpenAIKey, setOpenAIKey, deleteOPenAIKey } from './utils/api.js';
import {getOpenAIKey, setOpenAIKey, deleteOPenAIKey} from './utils/api.js';

export default function App({flags}) {
if(flags.setopenai) {
if (flags.setopenai) {
setOpenAIKey(flags.setopenai);
}
if(flags.delopenai) {
if (flags.delopenai) {
deleteOPenAIKey();
}
if (!getOpenAIKey()) {
console.log('Please provide an OpenAI API key.');
console.log('You can get one from https://platform.openai.com/account/api-keys')
console.log('Run `magicc --setopenai=<api-key>` to save your API key and try again.');
console.log(
'You can get one from https://platform.openai.com/account/api-keys',
);
console.log(
'Run `magicc --setopenai=<api-key>` to save your API key and try again.',
);
} else {
console.log('You have an OpenAI API key, you can now generate a commit message.');
console.log(
'You have an OpenAI API key, you can now generate a commit message.',
);
const gitCheck = isGit();
const committerCheck = isCommitterSet();
if (gitCheck && committerCheck) {
Expand All @@ -31,16 +37,20 @@ export default function App({flags}) {
}
return (
<>
<Gradient name='passion'>
<BigText text='Magicc' />
<Text>You can do `magicc`, you can build anything that you desire. πŸͺ„</Text>
<Gradient name="passion">
<BigText text="Magicc" />
<Text>
You can do `magicc`, you can build anything that you desire. πŸͺ„
</Text>
</Gradient>
<Text>
Version: <Text color='green'>{info('version')}</Text> |
Author: <Text color='blue'>{info('author')}</Text><Newline/>
Version: <Text color="green">{info('version')}</Text> | Author:{' '}
<Text color="blue">{info('author')}</Text>
<Newline />
<Text>
Need Help? <Text color="cyan">magicc --help</Text>
</Text><Newline/>
</Text>
<Newline />
==================================================
</Text>
</>
Expand Down
2 changes: 1 addition & 1 deletion source/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ const cli = meow(
},
);

render(<App flags={cli.flags}/>);
render(<App flags={cli.flags} />);
66 changes: 33 additions & 33 deletions source/utils/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,46 +3,46 @@ import Conf from 'conf';
const config = new Conf({projectName: 'magicc'});

async function isValidOpenAIKey(apiKey) {
try {
const response = await fetch('https://api.openai.com/v1/models', {
headers: {
'Authorization': `Bearer ${apiKey}`
}
});
try {
const response = await fetch('https://api.openai.com/v1/models', {
headers: {
Authorization: `Bearer ${apiKey}`,
},
});

if (response.status === 200) {
return true;
} else if (response.status === 401) {
console.error('Invalid API key');
return false;
} else {
console.error('Unexpected response status:', response.status);
return false;
}
} catch (error) {
console.error('Error while validating API key:', error);
return false;
}
if (response.status === 200) {
return true;
} else if (response.status === 401) {
console.error('Invalid API key');
return false;
} else {
console.error('Unexpected response status:', response.status);
return false;
}
} catch (error) {
console.error('Error while validating API key:', error);
return false;
}
}

const setOpenAIKey = (key) => {
isValidOpenAIKey(key).then(isValid => {
if (isValid) {
console.log('API key is valid');
config.set('openai', key);
} else {
console.log('API key is invalid');
}
});
const setOpenAIKey = key => {
isValidOpenAIKey(key).then(isValid => {
if (isValid) {
console.log('API key is valid');
config.set('openai', key);
} else {
console.log('API key is invalid');
}
});
};

const getOpenAIKey = () => {
return config.get('openai');
}
return config.get('openai');
};

const deleteOPenAIKey = () => {
config.delete('openai');
console.log('OpenAI API key deleted.');
}
config.delete('openai');
console.log('OpenAI API key deleted.');
};

export {setOpenAIKey, getOpenAIKey, deleteOPenAIKey};
5 changes: 2 additions & 3 deletions source/utils/commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ async function askForCommitMessage() {
.catch(error => {
console.error('Failed to commit changes:', error);
});
}
else {
} else {
console.log('Changes not committed.');
}
exit();
Expand All @@ -49,7 +48,7 @@ async function askForCommitMessage() {
</Box>
);
};

if (prompt) {
render(<SelectSuggestedCommit />);
} else {
Expand Down
8 changes: 4 additions & 4 deletions source/utils/config.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"emoji": "YYou are the author of the commit message. Your task is to select the appropriate category for the git diff based on the changes. Use the following categories (emoji category name => usage): πŸ“¦ new => for new files or new features; ✨ tweak => for enhancements or updates to the codebase; β˜• chore => for updates or changes outside the project codebase, including README.md; 🐞 fix => for fixing code bugs and errors. Please reply with the category name only.",
"message": "You are the author of the changes, you are going to provide a professional git commit message that is no longer than 25 characters in imperative present tense. Stricly no emojis are allowed and no conventional commit message as prefix is already provided. For example, instead of 'fix: fix a bug' make it 'fix a bug'. The message should be in lower case and no period at the end.",
"default_model": "gpt-4o-mini",
"maxDiffSize": 4000
"emoji": "YYou are the author of the commit message. Your task is to select the appropriate category for the git diff based on the changes. Use the following categories (emoji category name => usage): πŸ“¦ new => for new files or new features; ✨ tweak => for enhancements or updates to the codebase; β˜• chore => for updates or changes outside the project codebase, including README.md; 🐞 fix => for fixing code bugs and errors. Please reply with the category name only.",
"message": "You are the author of the changes, you are going to provide a professional git commit message that is no longer than 25 characters in imperative present tense. Stricly no emojis are allowed and no conventional commit message as prefix is already provided. For example, instead of 'fix: fix a bug' make it 'fix a bug'. The message should be in lower case and no period at the end.",
"default_model": "gpt-4o-mini",
"maxDiffSize": 4000
}
30 changes: 17 additions & 13 deletions source/utils/errors.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
import { execa } from "execa"
import {execa} from 'execa';

const isCommitterSet = async () => {
try {
const { stdout: name } = await execa("git", ["config", "--get", "user.name"]);
const { stdout: email } = await execa("git", ["config", "--get", "user.email"]);
try {
const {stdout: name} = await execa('git', ['config', '--get', 'user.name']);
const {stdout: email} = await execa('git', [
'config',
'--get',
'user.email',
]);

if (name && email) {
return true;
}
} catch (error) {
console.error("Failed to check if committer is set:", error);
return false;
}
}
if (name && email) {
return true;
}
} catch (error) {
console.error('Failed to check if committer is set:', error);
return false;
}
};

export default isCommitterSet;
export default isCommitterSet;
22 changes: 11 additions & 11 deletions source/utils/info.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import packageJSON from '../../package.json';

const { author, version } = packageJSON;
const {author, version} = packageJSON;

const info = (info) => {
if (info === 'version') {
return version;
} else if (info === 'author') {
return author;
} else {
return console.error('Invalid info type');
}
}
const info = info => {
if (info === 'version') {
return version;
} else if (info === 'author') {
return author;
} else {
return console.error('Invalid info type');
}
};

export default info;
export default info;
Loading