Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6,043 changes: 2,824 additions & 3,219 deletions package-lock.json

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,39 +46,39 @@
"outputPath": "build"
},
"devDependencies": {
"@babel/register": "^7.24.6",
"@eslint/js": "^9.10.0",
"@release-it/conventional-changelog": "^8.0.1",
"@types/chai": "^4.3.19",
"@types/chai-as-promised": "^8.0.0",
"@babel/register": "^7.25.9",
"@eslint/js": "^9.19.0",
"@release-it/conventional-changelog": "^10.0.0",
"@types/chai": "^5.0.1",
"@types/chai-as-promised": "^8.0.1",
"@types/eslint__js": "^8.42.3",
"@types/mocha": "^10.0.7",
"@types/node": "^22.5.4",
"@types/mocha": "^10.0.10",
"@types/node": "^22.13.0",
"@types/sinon": "^17.0.3",
"@typescript-eslint/eslint-plugin": "^8.5.0",
"@typescript-eslint/parser": "^8.5.0",
"@typescript-eslint/typescript-estree": "^8.5.0",
"c8": "^10.1.2",
"chai": "^5.1.1",
"chai-as-promised": "^8.0.0",
"@typescript-eslint/eslint-plugin": "^8.22.0",
"@typescript-eslint/parser": "^8.22.0",
"@typescript-eslint/typescript-estree": "^8.22.0",
"c8": "^10.1.3",
"chai": "^5.1.2",
"chai-as-promised": "^8.0.1",
"conventional-changelog-angular": "^8.0.0",
"esbuild": "^0.23.1",
"eslint": "^8.56.0",
"esbuild": "^0.24.2",
"eslint": "^8.57.1",
"eslint-config-standard": "^17.1.0",
"eslint-plugin-import": "^2.30.0",
"mocha": "^10.7.3",
"eslint-plugin-import": "^2.31.0",
"mocha": "^11.1.0",
"nexe": "^3.3.7",
"nock": "^13.5.5",
"nock": "^14.0.0",
"postject": "^1.0.0-alpha.6",
"prettier": "^3.3.3",
"prettier": "^3.4.2",
"proxyquire": "^2.1.3",
"release-it": "^17.6.0",
"release-it": "^18.1.2",
"rimraf": "^6.0.1",
"sinon": "^18.0.0",
"shx": "^0.3.4",
"sinon": "^19.0.2",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.2",
"typescript": "^5.5.4",
"shx": "^0.3.4"
"typescript": "^5.7.3"
},
"overrides": {
"inflight": "^2.0.0",
Expand All @@ -88,12 +88,12 @@
"@humanwhocodes/object-schema": "npm:@eslint/object-schema@latest"
},
"dependencies": {
"@octokit/rest": "^21.0.2",
"commander": "^12.1.0",
"@octokit/rest": "^21.1.0",
"commander": "^13.1.0",
"cosmiconfig": "^9.0.0",
"dotenv": "^16.4.5",
"openai": "^4.58.1",
"simple-git": "^3.26.0"
"dotenv": "^16.4.7",
"openai": "^4.82.0",
"simple-git": "^3.27.0"
},
"repository": {
"type": "git",
Expand Down Expand Up @@ -124,4 +124,4 @@
"engines": {
"node": ">=18.0.0"
}
}
}
11 changes: 9 additions & 2 deletions src/bin/pullcraft.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,21 @@ program
.arguments('[baseBranch] [compareBranch]')
.option('-n, --base-branch <baseBranch>', 'Base branch')
.option('-c, --compare-branch <compareBranch>', 'Compare branch')
.option('-e, --exclusions <patterns>', 'File exclusion patterns (comma-separated)', (value) => value.split(','))
.option(
'-e, --exclusions <patterns>',
'File exclusion patterns (comma-separated)',
(value) => value.split(',')
)
.option('-o, --open-pr', 'Open the PR webpage automatically')
.option('-g, --github-strategy <strategy>', 'GitHub strategy')
.option('-p, --placeholder-pattern <pattern>', 'Placeholder Pattern')
.option('-s, --system-prompt <prompt>', 'System Prompt')
.option('-t, --title-template <title>', 'Title Template')
.option('-d, --description-template <body>', 'Description Template')
.option('-f, --diff-threshold <threshold>', 'Max number of changed lines in a file, defaults to 1000')
.option(
'-f, --diff-threshold <threshold>',
'Max number of changed lines in a file, defaults to 1000'
)
.option('-h, --hint <hint>', 'Hint for the AI about the type of changes')
.option('--api-key <key>', 'OpenAI API Key')
.option('--url <url>', 'OpenAI URL')
Expand Down
108 changes: 99 additions & 9 deletions src/githubClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,51 @@ import cp, { execSync } from 'child_process';
let Octokit: any;

export class GitHubClient {
async listPulls ({ owner, repo, base, head }:{owner: string, repo: string, base: string, head: string}): Promise<any> {
async listPulls ({
owner,
repo,
base,
head
}: {
owner: string;
repo: string;
base: string;
head: string;
}): Promise<any> {
throw new Error('Not implemented');
}

async updatePull ({ owner, repo, pullNumber, title, body }:{owner: string, repo: string, pullNumber: number, title: string, body: string}) {
async updatePull ({
owner,
repo,
pullNumber,
title,
body
}: {
owner: string;
repo: string;
pullNumber: number;
title: string;
body: string;
}) {
throw new Error('Not implemented');
}

async createPull ({ owner, repo, base, head, title, body }:{owner: string, repo: string, base: string, head: string, title: string, body: string}): Promise<any> {
async createPull ({
owner,
repo,
base,
head,
title,
body
}: {
owner: string;
repo: string;
base: string;
head: string;
title: string;
body: string;
}): Promise<any> {
throw new Error('Not implemented');
}
}
Expand All @@ -28,15 +64,51 @@ export class OctokitClient extends GitHubClient {
this.octokit = new Octokit({ auth: githubToken });
}

async listPulls ({ owner, repo, base, head }:{owner: string, repo: string, base: string, head: string}): Promise<any> {
async listPulls ({
owner,
repo,
base,
head
}: {
owner: string;
repo: string;
base: string;
head: string;
}): Promise<any> {
return this.octokit.pulls.list({ owner, repo, base, head });
}

async updatePull ({ owner, repo, pullNumber, title, body }:{owner: string, repo: string, pullNumber: number, title: string, body: string}) {
async updatePull ({
owner,
repo,
pullNumber,
title,
body
}: {
owner: string;
repo: string;
pullNumber: number;
title: string;
body: string;
}) {
return this.octokit.pulls.update({ owner, repo, pullNumber, title, body });
}

async createPull ({ owner, repo, base, head, title, body }:{owner: string, repo: string, base: string, head: string, title: string, body: string}): Promise<any> {
async createPull ({
owner,
repo,
base,
head,
title,
body
}: {
owner: string;
repo: string;
base: string;
head: string;
title: string;
body: string;
}): Promise<any> {
return this.octokit.pulls.create({ owner, repo, base, head, title, body });
}
}
Expand All @@ -50,22 +122,40 @@ export class GhClient implements GitHubClient {
return `'${arg.replace(/'/g, "'\\''")}'`;
}

async listPulls (params: { owner: string; repo: string; base?: string; head?: string }): Promise<any[]> {
async listPulls (params: {
owner: string;
repo: string;
base?: string;
head?: string;
}): Promise<any[]> {
const { owner, repo, base, head } = params;
const command = `gh pr list --json number,title,headRefName -R ${owner}/${repo} --base '${base}' --head '${head}'`;
const output = cp.execSync(command).toString().trim();
return output ? JSON.parse(output) : [];
}

async updatePull (params: { owner: string; repo: string; pullNumber: number; title?: string; body?: string }): Promise<void> {
async updatePull (params: {
owner: string;
repo: string;
pullNumber: number;
title?: string;
body?: string;
}): Promise<void> {
const { owner, repo, pullNumber, title, body } = params;
let command = `gh pr edit ${pullNumber} -R ${owner}/${repo}`;
if (title) command += ` --title ${this.escapeShellArg(title)}`;
if (body) command += ` --body ${this.escapeShellArg(body)}`;
cp.execSync(command);
}

async createPull (params: { owner: string; repo: string; base: string; head: string; title: string; body?: string }): Promise<{ data: { html_url: string } }> {
async createPull (params: {
owner: string;
repo: string;
base: string;
head: string;
title: string;
body?: string;
}): Promise<{ data: { html_url: string } }> {
const { owner, repo, base, head, title, body } = params;
let command = `gh pr create -R ${owner}/${repo} --base ${this.escapeShellArg(base)} --head ${this.escapeShellArg(head)} --title ${this.escapeShellArg(title)}`;
if (body) command += ` --body ${this.escapeShellArg(body)}`;
Expand Down
Loading
Loading