Skip to content

Commit

Permalink
Add devtale documentation action (#40)
Browse files Browse the repository at this point in the history
* add action

* update README
  • Loading branch information
betogaona7 authored Aug 22, 2023
1 parent 4aa86dc commit b405d38
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ pip install -r requirements.txt

## Usage

### Terminal

> Note: currently, devtale only supports Python and PHP languages and GPT-4 as LLM.
- Create a `.env` file in the root directory and set your `OPENAI_API_KEY` there.
Expand All @@ -31,6 +33,26 @@ python cli.py -p [path/to/your/code] -o [path/to/docs]

To document an entire repository include the `-r` (recursive) flag. The program returns a JSON file per code file with the documentation data; If you want to also add the documentation inside a copy of code file, then please include the `-f` (fuse) flag.

### Workflow

> Note: You must check the box _"Allow GitHub Actions to create and approve pull requests"_ in your repository's setting -> actions for this to work.
- In the repository setting -> Secrets and Variables -> Actions -> Create `OPENAI_API_KEY` repository secret

- Add the following step in your workflow

```bash
- name: Document
uses: mystral-ai/devtale@v0.1
with:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
path: ${{ github.workspace }}
recursive: true
target_branch: main
```

The `recursive` option allows you to document the entire repository. Alternatively, you can specify a specific path to document a single file or folder and set `recursive` to `false`. The workflow action will automatically create the `devtale/documentation` branch and push a new pull request for your review towards the `target_branch`, including the added documentation.

### Dependency on GPT-4

We found that `GPT-3.5` can't extract code components and generate docstring in a reliable manner, while `GPT-4` can do so. Hence, devtale currently only works with `GPT-4`. Beware that the cost associated to run devtale on a large code repositive may be prohibitive. To reduce this cost, devtale uses `text-davinci-003` for generating top-level file summaries and README files.
60 changes: 60 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: "Document"
description: "Automatically document a repository, folder, or file."

inputs:
openai_api_key:
description: "Your OpenAI API key"
required: true
path:
description: "Path to your repository, folder, or file."
required: true
recursive:
description: "True if you want to document the full repository. Otherwise False"
required: false
default: false
target_branch:
description: "Branch name for the documentation pull request."
required: true

runs:
using: "composite"
steps:
- name: Set up Python
uses: actions/setup-python@v3
with:
python-version: "3.11"

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
shell: bash

- name: Document
run: |
if ${{ inputs.recursive }}; then
echo "Documenting repository"
python ${{ github.action_path }}/cli.py -r -p ${{ inputs.path }} -o ${{ inputs.path }} -f
else
echo "Documenting folder/path"
python ${{ github.action_path }}/cli.py -p ${{ inputs.path }} -o ${{ inputs.path }} -f
fi
env:
OPENAI_API_KEY: ${{ inputs.openai_api_key }}
shell: bash

- name: Clean Documentation Files
run: |
rm -f *.py.json
rm -f *.php.json
shell: bash

- name: Push PR
uses: peter-evans/create-pull-request@v5
with:
commit-message: add docstrings
title: "[devtale] Add documentation"
body: This PR incorporates automatically generated documentation into previously undocumented code files.
branch: devtale/documentation
base: ${{ inputs.target_branch }}
delete-branch: true

0 comments on commit b405d38

Please sign in to comment.