Skip to content

Commit

Permalink
Refactor APIClient to include repo details in file generation request
Browse files Browse the repository at this point in the history
  • Loading branch information
sumansaurabh committed Aug 24, 2024
1 parent 7150f08 commit 551fdd5
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 25 deletions.
40 changes: 20 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
# Penify-Hook
# Penify-cli

Penify-Hook is a Git post-commit hook that automatically generates docstrings for modified functions and classes in your codebase. It integrates with a remote API to analyze the changes and generate documentation, helping developers maintain high-quality, consistent documentation across their projects.
Penify-cli is a Git post-commit hook that automatically generates docstrings for modified functions and classes in your codebase. It integrates with a remote API to analyze the changes and generate documentation, helping developers maintain high-quality, consistent documentation across their projects.

## 1. Installing Penify-Hook
## 1. Installing Penify-cli

To install the `penify-hook` package, follow these steps:
To install the `penify-cli` package, follow these steps:

1. **Install the Penify-Hook Package:**
1. **Install the Penify-cli Package:**

First, make sure to install the `penify-hook` package via pip (replace `penify-hook` with the correct package name):
First, make sure to install the `penify-cli` package via pip (replace `penify-cli` with the correct package name):

```bash
pip install penify-hook
pip install penify-cli
```

## 2. Adding Environment Variable PENIFY_API_TOKEN

To use Penify-Hook, you need an API token. This token can be obtained from the Penify dashboard.
To use Penify-cli, you need an API token. This token can be obtained from the Penify dashboard.

1. **Obtain Your API Token:**

Expand All @@ -34,29 +34,29 @@ To use Penify-Hook, you need an API token. This token can be obtained from the P

## 3. Help

To see the help options for Penify-Hook, you can use the following command:
To see the help options for Penify-cli, you can use the following command:

```bash
penify-hook --help
penify-cli --help
```

This will display all available commands and options for using Penify-Hook.
This will display all available commands and options for using Penify-cli.

## 4. Usage

### 4.1 Using Simple Command (in a GIT enabled Repo)

You can use Penify-Hook to track Git changes and generate documentation for only the modified lines:
You can use Penify-cli to track Git changes and generate documentation for only the modified lines:

```bash
penify-hook -gf <GIT_FOLDER_PATH>
penify-cli -gf <GIT_FOLDER_PATH>
```

This command will analyze the specified file, generate docstrings for the modified functions and classes, and update the files. If nothing is provided, it will take the default directory.

### 4.2 Git Hook

Penify-Hook can be configured as a Git post-commit hook. Once set up, it will automatically generate documentation for any modifications made in your repository after each commit.
Penify-cli can be configured as a Git post-commit hook. Once set up, it will automatically generate documentation for any modifications made in your repository after each commit.

#### **Configuring the Post-Commit Hook:**

Expand All @@ -65,7 +65,7 @@ Penify-Hook can be configured as a Git post-commit hook. Once set up, it will au
Navigate to the root directory of your Git repository and run:

```bash
penify-hook --install -gf <GIT_FOLDER_PATH>
penify-cli --install -gf <GIT_FOLDER_PATH>
```

Replace `<GIT_FOLDER_PATH>` with the path to the folder containing your Git repository. This command will install the post-commit hook.
Expand All @@ -80,22 +80,22 @@ Penify-Hook can be configured as a Git post-commit hook. Once set up, it will au
git commit -m "Updated some functions"
```

After this commit, Penify-Hook will run, analyze the modified files, generate the necessary docstrings, and update the files automatically.
After this commit, Penify-cli will run, analyze the modified files, generate the necessary docstrings, and update the files automatically.

4. **Uninstalling the Post-Commit Hook:**

To remove the post-commit hook, use:

```bash
penify-hook --uninstall -f <GIT_FOLDER_PATH>
penify-cli --uninstall -f <GIT_FOLDER_PATH>
```

### 4.3 Generating Documentation for a Full Repository

Penify-Hook can generate documentation for all files in a repository, regardless of whether Git is installed or not:
Penify-cli can generate documentation for all files in a repository, regardless of whether Git is installed or not:

```bash
penify-hook -cf <COMPLETE_FOLDER_PATH>
penify-cli -cf <COMPLETE_FOLDER_PATH>
```

This command will scan the specified folder and generate docstrings for all files within it.
Expand All @@ -105,7 +105,7 @@ This command will scan the specified folder and generate docstrings for all file
If you want to generate docstrings for a specific file, you can use:

```bash
penify-hook -l <FILE_PATH>
penify-cli -l <FILE_PATH>
```

This will analyze the file, generate the required docstrings for all functions and classes, and update the file.
2 changes: 2 additions & 0 deletions penify_hook/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def send_file_for_docstring_generation(self, file_name, content, line_numbers, r
if repo_details:
payload['git_repo'] = repo_details

print(repo_details)

url = self.api_url+"/v1/file/generate/diff/doc"
response = requests.post(url, json=payload,headers={"api-key": f"{self.AUTH_TOKEN}"}, timeout=60*10)
if response.status_code == 200:
Expand Down
4 changes: 2 additions & 2 deletions penify_hook/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

HOOK_FILENAME = "post-commit"
HOOK_TEMPLATE = """#!/bin/sh
# This is a post-commit hook generated by penify-hook.
# This is a post-commit hook generated by penify-cli.
penify-hook -t {token} -f {folder_path}
penify-cli -t {token} -f {folder_path}
"""

def install_hook(repo_path, token, folder_path):
Expand Down
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from setuptools import setup, find_packages

setup(
name="penify-hook",
name="penify-cli",
version="0.1.0",
packages=find_packages(),
install_requires=[
Expand All @@ -11,15 +11,15 @@
],
entry_points={
"console_scripts": [
"penify-hook=penify_hook.main:main",
"penify-cli=penify_hook.main:main",
],
},
author="Suman Saurabh",
author_email="[email protected]",
description="A post-commit hook that sends modified files and their contents to an API.",
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
url="https://github.com/SingularityX-ai/penify-hook",
url="https://github.com/SingularityX-ai/penify-cli",
classifiers=[
"Programming Language :: Python :: 3",
"License :: OSI Approved :: MIT License",
Expand Down

0 comments on commit 551fdd5

Please sign in to comment.