Add documentation

This commit is contained in:
Hussam.lawen
2023-10-28 00:45:59 +03:00
parent 9e41f3780c
commit 6f2bbd3baa
4 changed files with 43 additions and 8 deletions

View File

@ -0,0 +1,35 @@
# Generate Custom Labels
The `generte_labels` tool scans the PR code changes, and given a list of labels and their descriptions, it automatically suggests labels that match the PR code changes.
It can be invoked manually by commenting on any PR:
```
/generte_labels
```
For example:
If we wish to add detect changes to SQL queries in a given PR, we can add the following custom label along with its description:
<kbd><img src=./../pics/custom_labels_list.png width="768"></kbd>
When running the `generte_labels` tool on a PR that includes changes in SQL queries, it will automatically suggest the custom label:
<kbd><img src=./../pics/custom_label_published.png width="768"></kbd>
### Configuration options
To enable custom labels, you need to add the following configuration to the [custom_labels file](./../pr_agent/settings/custom_labels.toml):
- Change `enable_custom_labels` to True: This will turn off the default labels and enable the custom labels provided in the custom_labels.toml file.
- Add the custom labels to the custom_labels.toml file. It should be formatted as follows:
```
[custom_labels."Custom Label Name"]
description = "Description of when AI should suggest this label"
```
- You can add modify the list to include all the custom labels you wish to use in your repository.
#### Github Action
To use the `generte_labels` tool with Github Action:
- Add the following file to your repository under `env` section in `.github/workflows/pr_agent.yml`
- Comma separated list of custom labels and their descriptions
- The number of labels and descriptions should be the same and in the same order (empty descriptions are allowed):
```
CUSTOM_LABELS: "label1, label2, ..."
CUSTOM_LABELS_DESCRIPTION: "label1 description, label2 description, ..."
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 253 KiB

BIN
pics/custom_labels_list.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 84 KiB

View File

@ -18,7 +18,7 @@ async def run_action():
OPENAI_ORG = os.environ.get('OPENAI_ORG') or os.environ.get('OPENAI.ORG') OPENAI_ORG = os.environ.get('OPENAI_ORG') or os.environ.get('OPENAI.ORG')
GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN') GITHUB_TOKEN = os.environ.get('GITHUB_TOKEN')
CUSTOM_LABELS = os.environ.get('CUSTOM_LABELS') CUSTOM_LABELS = os.environ.get('CUSTOM_LABELS')
CUSTOM_LABELS_DESCRIPTION = os.environ.get('CUSTOM_LABELS_DESCRIPTION') CUSTOM_LABELS_DESCRIPTIONS = os.environ.get('CUSTOM_LABELS_DESCRIPTIONS')
# CUSTOM_LABELS is a comma separated list of labels (string), convert to list and strip spaces # CUSTOM_LABELS is a comma separated list of labels (string), convert to list and strip spaces
get_settings().set("CONFIG.PUBLISH_OUTPUT_PROGRESS", False) get_settings().set("CONFIG.PUBLISH_OUTPUT_PROGRESS", False)
@ -36,7 +36,7 @@ async def run_action():
if not GITHUB_TOKEN: if not GITHUB_TOKEN:
print("GITHUB_TOKEN not set") print("GITHUB_TOKEN not set")
return return
CUSTOM_LABELS_DICT = handle_custom_labels(CUSTOM_LABELS, CUSTOM_LABELS_DESCRIPTION) CUSTOM_LABELS_DICT = handle_custom_labels(CUSTOM_LABELS, CUSTOM_LABELS_DESCRIPTIONS)
# Set the environment variables in the settings # Set the environment variables in the settings
get_settings().set("OPENAI.KEY", OPENAI_KEY) get_settings().set("OPENAI.KEY", OPENAI_KEY)
@ -93,7 +93,7 @@ async def run_action():
await PRAgent().handle_request(url, body) await PRAgent().handle_request(url, body)
def handle_custom_labels(CUSTOM_LABELS, CUSTOM_LABELS_DESCRIPTION): def handle_custom_labels(CUSTOM_LABELS, CUSTOM_LABELS_DESCRIPTIONS):
if CUSTOM_LABELS: if CUSTOM_LABELS:
CUSTOM_LABELS = [x.strip() for x in CUSTOM_LABELS.split(',')] CUSTOM_LABELS = [x.strip() for x in CUSTOM_LABELS.split(',')]
else: else:
@ -101,21 +101,21 @@ def handle_custom_labels(CUSTOM_LABELS, CUSTOM_LABELS_DESCRIPTION):
CUSTOM_LABELS = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation', CUSTOM_LABELS = ['Bug fix', 'Tests', 'Bug fix with tests', 'Refactoring', 'Enhancement', 'Documentation',
'Other'] 'Other']
print(f"Using default labels: {CUSTOM_LABELS}") print(f"Using default labels: {CUSTOM_LABELS}")
if CUSTOM_LABELS_DESCRIPTION: if CUSTOM_LABELS_DESCRIPTIONS:
CUSTOM_LABELS_DESCRIPTION = [x.strip() for x in CUSTOM_LABELS_DESCRIPTION.split(',')] CUSTOM_LABELS_DESCRIPTIONS = [x.strip() for x in CUSTOM_LABELS_DESCRIPTIONS.split(',')]
else: else:
# Set default labels # Set default labels
CUSTOM_LABELS_DESCRIPTION = ['Fixes a bug in the code', 'Adds or modifies tests', CUSTOM_LABELS_DESCRIPTIONS = ['Fixes a bug in the code', 'Adds or modifies tests',
'Fixes a bug in the code and adds or modifies tests', 'Fixes a bug in the code and adds or modifies tests',
'Refactors the code without changing its functionality', 'Refactors the code without changing its functionality',
'Adds new features or functionality', 'Adds new features or functionality',
'Adds or modifies documentation', 'Adds or modifies documentation',
'Other changes that do not fit in any of the above categories'] 'Other changes that do not fit in any of the above categories']
print(f"Using default labels: {CUSTOM_LABELS_DESCRIPTION}") print(f"Using default labels: {CUSTOM_LABELS_DESCRIPTIONS}")
# create a dictionary of labels and descriptions # create a dictionary of labels and descriptions
CUSTOM_LABELS_DICT = dict() CUSTOM_LABELS_DICT = dict()
for i in range(len(CUSTOM_LABELS)): for i in range(len(CUSTOM_LABELS)):
CUSTOM_LABELS_DICT[CUSTOM_LABELS[i]] = {'description': CUSTOM_LABELS_DESCRIPTION[i]} CUSTOM_LABELS_DICT[CUSTOM_LABELS[i]] = {'description': CUSTOM_LABELS_DESCRIPTIONS[i]}
return CUSTOM_LABELS_DICT return CUSTOM_LABELS_DICT