Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions samcli/lib/telemetry/project_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
"""

from os import getcwd
from os.path import basename
import re
import subprocess
from typing import List, Optional
Expand Down Expand Up @@ -48,7 +47,7 @@ def get_project_name() -> Optional[str]:
-------
str | None
A UUID5 encrypted string of either the name of the project, or the name of the
current directory that the command is running in.
current working directory that the command is running in.
If telemetry is opted out of by the user, returns None
"""
if not bool(GlobalConfig().telemetry_enabled):
Expand All @@ -61,7 +60,7 @@ def get_project_name() -> Optional[str]:
)
project_name = _parse_remote_origin_url(str(runcmd.stdout))[2] # dir is git repo, get project name from URL
except subprocess.CalledProcessError:
project_name = basename(getcwd().replace("\\", "/")) # dir is not a git repo, get directory name
project_name = getcwd().replace("\\", "/") # dir is not a git repo, get directory name

return _encrypt_value(project_name)

Expand Down
20 changes: 10 additions & 10 deletions tests/unit/lib/telemetry/test_project_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,24 +77,24 @@ def test_retrieve_project_name_from_git(self, origin, expected, sp_mock):

@parameterized.expand(
[
("C:/Users/aws/path/to/library/aws-sam-cli", "aws-sam-cli"),
("C:\\Users\\aws\\Windows\\path\\aws-sam-cli", "aws-sam-cli"),
("C:/", ""),
("C:\\", ""),
("E:/path/to/another/dir", "dir"),
("This/one/doesn't/start/with/a/letter", "letter"),
("/banana", "banana"),
("D:/one/more/just/to/be/safe", "safe"),
("C:/Users/aws/path/to/library/aws-sam-cli"),
("C:\\Users\\aws\\Windows\\path\\aws-sam-cli"),
("C:/"),
("C:\\"),
("E:/path/to/another/dir"),
("This/one/doesn't/start/with/a/letter"),
("/banana"),
("D:/one/more/just/to/be/safe"),
]
)
@patch("samcli.lib.telemetry.project_metadata.getcwd")
@patch("samcli.lib.telemetry.project_metadata.subprocess.run")
def test_retrieve_project_name_from_dir(self, cwd, expected, sp_mock, cwd_mock):
def test_retrieve_project_name_from_dir(self, cwd, sp_mock, cwd_mock):
sp_mock.side_effect = CalledProcessError(128, ["git", "config", "--get", "remote.origin.url"])
cwd_mock.return_value = cwd

project_name = get_project_name()
self.assertEqual(project_name, str(uuid5(NAMESPACE_URL, expected)))
self.assertEqual(project_name, str(uuid5(NAMESPACE_URL, cwd.replace("\\", "/"))))

@parameterized.expand(
[
Expand Down