Skip to content

Commit

Permalink
support review pull_request
Browse files Browse the repository at this point in the history
  • Loading branch information
pompurin404 committed Oct 26, 2024
1 parent 3e54409 commit 7837e52
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 6 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/issues.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate Token
uses: tibdex/github-app-token@v2
id: generate
with:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_PRIVATE_KEY }}
- name: Review Issues
uses: ./
with:
github_token: ${{ steps.generate.outputs.token }}
openai_base_url: ${{ secrets.OPENAI_BASE_URL }}
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
openai_model: ${{ vars.OPENAI_MODEL }}
system_prompt: ${{ vars.SYSTEM_PROMPT }}
available_tools: ${{ vars.AVAILABLE_TOOLS }}
system_prompt: ${{ vars.ISSUES_SYSTEM_PROMPT }}
available_tools: ${{ vars.ISSUES_AVAILABLE_TOOLS }}
user_input: |
Please review this issue:
Title: "${{ github.event.issue.title }}"
Content: "${{ github.event.issue.body }}"
github_token: ${{ secrets.POMPURIN404_TOKEN }}
38 changes: 38 additions & 0 deletions .github/workflows/pull_request.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
name: Review Issues

on:
pull_request_target:
types: [opened]

jobs:
review:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Fetch Patch Content
id: fetch
run: |
echo 'patch<<EOF' >> $GITHUB_OUTPUT
curl -L ${{ github.event.pull_request.patch_url }} >> $GITHUB_OUTPUT
echo 'EOF' >> $GITHUB_OUTPUT
- name: Generate Token
uses: tibdex/github-app-token@v2
id: generate
with:
app_id: ${{ secrets.BOT_APP_ID }}
private_key: ${{ secrets.BOT_PRIVATE_KEY }}
- name: Review Pull Request
uses: ./
with:
github_token: ${{ steps.generate.outputs.token }}
openai_base_url: ${{ secrets.OPENAI_BASE_URL }}
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
openai_model: ${{ vars.OPENAI_MODEL }}
system_prompt: ${{ vars.PULL_SYSTEM_PROMPT }}
available_tools: ${{ vars.PULL_AVAILABLE_TOOLS }}
user_input: |
Please review this pull request:
Title: "${{ github.event.pull_request.title }}"
Content: "${{ github.event.pull_request.body }}"
Changes: "${{ steps.fetch.outputs.patch }}"
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
- [x] Comment issue(commentIssue)
- [x] Label issue(labelIssue)
- [x] Rename issue(renameIssue)
- [x] Review pull request(reviewPullRequest)
- [ ] and more...

## Inputs
Expand Down
23 changes: 22 additions & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40022,8 +40022,8 @@ const zod_1 = __nccwpck_require__(931);
const zod_to_json_schema_1 = __importDefault(__nccwpck_require__(3109));
const github = __importStar(__nccwpck_require__(3802));
const _1 = __nccwpck_require__(3300);
const octokit = github.getOctokit(_1.github_token);
async function init_tools() {
const octokit = github.getOctokit(_1.github_token);
let repo_labels = [
"bug",
"enhancement",
Expand Down Expand Up @@ -40136,12 +40136,33 @@ async function init_tools() {
},
schema: RenameParams,
});
// review pull request
const ReviewParams = zod_1.z.object({
event: zod_1.z.enum(["APPROVE", "REQUEST_CHANGES", "COMMENT"]),
content: zod_1.z.string(),
});
const reviewPullRequest = zodFunction({
name: "reviewPullRequest",
description: "Review Pull Request",
function: async ({ event, content }) => {
octokit.rest.pulls.createReview({
owner: github.context.issue.owner,
repo: github.context.issue.repo,
pull_number: github.context.issue.number,
body: content,
event,
});
console.log(`#${github.context.issue.number} Reviewd as ${event}\n${content}`);
},
schema: ReviewParams,
});
return {
closeIssue,
lockIssue,
commentIssue,
labelIssue,
renameIssue,
reviewPullRequest,
};
}
// utils function
Expand Down
28 changes: 26 additions & 2 deletions src/github_calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import zodToJsonSchema from "zod-to-json-schema";
import * as github from "@actions/github";
import { github_token } from ".";

const octokit = github.getOctokit(github_token);

type Tools = Record<string, RunnableToolFunctionWithParse<any>>;

export async function init_tools(): Promise<Tools> {
const octokit = github.getOctokit(github_token);
let repo_labels: [string, ...string[]] = [
"bug",
"enhancement",
Expand Down Expand Up @@ -132,12 +131,37 @@ export async function init_tools(): Promise<Tools> {
schema: RenameParams,
});

// review pull request
const ReviewParams = z.object({
event: z.enum(["APPROVE", "REQUEST_CHANGES", "COMMENT"]),
content: z.string(),
});
type ReviewParams = z.infer<typeof ReviewParams>;
const reviewPullRequest = zodFunction({
name: "reviewPullRequest",
description: "Review Pull Request",
function: async ({ event, content }: ReviewParams) => {
octokit.rest.pulls.createReview({
owner: github.context.issue.owner,
repo: github.context.issue.repo,
pull_number: github.context.issue.number,
body: content,
event,
});
console.log(
`#${github.context.issue.number} Reviewd as ${event}\n${content}`
);
},
schema: ReviewParams,
});

return {
closeIssue,
lockIssue,
commentIssue,
labelIssue,
renameIssue,
reviewPullRequest,
};
}

Expand Down

0 comments on commit 7837e52

Please sign in to comment.