PR-Story is a GitHub App that transforms the commit messages of a pull request into a visual narrative. It uses AI to generate a story and accompanying images, which are then posted as a comment on the pull request. This provides a unique and intuitive way to understand the changes introduced in a PR.
- Listens for Pull Request Events: The app is triggered when a new pull request is opened.
- AI-Powered Narrative Generation: It uses an OpenAI model to convert commit messages into a compelling story.
- Text-to-Image Generation: A Diffusion Pipeline from Hugging Face's
diffuserslibrary creates images based on the generated story. - Automated PR Commenting: The generated images and their corresponding story captions are posted as a comment on the pull request.
- Webhook Trigger: A webhook is configured to listen for
pull_requestevents from GitHub. - Fetch Commit Messages: When a pull request is opened, the app fetches all the commit messages associated with it.
- Generate Story and Prompts: The commit messages are sent to an OpenAI model (GPT-4o) to generate a narrative. This narrative is broken down into a series of prompts for the text-to-image model.
- Generate Images: The prompts are fed into a pre-trained text-to-image model (
playgroundai/playground-v2.5-1024px-aesthetic) to generate a sequence of images. - Upload Images: The generated images are uploaded to Imgur to get public URLs.
- Post Comment: A comment is created on the pull request, containing the images and their corresponding captions, forming a visual story of the changes.
-
Clone the Repository:
git clone https://github.com/BH3325/pr_story.git cd pr_story -
Create a GitHub App:
- Go to your GitHub settings and create a new GitHub App.
- Set the Webhook URL to your application's public URL (e.g.,
https://your-domain.com/webhooks). - Create a Webhook Secret and save it.
- Under Permissions, grant the following repository permissions:
- Pull requests: Read & write
- Contents: Read-only
- Install the app on your target repositories.
- Generate a private key for your app and download it.
-
Set Up Environment Variables: Create a
.envfile in the root of the project and add the following variables:APP_ID="your_github_app_id" WEBHOOK_SECRET="your_github_app_webhook_secret" PK="your_base64_encoded_private_key" OPENAI_API_KEY="your_openai_api_key" IMGUR_CLIENT_ID="your_imgur_client_id"PKshould be the base64 encoded version of your GitHub App's private key. You can encode it using:cat your-private-key.pem | base64
-
Install Dependencies: This project uses
uvfor package management.pip install uv uv sync
-
Run the Application: Use
uvicornto run the FastAPI application:uv run uvicorn main:app --host 0.0.0.0 --port 8000
Once the app is running and installed on a repository:
- Open a new pull request in that repository.
- The app will automatically process the commit messages and post a comment with the visual story.
- Fine tuning: Improve specificity of generated images to better match code context.
- Theme customisation: Allow users to select different art styles for image generation.
- Audio integration: Generate songs or soundscapes to accompany the visual story.