diff --git a/.github/workflows/summarizer.yml b/.github/workflows/summarizer.yml index ea262c1..11e0cd3 100644 --- a/.github/workflows/summarizer.yml +++ b/.github/workflows/summarizer.yml @@ -4,6 +4,10 @@ on: pull_request: types: [opened, synchronize, reopened] +permissions: + pull-requests: write + contents: read + jobs: summarize: runs-on: ubuntu-latest @@ -26,4 +30,9 @@ jobs: env: GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }} GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: python src/main.py \ No newline at end of file + PR_NUMBER: ${{ github.event.pull_request.number }} + GITHUB_REPOSITORY: ${{ github.repository }} + run: | + python main.py > summary.txt + SUMMARY=$(cat summary.txt) + echo "$SUMMARY" \ No newline at end of file diff --git a/README.md b/README.md index e69de29..da6b3eb 100644 --- a/README.md +++ b/README.md @@ -0,0 +1,7 @@ +# nopejs Bot + +➤ Auto-generates concise summaries for GitHub pull requests using Gemini. + +## Overview + +nopejs is a GitHub Action that triggers on PR events, analyzes the PR content, and posts a summary. \ No newline at end of file diff --git a/src/__init__.py b/__init__.py similarity index 95% rename from src/__init__.py rename to __init__.py index d977131..5f97dab 100644 --- a/src/__init__.py +++ b/__init__.py @@ -2,4 +2,4 @@ GitHub PR Summarizer Bot This package uses the Gemini API to summarize pull requests. -""" \ No newline at end of file +""" diff --git a/src/main.py b/main.py similarity index 83% rename from src/main.py rename to main.py index c739545..db371c9 100644 --- a/src/main.py +++ b/main.py @@ -4,7 +4,7 @@ GITHUB_API = "https://api.github.com" REPO = os.getenv("GITHUB_REPOSITORY") -PR_NUMBER = os.getenv("GITHUB_REF").split("/")[-1] +PR_NUMBER = os.getenv("PR_NUMBER") TOKEN = os.getenv("GITHUB_TOKEN") headers = { @@ -30,6 +30,9 @@ def post_comment(comment): requests.post(url, headers=headers, json={"body": comment}) if __name__ == "__main__": + if not os.getenv("GEMINI_API_KEY"): + print("[DEBUG] GEMINI_API_KEY is not set.") pr_body, diff = get_pr_data() summary = generate_summary(pr_body, diff) - post_comment(f"**PR Summary**\n\n{summary}") \ No newline at end of file + post_comment(f"**PR Summary**\n\n{summary}") + print(summary) \ No newline at end of file diff --git a/setup.py b/setup.py index a4af97e..f92d880 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,19 @@ + from setuptools import setup, find_packages +import os + +def readme(): + try: + with open(os.path.join(os.path.dirname(__file__), 'README.md')) as f: + return f.read() + except Exception: + return '' + setup( name='github-pr-summarizer', version='0.1.0', - packages=find_packages(where="src"), - package_dir={"": "src"}, + packages=find_packages(), install_requires=[ 'google-generativeai>=0.3.2', 'requests>=2.31.0', @@ -17,11 +26,11 @@ }, author='Your Name', description='A GitHub Action bot that summarizes pull requests using Google Gemini API', - long_description=open('README.md').read(), + long_description=readme(), long_description_content_type='text/markdown', classifiers=[ 'Programming Language :: Python :: 3', 'License :: OSI Approved :: MIT License', ], python_requires='>=3.8', -) +) \ No newline at end of file diff --git a/src/summarizer.py b/summarizer.py similarity index 100% rename from src/summarizer.py rename to summarizer.py