mirror of
https://github.com/OMGeeky/gpt-pilot.git
synced 2026-02-23 15:49:50 +01:00
attempt to get email from ~/.gitconfig
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
import os
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@@ -39,9 +41,7 @@ def get_arguments():
|
|||||||
arguments['user_id'] = str(uuid.uuid4())
|
arguments['user_id'] = str(uuid.uuid4())
|
||||||
|
|
||||||
if 'email' not in arguments:
|
if 'email' not in arguments:
|
||||||
# todo change email so its not uuid4 but make sure to fix storing of development steps where
|
arguments['email'] = get_email()
|
||||||
# 1 user can have multiple apps. In that case each app should have its own development steps
|
|
||||||
arguments['email'] = str(uuid.uuid4())
|
|
||||||
|
|
||||||
if 'password' not in arguments:
|
if 'password' not in arguments:
|
||||||
arguments['password'] = 'password'
|
arguments['password'] = 'password'
|
||||||
@@ -54,3 +54,23 @@ def get_arguments():
|
|||||||
print(colored(f'python main.py app_id={arguments["app_id"]}', 'green', attrs=['bold']))
|
print(colored(f'python main.py app_id={arguments["app_id"]}', 'green', attrs=['bold']))
|
||||||
print(colored('--------------------------------------------------------------\n', 'green', attrs=['bold']))
|
print(colored('--------------------------------------------------------------\n', 'green', attrs=['bold']))
|
||||||
return arguments
|
return arguments
|
||||||
|
|
||||||
|
|
||||||
|
def get_email():
|
||||||
|
# Attempt to get email from .gitconfig
|
||||||
|
gitconfig_path = os.path.expanduser('~/.gitconfig')
|
||||||
|
|
||||||
|
if os.path.exists(gitconfig_path):
|
||||||
|
with open(gitconfig_path, 'r') as file:
|
||||||
|
content = file.read()
|
||||||
|
|
||||||
|
# Use regex to search for email address
|
||||||
|
email_match = re.search(r'email\s*=\s*([\w\.-]+@[\w\.-]+)', content)
|
||||||
|
|
||||||
|
if email_match:
|
||||||
|
return email_match.group(1)
|
||||||
|
|
||||||
|
# If not found, return a UUID
|
||||||
|
# todo change email so its not uuid4 but make sure to fix storing of development steps where
|
||||||
|
# 1 user can have multiple apps. In that case each app should have its own development steps
|
||||||
|
return str(uuid.uuid4())
|
||||||
|
|||||||
34
pilot/utils/test_arguments.py
Normal file
34
pilot/utils/test_arguments.py
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import pytest
|
||||||
|
from unittest.mock import patch, mock_open
|
||||||
|
import uuid
|
||||||
|
from .arguments import get_email
|
||||||
|
|
||||||
|
|
||||||
|
def test_email_found_in_gitconfig():
|
||||||
|
mock_file_content = """
|
||||||
|
[user]
|
||||||
|
name = test_user
|
||||||
|
email = test@example.com
|
||||||
|
"""
|
||||||
|
with patch('builtins.open', mock_open(read_data=mock_file_content)):
|
||||||
|
assert get_email() == "test@example.com"
|
||||||
|
|
||||||
|
|
||||||
|
def test_email_not_found_in_gitconfig():
|
||||||
|
mock_file_content = """
|
||||||
|
[user]
|
||||||
|
name = test_user
|
||||||
|
"""
|
||||||
|
mock_uuid = "12345678-1234-5678-1234-567812345678"
|
||||||
|
|
||||||
|
with patch('builtins.open', mock_open(read_data=mock_file_content)):
|
||||||
|
with patch.object(uuid, "uuid4", return_value=mock_uuid):
|
||||||
|
assert get_email() == mock_uuid
|
||||||
|
|
||||||
|
|
||||||
|
def test_gitconfig_not_present():
|
||||||
|
mock_uuid = "12345678-1234-5678-1234-567812345678"
|
||||||
|
|
||||||
|
with patch('os.path.exists', return_value=False):
|
||||||
|
with patch.object(uuid, "uuid4", return_value=mock_uuid):
|
||||||
|
assert get_email() == mock_uuid
|
||||||
Reference in New Issue
Block a user