diff --git a/README.md b/README.md index 6578ac0..e651482 100644 --- a/README.md +++ b/README.md @@ -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' | @@ -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' ``` @@ -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) diff --git a/action.yml b/action.yml index 8b2e187..c8c6b10 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -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: | @@ -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\", @@ -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<> $GITHUB_OUTPUT echo "$description" >> $GITHUB_OUTPUT @@ -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: | @@ -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({ diff --git a/docs/dev_workflow_steps.png b/docs/dev_workflow_steps.png new file mode 100644 index 0000000..370c4d1 Binary files /dev/null and b/docs/dev_workflow_steps.png differ