mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-07-05 21:30:40 +08:00
Merge pull request #47 from Codium-ai/feature/github_action
Github custom action development
This commit is contained in:
16
.github/workflows/review.yaml
vendored
Normal file
16
.github/workflows/review.yaml
vendored
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
issue_comment:
|
||||||
|
jobs:
|
||||||
|
pr_agent_job:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
name: Run pr agent on every pull request
|
||||||
|
steps:
|
||||||
|
- name: PR Agent action step
|
||||||
|
id: pragent
|
||||||
|
uses: Codium-ai/pr-agent@feature/github_action
|
||||||
|
env:
|
||||||
|
OPENAI_KEY: ${{ secrets.OPENAI_KEY }}
|
||||||
|
OPENAI_ORG: ${{ secrets.OPENAI_ORG }}
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
10
Dockerfile.github_action
Normal file
10
Dockerfile.github_action
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
FROM python:3.10 as base
|
||||||
|
|
||||||
|
WORKDIR /app
|
||||||
|
ADD requirements.txt .
|
||||||
|
RUN pip install -r requirements.txt && rm requirements.txt
|
||||||
|
ENV PYTHONPATH=/app
|
||||||
|
ADD pr_agent pr_agent
|
||||||
|
ADD github_action/entrypoint.sh /
|
||||||
|
RUN chmod +x /entrypoint.sh
|
||||||
|
ENTRYPOINT ["/entrypoint.sh"]
|
5
action.yaml
Normal file
5
action.yaml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
name: 'PR Agent'
|
||||||
|
description: 'Summarize, review and suggest improvements for pull requests'
|
||||||
|
runs:
|
||||||
|
using: 'docker'
|
||||||
|
image: 'Dockerfile.github_action'
|
2
github_action/entrypoint.sh
Normal file
2
github_action/entrypoint.sh
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
python /app/pr_agent/servers/github_action_runner.py
|
58
pr_agent/servers/github_action_runner.py
Normal file
58
pr_agent/servers/github_action_runner.py
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
import asyncio
|
||||||
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
|
from pr_agent.config_loader import settings
|
||||||
|
from pr_agent.tools.pr_questions import PRQuestions
|
||||||
|
from pr_agent.tools.pr_reviewer import PRReviewer
|
||||||
|
|
||||||
|
|
||||||
|
async def run_action():
|
||||||
|
GITHUB_EVENT_NAME = os.environ.get('GITHUB_EVENT_NAME', None)
|
||||||
|
if not GITHUB_EVENT_NAME:
|
||||||
|
print("GITHUB_EVENT_NAME not set")
|
||||||
|
return
|
||||||
|
GITHUB_EVENT_PATH = os.environ.get('GITHUB_EVENT_PATH', None)
|
||||||
|
if not GITHUB_EVENT_PATH:
|
||||||
|
print("GITHUB_EVENT_PATH not set")
|
||||||
|
return
|
||||||
|
event_payload = json.load(open(GITHUB_EVENT_PATH, 'r'))
|
||||||
|
RUNNER_DEBUG = os.environ.get('RUNNER_DEBUG', None)
|
||||||
|
if not RUNNER_DEBUG:
|
||||||
|
print("RUNNER_DEBUG not set")
|
||||||
|
OPENAI_KEY = os.environ.get('OPENAI_KEY', None)
|
||||||
|
if not OPENAI_KEY:
|
||||||
|
print("OPENAI_KEY not set")
|
||||||
|
return
|
||||||
|
OPENAI_ORG = os.environ.get('OPENAI_ORG', None)
|
||||||
|
GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN', None)
|
||||||
|
if not GITHUB_TOKEN:
|
||||||
|
print("GITHUB_TOKEN not set")
|
||||||
|
return
|
||||||
|
settings.set("OPENAI.KEY", OPENAI_KEY)
|
||||||
|
if OPENAI_ORG:
|
||||||
|
settings.set("OPENAI.ORG", OPENAI_ORG)
|
||||||
|
settings.set("GITHUB.USER_TOKEN", GITHUB_TOKEN)
|
||||||
|
settings.set("GITHUB.DEPLOYMENT_TYPE", "user")
|
||||||
|
if GITHUB_EVENT_NAME == "pull_request":
|
||||||
|
action = event_payload.get("action", None)
|
||||||
|
if action in ["opened", "reopened"]:
|
||||||
|
pr_url = event_payload.get("pull_request", {}).get("url", None)
|
||||||
|
if pr_url:
|
||||||
|
await PRReviewer(pr_url).review()
|
||||||
|
|
||||||
|
elif GITHUB_EVENT_NAME == "issue_comment":
|
||||||
|
action = event_payload.get("action", None)
|
||||||
|
if action in ["created", "edited"]:
|
||||||
|
comment_body = event_payload.get("comment", {}).get("body", None)
|
||||||
|
if comment_body:
|
||||||
|
pr_url = event_payload.get("issue", {}).get("pull_request", {}).get("url", None)
|
||||||
|
if pr_url:
|
||||||
|
if comment_body.strip().lower() == "review":
|
||||||
|
await PRReviewer(pr_url).review()
|
||||||
|
elif comment_body.lstrip().lower().startswith("answer"):
|
||||||
|
await PRQuestions(pr_url, comment_body).answer()
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
asyncio.run(run_action())
|
Reference in New Issue
Block a user