From 5742a9be1e822babd06a8fe57e5d78d3c5d83a0f Mon Sep 17 00:00:00 2001 From: Ori Kotek Date: Thu, 13 Jul 2023 17:46:12 +0300 Subject: [PATCH] Github custom action development --- .github/workflows/review.yaml | 13 +++++++++++ Dockerfile.github_action | 10 +++++++++ action.yaml | 10 +++++++++ github_action/entrypoint.sh | 2 ++ pr_agent/servers/github_action_runner.py | 28 ++++++++++++++++++++++++ 5 files changed, 63 insertions(+) create mode 100644 .github/workflows/review.yaml create mode 100644 Dockerfile.github_action create mode 100644 action.yaml create mode 100644 github_action/entrypoint.sh create mode 100644 pr_agent/servers/github_action_runner.py diff --git a/.github/workflows/review.yaml b/.github/workflows/review.yaml new file mode 100644 index 00000000..93ad8040 --- /dev/null +++ b/.github/workflows/review.yaml @@ -0,0 +1,13 @@ +on: [push] + +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 + with: + openai-key: "TBD: openai key" + diff --git a/Dockerfile.github_action b/Dockerfile.github_action new file mode 100644 index 00000000..c7211787 --- /dev/null +++ b/Dockerfile.github_action @@ -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"] diff --git a/action.yaml b/action.yaml new file mode 100644 index 00000000..3b1949ce --- /dev/null +++ b/action.yaml @@ -0,0 +1,10 @@ +name: 'PR Agent' +description: 'Summarize, review and suggest improvements for pull requests' +inputs: + openai-key: # id of input + description: 'OpenAI Key' + required: true + default: '' +runs: + using: 'docker' + image: 'Dockerfile.github_action' diff --git a/github_action/entrypoint.sh b/github_action/entrypoint.sh new file mode 100644 index 00000000..4d493c7c --- /dev/null +++ b/github_action/entrypoint.sh @@ -0,0 +1,2 @@ +#!/bin/bash +python /app/pr_agent/servers/github_action_runner.py diff --git a/pr_agent/servers/github_action_runner.py b/pr_agent/servers/github_action_runner.py new file mode 100644 index 00000000..39f7469d --- /dev/null +++ b/pr_agent/servers/github_action_runner.py @@ -0,0 +1,28 @@ +import json +import os + + +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')) + GITHUB_REPOSITORY = os.environ.get('GITHUB_REPOSITORY', None) + if not GITHUB_REPOSITORY: + print("GITHUB_REPOSITORY not set") + return + print(event_payload) + print(GITHUB_REPOSITORY) + print(GITHUB_EVENT_NAME) + print(GITHUB_EVENT_PATH) + print("Hello from run_action") + RUNNER_DEBUG = os.environ.get('RUNNER_DEBUG', None) + if not RUNNER_DEBUG: + print("RUNNER_DEBUG not set") + return + print(RUNNER_DEBUG)