Skip to content

Commit

Permalink
Merge pull request #551 from gauge-sh/add-username-to-report-upload
Browse files Browse the repository at this point in the history
prompt for username instead of using configreader
  • Loading branch information
caelean authored Jan 16, 2025
2 parents 871a4d4 + 10be3c0 commit 071b992
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
3 changes: 0 additions & 3 deletions python/tach/filesystem/git_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ class GitBranchInfo:
name: str
commit: str
owner: str
user_name: str
email: str


Expand Down Expand Up @@ -127,7 +126,6 @@ def get_current_branch_info(
url = repo.remotes.origin.url
owner_name, repo_name = _get_owner_and_repo_name(url)
config_reader = repo.config_reader()
user_name = str(config_reader.get_value("user", "name", default=""))
email = str(config_reader.get_value("user", "email", default=""))
branch = _get_branch_name(repo)
commit = _get_commit(repo)
Expand All @@ -140,7 +138,6 @@ def get_current_branch_info(
owner=owner_name,
name=branch,
commit=commit,
user_name=user_name,
email=email,
)

Expand Down
15 changes: 12 additions & 3 deletions python/tach/modularity.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ def upload_report_to_gauge(
GAUGE_UPLOAD_URL = f"{GAUGE_API_BASE_URL}/api/client/tach-upload/1.3"


def post_json_to_gauge_api(data: dict[str, Any]) -> dict[str, str]:
def post_json_to_gauge_api(
data: dict[str, Any], user_name: str | None = None
) -> dict[str, str]:
if not GAUGE_API_KEY:
raise TachClosedBetaError(
f"{BCOLORS.WARNING}Modularity is currently in closed beta. Visit {GAUGE_API_BASE_URL}/closed-beta to request access.{BCOLORS.ENDC}"
Expand All @@ -68,6 +70,8 @@ def post_json_to_gauge_api(data: dict[str, Any]) -> dict[str, str]:
"Content-Type": "application/json",
"Authorization": GAUGE_API_KEY,
}
if user_name:
data["user_name"] = user_name
json_data = json.dumps(data)
conn = None
try:
Expand All @@ -79,7 +83,12 @@ def post_json_to_gauge_api(data: dict[str, Any]) -> dict[str, str]:
conn.request("POST", url_parts.path, body=json_data, headers=headers)
response = conn.getresponse()
response_data = response.read().decode("utf-8")
# Check for non-200 status codes
# If key is unbound, prompt user to provide username to bind key
if response.status == 422 and not user_name:
# Prompt user to provide username
conn.close()
user_name = input("Enter your GitHub username: ").strip()
return post_json_to_gauge_api(data, user_name)
if response.status != 200:
raise TachError(
f"API request failed with status {response.status}: {response_data}"
Expand Down Expand Up @@ -299,7 +308,7 @@ def generate_modularity_report(
print(f"{BCOLORS.OKCYAN} > Generating report...{BCOLORS.ENDC}")
branch_info = get_current_branch_info(project_root, allow_dirty=force)
report = Report(
user_name=branch_info.user_name,
user_name="", # only needed for binding a new api key
email=branch_info.email,
owner=branch_info.owner,
repo=branch_info.repo,
Expand Down

0 comments on commit 071b992

Please sign in to comment.