@rahul-004x/committs 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +49 -0
- package/dist/util.d.ts +5 -0
- package/dist/util.js +13 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
## Installation and Usage
|
|
2
|
+
|
|
3
|
+
1. Install the CLI:
|
|
4
|
+
|
|
5
|
+
```sh
|
|
6
|
+
npm install -g committs
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
2. Retrieve your API key from [OpenRouter]("https://openrouter.ai/settings/keys")
|
|
10
|
+
|
|
11
|
+
> Note: If you haven't already, you'll have to create an account and set up billing.
|
|
12
|
+
|
|
13
|
+
3. Set the key so aicommits can use it:
|
|
14
|
+
|
|
15
|
+
```sh
|
|
16
|
+
echo "OPENROUTER_API_KEY=<your token>" >> ~/.committs
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
4. You're ready to go!
|
|
20
|
+
|
|
21
|
+
Run `committs` in any Git repo and it will generate a commit message.
|
|
22
|
+
|
|
23
|
+
|
package/dist/cli.d.ts
ADDED
package/dist/cli.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { $, echo, question } from "zx";
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { getConfig } from "./util.js";
|
|
5
|
+
void (async function () {
|
|
6
|
+
console.log(chalk.white("Generating ai messages...."));
|
|
7
|
+
const config = await getConfig();
|
|
8
|
+
const apiKey = config.OPENROUTER_API_KEY;
|
|
9
|
+
const diffResult = await $ `git diff --cached`;
|
|
10
|
+
const diff = diffResult.stdout.trim();
|
|
11
|
+
if (!diff) {
|
|
12
|
+
console.log(chalk.yellow("No staged changes found."));
|
|
13
|
+
process.exit(0);
|
|
14
|
+
}
|
|
15
|
+
const prompt = `I want you to act like a git commit writer. I will give you a diff and your task is to write a semantic git commit message strictly semantic. Return only the commit message, a complete sentence, and do not repeat yourself.`;
|
|
16
|
+
const response = await fetch("https://openrouter.ai/api/v1/chat/completions", {
|
|
17
|
+
method: "POST",
|
|
18
|
+
headers: {
|
|
19
|
+
Authorization: `Bearer ${apiKey}`,
|
|
20
|
+
"Content-Type": "application/json",
|
|
21
|
+
},
|
|
22
|
+
body: JSON.stringify({
|
|
23
|
+
model: "google/gemini-3-flash-preview",
|
|
24
|
+
messages: [
|
|
25
|
+
{ role: "system", content: prompt },
|
|
26
|
+
{
|
|
27
|
+
role: "user",
|
|
28
|
+
content: diff,
|
|
29
|
+
},
|
|
30
|
+
],
|
|
31
|
+
}),
|
|
32
|
+
});
|
|
33
|
+
const jsonResponse = await response.json();
|
|
34
|
+
if (jsonResponse.error) {
|
|
35
|
+
console.error(chalk.red("API Error:"), JSON.stringify(jsonResponse.error, null, 2));
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
const aiCommit = jsonResponse.choices[0].message.content;
|
|
39
|
+
let cleanedUpAiCommit = aiCommit.replace(/(\r\n|\n|\r)/gm, "").trim();
|
|
40
|
+
console.log(chalk.green("Commit message:"), cleanedUpAiCommit);
|
|
41
|
+
const commitConfimation = await question("\n Would you like to commit" + chalk.yellow("(y/n): "), {
|
|
42
|
+
choices: ["Y", "n"],
|
|
43
|
+
});
|
|
44
|
+
$.verbose = true;
|
|
45
|
+
echo("\n");
|
|
46
|
+
if (commitConfimation !== "n") {
|
|
47
|
+
await $ `git commit -m ${cleanedUpAiCommit}`;
|
|
48
|
+
}
|
|
49
|
+
})();
|
package/dist/util.d.ts
ADDED
package/dist/util.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import os from "os";
|
|
2
|
+
import path from "path";
|
|
3
|
+
import fs from "fs/promises";
|
|
4
|
+
import ini from "ini";
|
|
5
|
+
const fileExist = (filePath) => fs.access(filePath).then(() => true, () => false);
|
|
6
|
+
export const getConfig = async () => {
|
|
7
|
+
const confitPath = path.join(os.homedir(), '.committs');
|
|
8
|
+
const confitExist = await fileExist(confitPath);
|
|
9
|
+
if (!confitExist)
|
|
10
|
+
return {};
|
|
11
|
+
const confitString = await fs.readFile(confitPath, 'utf-8');
|
|
12
|
+
return ini.parse(confitString);
|
|
13
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rahul-004x/committs",
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "AI-powered git commit message generator",
|
|
5
|
+
"main": "dist/cli.js",
|
|
6
|
+
"bin": {
|
|
7
|
+
"committs": "./dist/cli.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"cli.js"
|
|
12
|
+
],
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"start": "bun src/cli.ts",
|
|
16
|
+
"prepublishOnly": "npm run build"
|
|
17
|
+
},
|
|
18
|
+
"type": "module",
|
|
19
|
+
"private": false,
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"git",
|
|
25
|
+
"commit",
|
|
26
|
+
"ai",
|
|
27
|
+
"cli"
|
|
28
|
+
],
|
|
29
|
+
"author": "",
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"devDependencies": {
|
|
32
|
+
"@types/bun": "latest",
|
|
33
|
+
"@types/ini": "^4.1.1"
|
|
34
|
+
},
|
|
35
|
+
"peerDependencies": {
|
|
36
|
+
"typescript": "^5"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"chalk": "^5.6.2",
|
|
40
|
+
"ini": "^6.0.0",
|
|
41
|
+
"zx": "^8.8.5"
|
|
42
|
+
}
|
|
43
|
+
}
|