Skip to content

Commit

Permalink
📚 Update README and action.yml with new OpenAI model input
Browse files Browse the repository at this point in the history
🔧 This commit introduces the following changes:

- Added a new input parameter `openai_model` to customize the OpenAI model used for generating PR descriptions
- Updated the README to reflect the new input and its default value
- Modified the `action.yml` file to incorporate the new `openai_model` parameter
- Improved error handling for OpenAI API responses
- Added a visual representation of the development workflow in the README
- Included a new image file `dev_workflow_steps.png` in the `docs` folder

These updates enhance the flexibility of the action by allowing users to specify their preferred OpenAI model. The README now provides a more comprehensive guide to the development workflow, making it easier for contributors to understand the project structure and processes.
  • Loading branch information
yuri-val committed Oct 19, 2024
1 parent d703456 commit 33a5297
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 3 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This GitHub Action automatically creates or updates a Pull Request from a develo
| Name | Description | Required | Default |
|------|-------------|----------|---------|
| `openai_api_key` | OpenAI API Key | Yes | N/A |
| `openai_model` | OpenAI model to use for generating PR descriptions | No | 'gpt-4o-mini' |
| `github_token` | GitHub Personal Access Token with repo permissions | Yes | N/A |
| `dev_branch` | Name of the development branch | No | 'dev' |

Expand All @@ -34,6 +35,7 @@ To use this action in your workflow, add the following step:
uses: yuri-val/auto-pr-action@v1
with:
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
openai_model: gpt-4o # Optional, defaults to 'gpt-4o-mini'
github_token: ${{ secrets.GITHUB_TOKEN }}
dev_branch: dev # Optional, defaults to 'dev'
```
Expand Down Expand Up @@ -75,6 +77,44 @@ jobs:
6. Creates a new PR or updates an existing one
7. Adds relevant reviewers to the PR

## GitHub Workflow Description (Development Workflow)

### Branch Structure
1. Default Branch: `main` or `master`
2. Development Branch: `dev`
3. Feature Branches: Multiple branches like `feature/new_awesome_feature`, `feature/new_files`, etc.

### Workflow Steps

![alt text](docs/dev_workflow_steps.png)

1. **Branch Creation:**
- The `dev` branch is created from the default branch (`main` or `master`).
- `dev` always contains all commits from the default branch.

2. **Feature Development:**
- Multiple feature branches are created from `dev`.
- Examples: `feature/new_awesome_feature`, `feature/new_files`, etc.
- Developers work on these feature branches.

3. **Feature Integration:**
- When a feature is complete, it is merged into the `dev` branch.

4. **Automated Pull Request Creation/Update:**
- On every merge to `dev` (or any push to `dev`):
- An automated process creates or updates a Pull Request from `dev` to the default branch (`main` or `master`).
- The Pull Request description is automatically generated using OpenAI's API.
- This ensures that the default branch is always aware of changes in `dev`.

5. **Continuous Integration:**
- The `dev` branch continuously integrates new features.
- The automated PR to the default branch is kept up-to-date with these changes.

6. **Review and Merge:**
- The auto-generated PR can be reviewed and eventually merged into the default branch when ready.

This workflow allows for organized feature development, continuous integration into the `dev` branch, and an always up-to-date PR to the default branch with AI-generated descriptions for easy review and merging.

## License

[MIT License](LICENSE)
Expand Down
18 changes: 15 additions & 3 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ inputs:
openai_api_key:
description: 'OpenAI API Key'
required: true
openai_model:
description: 'OpenAI model to use (e.g., gpt-4, gpt-3.5-turbo, etc.) https://platform.openai.com/docs/models'
required: false
default: 'gpt-4o-mini'
github_token:
description: 'GitHub (PAT) token with repo permissions'
required: true
Expand Down Expand Up @@ -79,6 +83,7 @@ runs:
id: generate_release_notes
env:
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
OPENAI_MODEL: ${{ inputs.openai_model }}
DIFF_OUTPUT: ${{ steps.get_diff.outputs.diff_output }}
shell: bash
run: |
Expand All @@ -91,7 +96,7 @@ runs:
-H "Content-Type: application/json" \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-d "{
\"model\": \"gpt-4o-mini\",
\"model\": \"${OPENAI_MODEL}\",
\"messages\": [
{
\"role\": \"system\",
Expand All @@ -109,6 +114,13 @@ runs:
\"presence_penalty\": 0
}")
# Check for errors in the response
error_message=$(echo "$response" | jq -r '.error.message // empty')
if [ -n "$error_message" ]; then
echo "Error from OpenAI API: $error_message"
exit 1
fi
description=$(echo "$response" | jq -r '.choices[0].message.content')
echo "description<<EOF" >> $GITHUB_OUTPUT
echo "$description" >> $GITHUB_OUTPUT
Expand All @@ -125,7 +137,7 @@ runs:
uses: actions/github-script@v6
env:
PR_TITLE: ${{ steps.set_release_title.outputs.title }}
PR_BODY: ${{ steps.generate_release_notes.outputs.description }}
PR_BODY: ${{ toJSON(steps.generate_release_notes.outputs.description) }}
with:
github-token: ${{ inputs.github_token }}
script: |
Expand All @@ -134,7 +146,7 @@ runs:
const head = '${{ inputs.dev_branch }}';
const base = '${{ steps.get_default_branch.outputs.branch }}';
const title = process.env.PR_TITLE;
const body = process.env.PR_BODY;
const body = JSON.parse(process.env.PR_BODY);
// Check if PR from dev to default branch already exists
const { data: pulls } = await github.rest.pulls.list({
Expand Down
Binary file added docs/dev_workflow_steps.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 33a5297

Please sign in to comment.