Skip to content

Commit

Permalink
Allow users to opt-in for existing PR description overwrite
Browse files Browse the repository at this point in the history
Allow users to run the action and overwrite the PR description
even if one already exists.
This will allow for the description to remain consistent with the
PR changes and not require for the users to manually clear out the
PR description in order to get the Action to run.

Requested and fixes #5
  • Loading branch information
platisd committed May 21, 2024
1 parent 6159e09 commit 96f5b05
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
28 changes: 15 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ fill up the description of your pull request. Just like ChatGPT would! 🎉<br>
The Action tries to focus on **why** the changes are needed rather on **what** they are,
like any proper pull request description should.

The GitHub Action will only run when a PR description is not already provided.
In other words it will not accidentally overwrite your existing description.
The GitHub Action will (by default) only run when a PR description is not already provided.
In other words it will not accidentally overwrite your existing description,
unless you opt-in to do so by setting the `overwrite_description` input to `true`.
The idea is this Action will save you the time and trouble of writing **meaningful** pull request descriptions.<br>
You can customize it in different ways. One of them allows the Action to only run on pull requests started
by specific users, e.g. the main maintainers of the repository.
Expand Down Expand Up @@ -42,17 +43,18 @@ jobs:
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
```
| Input | Description | Required | Default |
| ------------------- | -------------------------------------------------------------- | -------- | -------------------------- |
| `github_token` | The GitHub token to use for the Action | Yes | |
| `openai_api_key` | The [OpenAI API key] to use, keep it hidden | Yes | |
| `pull_request_id` | The ID of the pull request to use | No | Extracted from metadata |
| `openai_model` | The [OpenAI model] to use | No | `gpt-3.5-turbo` |
| `max_tokens` | The maximum number of **prompt tokens** to use | No | `1000` |
| `temperature` | Higher values will make the model more creative (0-2) | No | `0.6` |
| `sample_prompt` | The prompt to use for giving context to the model | No | See `SAMPLE_PROMPT` |
| `sample_response` | A sample response for giving context to the model | No | See `GOOD_SAMPLE_RESPONSE` |
| `completion_prompt` | The prompt to use for the model to generate the PR description | No | See `COMPLETION_PROMPT` |
| Input | Description | Required | Default |
| ----------------------- | -------------------------------------------------------------- | -------- | -------------------------- |
| `github_token` | The GitHub token to use for the Action | Yes | |
| `openai_api_key` | The [OpenAI API key] to use, keep it hidden | Yes | |
| `pull_request_id` | The ID of the pull request to use | No | Extracted from metadata |
| `openai_model` | The [OpenAI model] to use | No | `gpt-3.5-turbo` |
| `max_tokens` | The maximum number of **prompt tokens** to use | No | `1000` |
| `temperature` | Higher values will make the model more creative (0-2) | No | `0.6` |
| `sample_prompt` | The prompt to use for giving context to the model | No | See `SAMPLE_PROMPT` |
| `sample_response` | A sample response for giving context to the model | No | See `GOOD_SAMPLE_RESPONSE` |
| `completion_prompt` | The prompt to use for the model to generate the PR description | No | See `COMPLETION_PROMPT` |
| `overwrite_description` | Whether to overwrite the PR description if it already exists | No | `false` |


[OpenAI API key]: https://help.openai.com/en/articles/4936850-where-do-i-find-my-secret-api-key
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ inputs:
description: 'Prompt to use as the final prompt to the model, refer to COMPLETION_PROMPT in the Python file.'
required: false
default: ''
overwrite_description:
description: 'Overwrite the PR description if it already exists. This also means that the action will run on every PR update'
required: false
default: 'false'

runs:
using: 'docker'
Expand Down
3 changes: 2 additions & 1 deletion autofill_description.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,8 @@ def main():
return 1
pull_request_data = json.loads(pull_request_result.text)

if pull_request_data["body"]:
overwrite_description = os.environ.get("INPUT_OVERWRITE_DESCRIPTION", "false")
if pull_request_data["body"] and overwrite_description.lower() == "false":
print("Pull request already has a description, skipping")
return 0

Expand Down

0 comments on commit 96f5b05

Please sign in to comment.