Skip to content

Commit 050b85d

Browse files
committed
Generate base github action
0 parents  commit 050b85d

File tree

2 files changed

+199
-0
lines changed

2 files changed

+199
-0
lines changed

README.md

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Patched GenerateDocstring Action
2+
3+
This GitHub Action uses [patchwork-cli](https://docs.patched.codes/patchwork/quickstart) to automatically document methods in your code by generating docstrings.
4+
5+
## Features
6+
7+
- Automatically generates docstrings for methods in your code
8+
- Supports various LLM providers (OpenAI, local models, or custom endpoints)
9+
- Creates pull requests with the generated docstrings
10+
- Option to rewrite existing docstrings
11+
- Configurable base path for code scanning
12+
- Customizable branch naming and PR behavior
13+
14+
## Usage
15+
16+
```yaml
17+
name: Generate Docstrings
18+
on:
19+
workflow_dispatch: # Allow manual triggers
20+
21+
jobs:
22+
generate-docstrings:
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v3
26+
- uses: patched-codes/[email protected]
27+
with:
28+
patched_api_key: ${{ secrets.PATCHED_API_KEY }}
29+
base_path: "./src" # Path to start generating docstrings from
30+
```
31+
32+
## Inputs
33+
34+
### Required
35+
36+
One of the following must be provided:
37+
38+
- `patched_api_key`: Patched API key for the LLM ([Get an API key](https://app.patched.codes/))
39+
- `openai_api_key`: OpenAI API key for the LLM ([Get an API key](https://platform.openai.com/account/api-keys))
40+
41+
### Optional
42+
43+
- `base_path`: Base path to start generating docstrings from (default: './')
44+
- `github_token`: GitHub token for creating pull requests (default: [Automatically set by GitHub](https://docs.github.com/en/actions/security-for-github-actions/security-guides/automatic-token-authentication))
45+
- `model`: LLM model to use
46+
- `client_base_url`: Base URL for the LLM API
47+
- `rewrite_existing`: Whether to rewrite existing docstrings
48+
- `branch_prefix`: Prefix for the created branch (default: 'patched-generate-docstring/')
49+
- `disable_branch`: Disable creating new branches
50+
- `disable_pr`: Disable creating pull requests
51+
- `force_pr_creation`: Force push commits to existing PR
52+
- `model_temperature`: Temperature parameter for the LLM
53+
- `model_top_p`: Top-p parameter for the LLM
54+
- `model_max_tokens`: Maximum tokens for the LLM response
55+
56+
## Examples
57+
58+
### Basic Usage
59+
60+
```yaml
61+
- uses: patched-codes/[email protected]
62+
with:
63+
patched_api_key: ${{ secrets.PATCHED_API_KEY }}
64+
base_path: "./src"
65+
```
66+
67+
### Custom Documentation Settings
68+
69+
```yaml
70+
- uses: patched-codes/[email protected]
71+
with:
72+
patched_api_key: ${{ secrets.PATCHED_API_KEY }}
73+
base_path: "./src"
74+
rewrite_existing: true
75+
branch_prefix: "docs/auto-docstrings/"
76+
```
77+
78+
### Using Custom Model
79+
80+
```yaml
81+
- uses: patched-codes/[email protected]
82+
with:
83+
openai_api_key: ${{ secrets.OPENAI_API_KEY }}
84+
base_path: "./src"
85+
model: "gpt-4"
86+
model_temperature: 0.2
87+
model_top_p: 0.95
88+
model_max_tokens: 2000
89+
```
90+
91+
## License
92+
93+
MIT
94+
95+
## Contributing
96+
97+
Contributions are welcome! Please feel free to submit a Pull Request.

action.yml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
name: 'Patched GenerateDocstring'
2+
description: 'Automatically document methods in your code by generating docstrings'
3+
branding:
4+
icon: 'file-text'
5+
color: 'purple'
6+
author: '@patched-codes'
7+
8+
inputs:
9+
github_token:
10+
description: 'GitHub token for creating pull requests'
11+
required: false
12+
default: ${{ github.token }}
13+
openai_api_key:
14+
description: 'OpenAI API key for the LLM'
15+
required: false
16+
base_path:
17+
description: 'Base path to start generating docstrings from'
18+
required: false
19+
default: '.'
20+
model:
21+
description: 'LLM model to use'
22+
required: false
23+
client_base_url:
24+
description: 'Base URL for the LLM API'
25+
required: false
26+
rewrite_existing:
27+
description: 'Whether to rewrite existing docstrings'
28+
required: false
29+
branch_prefix:
30+
description: 'Prefix for the created branch'
31+
required: false
32+
default: 'patched-generate-docstring/'
33+
disable_branch:
34+
description: 'Disable creating new branches'
35+
required: false
36+
disable_pr:
37+
description: 'Disable creating pull requests'
38+
required: false
39+
force_pr_creation:
40+
description: 'Force push commits to existing PR'
41+
required: false
42+
model_temperature:
43+
description: 'Temperature parameter for the LLM'
44+
required: false
45+
model_top_p:
46+
description: 'Top-p parameter for the LLM'
47+
required: false
48+
model_max_tokens:
49+
description: 'Maximum tokens for the LLM response'
50+
required: false
51+
52+
outputs:
53+
pr_url:
54+
description: 'URL of the created pull request'
55+
value: ${{ steps.generate-docstring.outputs.pr_url }}
56+
57+
runs:
58+
using: 'composite'
59+
steps:
60+
- name: Set up Python
61+
uses: actions/setup-python@v4
62+
with:
63+
python-version: '3.x'
64+
65+
- name: Restore pip cache
66+
uses: actions/cache@v3
67+
with:
68+
path: ~/.cache/pip
69+
key: ${{ runner.os }}-pip-patchwork-cli
70+
restore-keys: |
71+
${{ runner.os }}-pip-patchwork-cli
72+
73+
- name: Install dependencies
74+
shell: bash
75+
run: |
76+
python -m pip install --upgrade pip
77+
pip install patchwork-cli
78+
79+
- name: Generate config
80+
shell: bash
81+
run: |
82+
cat > config.yml << EOF
83+
github_api_key: "${{ inputs.github_token }}"
84+
$([ -n "${{ inputs.openai_api_key }}" ] && echo "openai_api_key: \"${{ inputs.openai_api_key }}\"")
85+
$([ -n "${{ inputs.base_path }}" ] && echo "base_path: \"${{ inputs.base_path }}\"")
86+
$([ -n "${{ inputs.model }}" ] && echo "model: \"${{ inputs.model }}\"")
87+
$([ -n "${{ inputs.client_base_url }}" ] && echo "client_base_url: \"${{ inputs.client_base_url }}\"")
88+
$([ -n "${{ inputs.rewrite_existing }}" ] && echo "rewrite_existing: ${{ inputs.rewrite_existing }}")
89+
$([ -n "${{ inputs.branch_prefix }}" ] && echo "branch_prefix: \"${{ inputs.branch_prefix }}\"")
90+
$([ -n "${{ inputs.disable_branch }}" ] && echo "disable_branch: ${{ inputs.disable_branch }}")
91+
$([ -n "${{ inputs.disable_pr }}" ] && echo "disable_pr: ${{ inputs.disable_pr }}")
92+
$([ -n "${{ inputs.force_pr_creation }}" ] && echo "force_pr_creation: ${{ inputs.force_pr_creation }}")
93+
$([ -n "${{ inputs.model_temperature }}" ] && echo "model_temperature: ${{ inputs.model_temperature }}")
94+
$([ -n "${{ inputs.model_top_p }}" ] && echo "model_top_p: ${{ inputs.model_top_p }}")
95+
$([ -n "${{ inputs.model_max_tokens }}" ] && echo "model_max_tokens: ${{ inputs.model_max_tokens }}")
96+
EOF
97+
98+
- name: Run GenerateDocstring
99+
id: generate-docstring
100+
shell: bash
101+
run: |
102+
patchwork GenerateDocstring --config config.yml

0 commit comments

Comments
 (0)