|
| 1 | +--- |
| 2 | +hide: |
| 3 | + - revision_date |
| 4 | + - revision_history |
| 5 | +--- |
| 6 | + |
| 7 | +# configuration options |
| 8 | + |
| 9 | +this page documents all the configuration options available for the openai summarize diff action. |
| 10 | + |
| 11 | +## input parameters |
| 12 | + |
| 13 | +the action accepts the following inputs, which can be specified in your workflow file: |
| 14 | + |
| 15 | +| parameter | required | default | description | |
| 16 | +|-----------|----------|---------|-------------| |
| 17 | +| `diff` | yes | - | the git diff to be explained. typically generated via `git diff` command. | |
| 18 | +| `apikey` | yes | - | your openai api key. should be stored as a secret. | |
| 19 | +| `examplePostSummary` | no | "update the code with new features: parallelisation, caching, and better error handling" | an example summary to guide the model's output style. | |
| 20 | +| `maxTokens` | no | 30 | maximum number of tokens to generate. this affects the length of the generated explanation. | |
| 21 | +| `maxCharacters` | no | 140 | maximum characters in the generated explanation. useful for ensuring the explanation fits in limited spaces. | |
| 22 | + |
| 23 | +## detailed parameter information |
| 24 | + |
| 25 | +### `diff` |
| 26 | + |
| 27 | +the git diff to be explained. this should be the output from a git diff command. you'll typically generate this in your workflow using a command like: |
| 28 | + |
| 29 | +```bash |
| 30 | +git diff origin/${{ github.event.pull_request.base.ref }}..HEAD |
| 31 | +``` |
| 32 | + |
| 33 | +the diff should be provided in the standard git diff format: |
| 34 | + |
| 35 | +```diff |
| 36 | +diff --git a/file.js b/file.js |
| 37 | +index 123..456 789 |
| 38 | +--- a/file.js |
| 39 | ++++ b/file.js |
| 40 | +@@ -1,3 +1,4 @@ |
| 41 | + const a = 1; |
| 42 | ++const b = 2; |
| 43 | + const c = 3; |
| 44 | +``` |
| 45 | + |
| 46 | +### `apikey` |
| 47 | + |
| 48 | +your openai api key. this should be stored as a github repository secret and referenced in your workflow like this: |
| 49 | + |
| 50 | +```yaml |
| 51 | +apikey: ${{ secrets.OPENAI_API_KEY }} |
| 52 | +``` |
| 53 | +
|
| 54 | +never hardcode your api key directly in the workflow file. |
| 55 | +
|
| 56 | +### `examplePostSummary` |
| 57 | + |
| 58 | +an example summary to guide the model's output style. this helps the openai model understand the tone, format, and style you want for the generated explanation. |
| 59 | + |
| 60 | +examples: |
| 61 | + |
| 62 | +- `"feat: added user authentication and improved error handling"` |
| 63 | +- `"fix: resolved memory leak in data processing pipeline"` |
| 64 | +- `"refactor: simplified API response handling for better maintainability"` |
| 65 | + |
| 66 | +### `maxTokens` |
| 67 | + |
| 68 | +maximum number of tokens to generate. openai models use tokens, which are chunks of text (roughly 4 characters per token in english). this parameter limits the length of the generated explanation. |
| 69 | + |
| 70 | +recommended values: |
| 71 | +- short summaries: 20-30 |
| 72 | +- medium explanations: 50-100 |
| 73 | +- detailed explanations: 100-200 |
| 74 | + |
| 75 | +note that higher values may result in higher api costs. |
| 76 | + |
| 77 | +### `maxCharacters` |
| 78 | + |
| 79 | +maximum characters in the generated explanation. this parameter ensures the explanation fits within specific character limits (like tweet length, commit message limits, etc.) |
| 80 | + |
| 81 | +recommended values: |
| 82 | +- tweet-like: 140-280 |
| 83 | +- commit message: ~50-72 |
| 84 | +- pr comment: 500-1000 |
| 85 | + |
| 86 | +## output parameters |
| 87 | + |
| 88 | +| parameter | description | |
| 89 | +|-----------|-------------| |
| 90 | +| `explanation` | the generated explanation of the diff. | |
| 91 | + |
| 92 | +## usage examples |
| 93 | + |
| 94 | +### basic usage |
| 95 | + |
| 96 | +```yaml |
| 97 | +- name: Explain Diff |
| 98 | + id: explain |
| 99 | + uses: captradeoff/openai-summarize-diff-action@main |
| 100 | + with: |
| 101 | + diff: ${{ env.DIFF }} |
| 102 | + apikey: ${{ secrets.OPENAI_API_KEY }} |
| 103 | +``` |
| 104 | + |
| 105 | +### custom summary style |
| 106 | + |
| 107 | +```yaml |
| 108 | +- name: Explain Diff |
| 109 | + id: explain |
| 110 | + uses: captradeoff/openai-summarize-diff-action@main |
| 111 | + with: |
| 112 | + diff: ${{ env.DIFF }} |
| 113 | + apikey: ${{ secrets.OPENAI_API_KEY }} |
| 114 | + examplePostSummary: "feat: updated api with improved performance and better error messages" |
| 115 | +``` |
| 116 | + |
| 117 | +### longer output |
| 118 | + |
| 119 | +```yaml |
| 120 | +- name: Explain Diff |
| 121 | + id: explain |
| 122 | + uses: captradeoff/openai-summarize-diff-action@main |
| 123 | + with: |
| 124 | + diff: ${{ env.DIFF }} |
| 125 | + apikey: ${{ secrets.OPENAI_API_KEY }} |
| 126 | + maxTokens: 100 |
| 127 | + maxCharacters: 500 |
| 128 | +``` |
| 129 | + |
| 130 | +## using the output |
| 131 | + |
| 132 | +you can use the `explanation` output in subsequent steps: |
| 133 | + |
| 134 | +```yaml |
| 135 | +- name: Output explanation |
| 136 | + run: echo "${{ steps.explain.outputs.explanation }}" |
| 137 | +``` |
| 138 | + |
| 139 | +or add it as a pr comment: |
| 140 | + |
| 141 | +```yaml |
| 142 | +- name: Post comment |
| 143 | + uses: actions/github-script@v7 |
| 144 | + with: |
| 145 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 146 | + script: | |
| 147 | + github.rest.issues.createComment({ |
| 148 | + issue_number: context.issue.number, |
| 149 | + owner: context.repo.owner, |
| 150 | + repo: context.repo.repo, |
| 151 | + body: `## 🤖 AI Summary of Changes\n\n${{ steps.explain.outputs.explanation }}` |
| 152 | + }); |
| 153 | +``` |
| 154 | + |
| 155 | +## best practices |
| 156 | + |
| 157 | +1. **store api keys securely**: always use github secrets for your openai api key. |
| 158 | +2. **optimize token usage**: use the minimum number of tokens needed to get a good summary to minimize costs. |
| 159 | +3. **provide example summaries**: for more consistent results, provide example summaries that match your desired style. |
| 160 | +4. **filter large diffs**: consider filtering out large auto-generated files from diffs for better results. |
| 161 | +5. **handle error cases**: add error handling in your workflow for cases where the openai api might fail. |
0 commit comments