generated from ztimson/template
Update
This commit is contained in:
8
.env
Normal file
8
.env
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
GIT_HOST=
|
||||||
|
GIT_OWNER=
|
||||||
|
GIT_REPO=
|
||||||
|
GIT_TOKEN=
|
||||||
|
PULL_REQUEST=
|
||||||
|
AI_HOST=
|
||||||
|
AI_MODEL=
|
||||||
|
AI_TOKEN=
|
||||||
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.env.local
|
||||||
22
package-lock.json
generated
22
package-lock.json
generated
@@ -10,7 +10,9 @@
|
|||||||
"license": "ISC",
|
"license": "ISC",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ztimson/ai-utils": "0.2.3",
|
"@ztimson/ai-utils": "0.2.3",
|
||||||
"@ztimson/utils": "^0.28.3"
|
"@ztimson/node-utils": "^1.0.7",
|
||||||
|
"@ztimson/utils": "^0.28.3",
|
||||||
|
"dotenv": "^17.2.3"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@anthropic-ai/sdk": {
|
"node_modules/@anthropic-ai/sdk": {
|
||||||
@@ -311,9 +313,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@ztimson/node-utils": {
|
"node_modules/@ztimson/node-utils": {
|
||||||
"version": "1.0.4",
|
"version": "1.0.7",
|
||||||
"resolved": "https://registry.npmjs.org/@ztimson/node-utils/-/node-utils-1.0.4.tgz",
|
"resolved": "https://registry.npmjs.org/@ztimson/node-utils/-/node-utils-1.0.7.tgz",
|
||||||
"integrity": "sha512-EVI0CQYvrzRV7f9pmy13piyFfF9htYS4Kf2W/dW4HzSBEPTO//mGPZthWyQXnxvMeG6p3e5hAPlQ4hAmrRDv6A==",
|
"integrity": "sha512-BqrEMfW3/FKyYnTnL1uzxHUZFUeg2FaRGjL9tWAFkw8M99HcN9HoStdrPL6JfLSudvCwDbGzUJSEP6GL0E8uoQ==",
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
"node_modules/@ztimson/utils": {
|
"node_modules/@ztimson/utils": {
|
||||||
@@ -682,6 +684,18 @@
|
|||||||
"node": ">=8"
|
"node": ">=8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"node_modules/dotenv": {
|
||||||
|
"version": "17.2.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/dotenv/-/dotenv-17.2.3.tgz",
|
||||||
|
"integrity": "sha512-JVUnt+DUIzu87TABbhPmNfVdBDt18BLOWjMUFJMSi/Qqg7NTYtabbvSNJGOJ7afbRuv9D/lngizHtP7QyLQ+9w==",
|
||||||
|
"license": "BSD-2-Clause",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=12"
|
||||||
|
},
|
||||||
|
"funding": {
|
||||||
|
"url": "https://dotenvx.com"
|
||||||
|
}
|
||||||
|
},
|
||||||
"node_modules/dunder-proto": {
|
"node_modules/dunder-proto": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
"resolved": "https://registry.npmjs.org/dunder-proto/-/dunder-proto-1.0.1.tgz",
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
"description": "",
|
"description": "",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ztimson/ai-utils": "0.2.3",
|
"@ztimson/ai-utils": "0.2.3",
|
||||||
|
"@ztimson/node-utils": "^1.0.7",
|
||||||
"@ztimson/utils": "^0.28.3",
|
"@ztimson/utils": "^0.28.3",
|
||||||
"@ztimson/node-utils": "^1.0.4"
|
"dotenv": "^17.2.3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,11 @@ import {$} from '@ztimson/node-utils';
|
|||||||
import * as os from 'node:os';
|
import * as os from 'node:os';
|
||||||
import * as path from 'node:path';
|
import * as path from 'node:path';
|
||||||
import * as fs from 'node:fs';
|
import * as fs from 'node:fs';
|
||||||
|
import * as dotenv from 'dotenv';
|
||||||
|
import {execSync} from 'node:child_process';
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
dotenv.config({path: '.env.local', override: true});
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const
|
const
|
||||||
@@ -16,9 +21,13 @@ import * as fs from 'node:fs';
|
|||||||
model = process.env['AI_MODEL'],
|
model = process.env['AI_MODEL'],
|
||||||
token = process.env['AI_TOKEN'];
|
token = process.env['AI_TOKEN'];
|
||||||
|
|
||||||
|
|
||||||
const comments = [];
|
const comments = [];
|
||||||
const commit = (await $`git log -1 --pretty=format:%H`).trim();
|
const commit = await $`cd ${root} && git log -1 --pretty=format:%H`;
|
||||||
const gitDiff = await $`git diff HEAD^..HEAD`;
|
const remote = await $`cd ${root} && git symbolic-ref refs/remotes/origin/HEAD`;
|
||||||
|
const gitDiff = execSync(`git diff ${remote}...HEAD`, {cwd: root, encoding: 'utf-8'});
|
||||||
|
|
||||||
|
console.log(`Inspecting: ${root} (${commit})`);
|
||||||
|
|
||||||
let options = {ollama: {model, host}};
|
let options = {ollama: {model, host}};
|
||||||
if(host === 'anthropic') options = {anthropic: {model, token}};
|
if(host === 'anthropic') options = {anthropic: {model, token}};
|
||||||
@@ -61,7 +70,13 @@ import * as fs from 'node:fs';
|
|||||||
}]
|
}]
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if(!gitDiff) {
|
||||||
|
console.warn('No diff found');
|
||||||
|
return process.exit();
|
||||||
|
}
|
||||||
|
|
||||||
const summary = await ai.language.ask(gitDiff);
|
const summary = await ai.language.ask(gitDiff);
|
||||||
|
if(git) {
|
||||||
const res = await fetch(`${git}/api/v1/repos/${owner}/${repo}/pulls/${pr}/reviews`, {
|
const res = await fetch(`${git}/api/v1/repos/${owner}/${repo}/pulls/${pr}/reviews`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -76,4 +91,7 @@ import * as fs from 'node:fs';
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
if(!res.ok) throw new Error(`${res.status} ${await res.text()}`);
|
if(!res.ok) throw new Error(`${res.status} ${await res.text()}`);
|
||||||
|
} else {
|
||||||
|
console.log(comments.map(c => `${c.path}:${c.new_position}\n${c.body}`).join('\n\n') + '\n\n' + summary);
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
|||||||
Reference in New Issue
Block a user