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

Introduce pre-commit hooks and GitHub Actions #1316

Merged
merged 5 commits into from
Nov 8, 2024

Conversation

yu-iskw
Copy link
Contributor

@yu-iskw yu-iskw commented Oct 30, 2024

Motivation

pre-commit is very useful to apply static code analyzers including linters to code using git hooks. This pull request aims to implement basic pre-commit hooks to keep the code quality pr-agent great.

Signed-off-by: Yu Ishikawa <[email protected]>
Signed-off-by: Yu Ishikawa <[email protected]>
Signed-off-by: Yu Ishikawa <[email protected]>
Comment on lines +1 to +15
name: pre-commit

on:
pull_request:
push:
branches: [main]

jobs:
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v5
# SEE https://github.com/pre-commit/action
- uses: pre-commit/[email protected]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This GitHub Action comes from https://github.com/pre-commit/action .

Comment on lines +7 to +15
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v5.0.0
hooks:
- id: check-added-large-files
- id: check-toml
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can go with basic pre-commit hooks to format code. Then, we can take other hooks if ok.

Comment on lines +20 to +24
- repo: https://github.com/pycqa/isort
# rev must match what's in dev-requirements.txt
rev: 5.13.2
hooks:
- id: isort
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@yu-iskw yu-iskw marked this pull request as ready for review October 30, 2024 01:11
@mrT23
Copy link
Collaborator

mrT23 commented Oct 31, 2024

@yu-iskw thanks for the PR.

I was starting an answer describing how much I hate linters (especially auto line breaks, which usually make the code unreadable), but when reviewing the results, I actually kind of like them. It mainly orders things in alphabetical order, which is good, and makes the spacing more consistent.

How will this hook work in practice ? what happens when I open a PR that is not complaint with its rules?

@yu-iskw
Copy link
Contributor Author

yu-iskw commented Nov 1, 2024

@mrT23

How will this hook work in practice ? what happens when I open a PR that is not complaint with its rules?

The hooks enabled in the pull request automatically formats code. As long as pre-commit is installed locally, pre-commit hooks are automatically triggered when committing and pushing commits.

Apart from formating code, some pre-commit hooks like bandit and semgrep helps us to automatically find vulnerabilities and security issues to some degree. That would be useful to keep our code secure.

@mrT23
Copy link
Collaborator

mrT23 commented Nov 8, 2024

/improve

Copy link
Contributor

qodo-merge-pro bot commented Nov 8, 2024

PR Code Suggestions ✨

CategorySuggestion                                                                                                                                    Score
General
Improve exception handling by specifying the expected exception type

Replace the bare 'except' clause with a specific exception type to catch only the
relevant exceptions and avoid masking other potential errors.

pr_agent/tools/pr_similar_issue.py [113-116]

 try:
     import lancedb  # import lancedb only if needed
-except:
+except ImportError:
     raise Exception("Please install lancedb to use lancedb as vectordb")
  • Apply this suggestion
Suggestion importance[1-10]: 6

Why: Specifying ImportError instead of using a bare except clause improves error handling and code clarity, making it easier to debug and maintain the code.

6
Simplify and clarify the sentence structure to improve readability

Consider rephrasing the sentence to improve clarity and conciseness. The current
wording is somewhat redundant and could be simplified.

docs/docs/tools/improve.md [219]

-+Another option to give additional guidance to the AI model is by creating a dedicated [**wiki page**](https://github.com/Codium-ai/pr-agent/wiki) called `best_practices.md`.
++To provide additional guidance to the AI model, create a dedicated [**wiki page**](https://github.com/Codium-ai/pr-agent/wiki) called `best_practices.md`.
  • Apply this suggestion
Suggestion importance[1-10]: 5

Why: The suggestion improves clarity and conciseness by simplifying the sentence structure. While the change is minor, it enhances readability, which is important for documentation.

5
Correct grammatical structure to improve readability and clarity

The added line contains a grammatical error. The phrase "are quite useful, and
should be considered for enabling" is awkward and can be improved for clarity.

docs/docs/tools/review.md [184]

-+    Some of the features that are disabled by default are quite useful, and should be considered for enabling. For example:
++    Some features that are disabled by default are quite useful and should be considered for enabling. For example:
  • Apply this suggestion
Suggestion importance[1-10]: 4

Why: The suggestion corrects a minor grammatical issue and slightly improves the sentence structure. While the change is small, it enhances the overall readability of the documentation.

4
Use specific imports instead of importing multiple items on a single line

Consider using a more specific import for FilePatchInfo instead of importing it from
pr_agent.algo.types. This can improve code readability and make dependencies
clearer.

pr_agent/algo/pr_processing.py [9]

-from pr_agent.algo.types import EDIT_TYPE, FilePatchInfo
+from pr_agent.algo.types import EDIT_TYPE
+from pr_agent.algo.types import FilePatchInfo
  • Apply this suggestion
Suggestion importance[1-10]: 3

Why: The suggestion improves code readability slightly by separating imports, but it doesn't significantly impact functionality or maintainability.

3
Group related imports together and separate them with blank lines for better organization

Consider grouping related imports together and separating them with a blank line.
This can improve code organization and readability.

pr_agent/tools/pr_code_suggestions.py [1-10]

+import asyncio
+import copy
+import difflib
+import re
+import textwrap
+import traceback
+from functools import partial
+from typing import Dict, List
 
+from jinja2 import Environment, StrictUndefined
  • Apply this suggestion
Suggestion importance[1-10]: 2

Why: The suggestion aims to improve code organization, but the existing code already follows a logical import structure. The impact is minimal.

2
Possible issue
Ensure consistent import of required libraries regardless of the chosen vectordb

Move the import statement for 'pandas' outside of the try-except block to ensure
it's always imported when needed, not just when the 'pinecone' vectordb is used.

pr_agent/tools/pr_similar_issue.py [35-41]

+import pandas as pd
+
 if get_settings().pr_similar_issue.vectordb == "pinecone":
     try:
-        import pandas as pd
         import pinecone
         from pinecone_datasets import Dataset, DatasetMetadata
     except:
         raise Exception("Please install 'pinecone' and 'pinecone_datasets' to use pinecone as vectordb")
  • Apply this suggestion
Suggestion importance[1-10]: 5

Why: Moving the pandas import outside the conditional block improves code organization and ensures it's available when needed, but it's a minor change that doesn't significantly impact functionality.

5
  • Author self-review: I have reviewed the PR code suggestions, and addressed the relevant ones.

@mrT23 mrT23 merged commit dfb3d80 into Codium-ai:main Nov 8, 2024
2 of 3 checks passed
@yu-iskw
Copy link
Contributor Author

yu-iskw commented Nov 8, 2024

@mrT23 Thank you for merging!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants