Skip to content
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

ci: Migrate to ruff #5150

Merged
merged 9 commits into from
Feb 21, 2025
Merged

ci: Migrate to ruff #5150

merged 9 commits into from
Feb 21, 2025

Conversation

khvn26
Copy link
Member

@khvn26 khvn26 commented Feb 20, 2025

Thanks for submitting a PR! Please check the boxes below:

  • I have added information to docs/ if required so people know about the feature!
  • I have filled in the "Changes" section below?
  • I have filled in the "How did you test this code" section below?
  • I have used a Conventional Commit title for this Pull Request

Changes

This PR migrates all of Python linting and formatting, including import sorting, to ruff.
I tried my best to preserve original linting rules and formatting configuration, however, since the latter was inconsistent across black and isort, there's still a hefty load of changes that come along with the migration.

The initial rationale behind this to restore import order linting after we had to turn it off to be able to merge #5119. I have confirmed that ruff does not force incorrect type: ignore comment placement, unlike isort (see PyCQA/isort#2244).

The overall developer experience and performance are resoundingly better that the flake8-black-isort combination we had to support earlier.

Once this is merged, I'll open a follow-up PR adding the formatting changes to .git-blame-ignore-revs.

How did you test this code?

Ran pre-commit and ruff check/ruff format, making sure the outcomes are consistent.

@khvn26 khvn26 requested a review from a team as a code owner February 20, 2025 20:18
@khvn26 khvn26 requested review from matthewelwell and removed request for a team February 20, 2025 20:18
Copy link

vercel bot commented Feb 20, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

3 Skipped Deployments
Name Status Preview Comments Updated (UTC)
docs ⬜️ Ignored (Inspect) Visit Preview Feb 21, 2025 2:43pm
flagsmith-frontend-preview ⬜️ Ignored (Inspect) Visit Preview Feb 21, 2025 2:43pm
flagsmith-frontend-staging ⬜️ Ignored (Inspect) Visit Preview Feb 21, 2025 2:43pm

@github-actions github-actions bot added api Issue related to the REST API ci-cd Build, test and deployment related labels Feb 20, 2025
Copy link
Contributor

github-actions bot commented Feb 20, 2025

Docker builds report

Image Build Status Security report
ghcr.io/flagsmith/flagsmith-e2e:pr-5150 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-api-test:pr-5150 Finished ✅ Skipped
ghcr.io/flagsmith/flagsmith-frontend:pr-5150 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-api:pr-5150 Finished ✅ Results
ghcr.io/flagsmith/flagsmith:pr-5150 Finished ✅ Results
ghcr.io/flagsmith/flagsmith-private-cloud:pr-5150 Finished ✅ Results

@@ -71,14 +70,14 @@
return func(*args, **kwargs) # type: ignore[no-any-return]
except ValueError as e:
return Response(
data={"detail": (f"{error or default_error}" f" Error: {str(e)}")},
data={"detail": (f"{error or default_error} Error: {str(e)}")},

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix AI 3 days ago

To fix the problem, we need to ensure that detailed error messages are not exposed to the end user. Instead, we should log the detailed error message on the server and return a generic error message to the user. This can be achieved by modifying the github_api_call_error_handler decorator to log the exception details and return a generic error message.

  • Modify the github_api_call_error_handler decorator to log the exception details using the logger and return a generic error message to the user.
  • Ensure that the logging captures the necessary details for debugging without exposing them to the user.
Suggested changeset 1
api/integrations/github/views.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api/integrations/github/views.py b/api/integrations/github/views.py
--- a/api/integrations/github/views.py
+++ b/api/integrations/github/views.py
@@ -71,4 +71,5 @@
             except ValueError as e:
+                logger.error(f"{error or default_error} Error: {str(e)}", exc_info=e)
                 return Response(
-                    data={"detail": (f"{error or default_error} Error: {str(e)}")},
+                    data={"detail": default_error},
                     content_type="application/json",
@@ -79,3 +80,3 @@
                 return Response(
-                    data={"detail": (f"{error or default_error} Error: {str(e)}")},
+                    data={"detail": default_error},
                     content_type="application/json",
EOF
@@ -71,4 +71,5 @@
except ValueError as e:
logger.error(f"{error or default_error} Error: {str(e)}", exc_info=e)
return Response(
data={"detail": (f"{error or default_error} Error: {str(e)}")},
data={"detail": default_error},
content_type="application/json",
@@ -79,3 +80,3 @@
return Response(
data={"detail": (f"{error or default_error} Error: {str(e)}")},
data={"detail": default_error},
content_type="application/json",
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
content_type="application/json",
status=status.HTTP_400_BAD_REQUEST,
)
except requests.RequestException as e:
logger.error(f"{error or default_error} Error: {str(e)}", exc_info=e)
return Response(
data={"detail": (f"{error or default_error}" f" Error: {str(e)}")},
data={"detail": (f"{error or default_error} Error: {str(e)}")},

Check warning

Code scanning / CodeQL

Information exposure through an exception Medium

Stack trace information
flows to this location and may be exposed to an external user.

Copilot Autofix AI 3 days ago

To fix the problem, we need to ensure that detailed error messages, including stack traces, are not exposed to external users. Instead, we should log the detailed error message on the server and return a generic error message to the user. This can be achieved by modifying the github_api_call_error_handler decorator to log the exception details and return a generic error message.

  1. Modify the github_api_call_error_handler decorator to log the detailed error message using the logger and return a generic error message to the user.
  2. Ensure that the logging includes the stack trace for debugging purposes.
Suggested changeset 1
api/integrations/github/views.py

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/api/integrations/github/views.py b/api/integrations/github/views.py
--- a/api/integrations/github/views.py
+++ b/api/integrations/github/views.py
@@ -79,3 +79,3 @@
                 return Response(
-                    data={"detail": (f"{error or default_error} Error: {str(e)}")},
+                    data={"detail": (f"{error or default_error} Error occurred while processing your request.")},
                     content_type="application/json",
EOF
@@ -79,3 +79,3 @@
return Response(
data={"detail": (f"{error or default_error} Error: {str(e)}")},
data={"detail": (f"{error or default_error} Error occurred while processing your request.")},
content_type="application/json",
Copilot is powered by AI and may make mistakes. Always verify output.
Positive Feedback
Negative Feedback

Provide additional feedback

Please help us improve GitHub Copilot by sharing more details about this comment.

Please select one or more of the options
Copy link
Contributor

github-actions bot commented Feb 20, 2025

Uffizzi Preview deployment-61166 was deleted.

Copy link

codecov bot commented Feb 20, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.47%. Comparing base (690f87c) to head (7165289).
Report is 5 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #5150   +/-   ##
=======================================
  Coverage   97.46%   97.47%           
=======================================
  Files        1224     1224           
  Lines       42573    42567    -6     
=======================================
- Hits        41495    41491    -4     
+ Misses       1078     1076    -2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@github-actions github-actions bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels Feb 20, 2025
@github-actions github-actions bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels Feb 20, 2025
@github-actions github-actions bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels Feb 21, 2025
@github-actions github-actions bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels Feb 21, 2025
@github-actions github-actions bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels Feb 21, 2025
@github-actions github-actions bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels Feb 21, 2025
@github-actions github-actions bot added ci-cd Build, test and deployment related and removed ci-cd Build, test and deployment related labels Feb 21, 2025
@khvn26 khvn26 merged commit f7487ac into main Feb 21, 2025
37 checks passed
@khvn26 khvn26 deleted the ci/ruff branch February 21, 2025 17:15
khvn26 added a commit that referenced this pull request Feb 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Issue related to the REST API ci-cd Build, test and deployment related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants