Skip to content

Commit

Permalink
removed username
Browse files Browse the repository at this point in the history
  • Loading branch information
luciferlinx101 committed Jul 3, 2023
1 parent 65f6c89 commit 8ec0ab2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 15 deletions.
9 changes: 4 additions & 5 deletions superagi/helper/tool_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,12 @@ def register_toolkits(session, organisation):
logger.info(f"Toolkits Registered Successfully for Organisation ID : {organisation.id}!")


def extract_repo_name_with_username(repo_link):
def extract_repo_name(repo_link):
# Extract the repository name from the link
# Assuming the GitHub link format: https://github.com/username/repoName
username_repo = repo_link.rsplit('/', 2)[-2:]
user_repo_key = "_".join(username_repo)
repo_name = repo_link.rsplit('/', 1)[-1]

return user_repo_key
return repo_name


def add_tool_to_json(repo_link):
Expand All @@ -263,7 +262,7 @@ def add_tool_to_json(repo_link):
tools_data = json.load(file)

# Extract the repository name from the link
repo_name = extract_repo_name_with_username(repo_link)
repo_name = extract_repo_name(repo_link)

# Add a new key-value pair to the tools object
tools_data['tools'][repo_name] = repo_link
Expand Down
6 changes: 3 additions & 3 deletions tests/unit_tests/helper/test_tool_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from superagi.helper.tool_helper import (
parse_github_url,
load_module_from_file,
extract_repo_name_with_username,
extract_repo_name,
add_tool_to_json, get_readme_content_from_code_link, download_tool
)

Expand Down Expand Up @@ -73,8 +73,8 @@ def test_get_readme_content_from_code_link(mock_requests_get):

def test_extract_repo_name():
repo_link = 'https://github.com/username/repo'
expected_result = 'username_repo'
assert extract_repo_name_with_username(repo_link) == expected_result
expected_result = 'repo'
assert extract_repo_name(repo_link) == expected_result


@patch('requests.get')
Expand Down
10 changes: 3 additions & 7 deletions tests/unit_tests/test_tool_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@
from unittest.mock import Mock, patch, mock_open, MagicMock
from superagi.tool_manager import parse_github_url, download_tool, load_tools_config, download_and_extract_tools


def test_parse_github_url():
url = 'https://github.com/owner/repo'
assert parse_github_url(url) == 'owner/repo/main'


def setup_function():
os.makedirs('target_folder', exist_ok=True)


# Teardown function to remove the directory
def teardown_function():
shutil.rmtree('target_folder')


@patch('requests.get')
@patch('zipfile.ZipFile')
def test_download_tool(mock_zip, mock_get):
Expand All @@ -35,6 +31,7 @@ def test_download_tool(mock_zip, mock_get):
mock_zip.assert_called_once_with('target_folder/tool.zip', 'r')



@patch('json.load')
def test_load_tools_config(mock_json_load):
mock_json_load.return_value = {"tools": {"tool1": "url1", "tool2": "url2"}}
Expand All @@ -43,11 +40,10 @@ def test_load_tools_config(mock_json_load):
assert config == {"tool1": "url1", "tool2": "url2"}


@patch('superagi.tool_manager.load_tools_config')
@patch('superagi.tool_manager.download_tool')
def test_download_and_extract_tools(mock_download_tool, mock_load_tools_config):
@patch('superagi.tool_manager.load_tools_config')
def test_download_and_extract_tools(mock_load_tools_config, mock_download_tool):
mock_load_tools_config.return_value = {"tool1": "url1", "tool2": "url2"}

download_and_extract_tools()

mock_load_tools_config.assert_called_once()
Expand Down
1 change: 1 addition & 0 deletions tools.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"tools": {
"GreetingTool": "https://github.com/luciferlinx101/GreetingTool"
}
}

0 comments on commit 8ec0ab2

Please sign in to comment.