Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Eric/use types and logging #61

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
flowstate merged 5 commits into main from eric/use-types-and-logging
Mar 11, 2025
Merged

Eric/use types and logging #61

flowstate merged 5 commits into main from eric/use-types-and-logging
Mar 11, 2025

Conversation

@flowstate
Copy link
Contributor

@flowstate flowstate commented Mar 10, 2025
edited
Loading

  • Fixes the debug logging (don't know the root cause yet, but this solves it)
  • Correctly handles success and failure of create repo SDK call if there isn't an existing repo

We thought we need to add use_types=True, but there are no types for the post method in the SDK.

The actual problem was that the SDK's repos.post method has the following code:

 def post(self, org_slug: str, **kwargs) -> dict:
 params = {}
 if kwargs:
 for key, val in kwargs.items():
 params[key] = val
 if len(params) == 0:
 return {}
 path = "orgs/" + org_slug + "/repos"
 payload = json.dumps(params)
 response = self.api.do_request(path=path, method="POST", payload=payload)
 if response.status_code == 201:
 return response.json()
 error_message = response.json().get("error", {}).get("message", "Unknown error")
 log.error(f"Error creating repository: {response.status_code}, message: {error_message}")
 return {}

So the fix was to check for success by checking if the response had content or not.

I've also wrapped this create call in its own try/except, and if it fails we log it and exit with code 2.

So now if both calls fail there won't be an "unexpected error while running the CLI"

======

Proof that the logging issue is gone:

with debug enabled:

$> socketcli --repo test-large-repo --branch "test-cli-v2-perf" --pr_number 12 --target_path ../test-large-repo --timeout 1200 --enable-debug --exclude-license-details --ignore-commit-files
DEBUG:socketcli:Debug logging enabled
DEBUG:socketcli:loaded socket_config
DEBUG:socketcli:loaded client
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.socket.dev:443
DEBUG:urllib3.connectionpool:https://api.socket.dev:443 "GET /v0/organizations HTTP/11" 200 None
DEBUG:urllib3.connectionpool:Starting new HTTPS connection (1): api.socket.dev:443
DEBUG:urllib3.connectionpool:https://api.socket.dev:443 "GET /v0/orgs/socketdev-demo/settings/security-policy 
...
INFO:socketdev:Total time to create new full scan: 5.81
INFO:socketdev:No head scan found. New scan ID: 089908d7-c2c7-40b3-aa65-791e35942cb5
INFO:socketcli:No issues found

without debug:

$> socketcli --repo test-large-repo --branch "test-cli-v2-perf" --pr_number 12 --target_path ../test-large-repo --timeout 1200 --exclude-license-details --ignore-commit-files 
INFO:socketcli:API Mode
INFO:socketdev:Total time to create new full scan: 17.40
INFO:socketdev:No head scan found. New scan ID: 75f0f2d1-8f45-4d98-b199-5dc9ac11be3f
INFO:socketcli:No issues found

@flowstate flowstate requested a review from a team as a code owner March 10, 2025 23:00
@flowstate flowstate requested review from alxhotel and rchatrath7 and removed request for a team March 10, 2025 23:00
Copy link

github-actions bot commented Mar 10, 2025
edited
Loading

🚀 Preview package published!

Install with:

pip install --index-url https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple socketsecurity==2.0.12.dev615

Docker image: socketdev/cli:pr-61

@flowstate flowstate requested review from dacoburn and removed request for alxhotel and rchatrath7 March 10, 2025 23:06
@flowstate flowstate merged commit f30db3c into main Mar 11, 2025
6 checks passed
@dacoburn dacoburn deleted the eric/use-types-and-logging branch April 3, 2025 20:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@dacoburn dacoburn dacoburn approved these changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /