Getting Started with Sourcery for GitHub¶
Installation¶
You can install the Sourcery GitHub app directly using this link:
Install Sourcery for GitHub{ .md-button .md-button--primary }
Sourcery automatically reviews any new PRs made to your repo and will give suggestions on how you can improve your code. Sourcery will only review the changes made in the PR, not your full code base.
To have Sourcery review your whole repository:
- Open up your Sourcery Dashboard
- Select your repo (or add new repos)
- Click the Refactor button
Accept a Suggestion¶
In GitHub you can accept all of Sourcery's suggestions by merging the PR.
To accept or skip individual changes we recommend opening the reviewed files in your IDE and interacting with the changes on a one by one basis.
Add new repos¶
To add Sourcery to new repos:
- Open up your Sourcery Dashboard
- Click the Add Repo button
- Select the repo you want to add
Disable Sourcery on a File or Path¶
We know there might be files or paths you don't want Sourcery to refactor -
especially things like third party libraries. If you want Sourcery to ignore
these you can add a file or a path to the ignore section in the .sourcery.yaml
file in your project directory like this:
ignore:
- data
- .venv
- '*_test.py' # Note that any strings beginning with * must be quoted
Sourcery does by default ignore certain directories, for example venv
and
node_modules
. The full configuration including these defaults is described in
the configuration section of
our docs.
Quality Metrics¶
Sourcery provides quality metrics on every Sourcery PR. Scroll to the bottom of the pull request to see Sourcery's metrics across four different areas:
- Complexity
- Method Length
- Working Memory
- Overall Quality
Sourcery will comment on each pull request scanned with a Quality Report. This details whether the pull request has increased or decreased code quality in the affected files, and gives a breakdown per file. It also shows up to five functions in these files that have a low quality score, and our recommendations for improving them.
FAQ¶
-
How do I know your refactorings won't change my code?
-
We run every potential refactoring we make through multiple validation steps to try to ensure that they will never change what your code is doing. If you ever come across a suggestion that would change the function of your code please let us know and we will make a fix ASAP.
-
Can I configure Sourcery not to make certain refactorings?
-
You can add a Sourcery configuration file to your project to switch off individual refactorings. This is covered in detail in Sourcery Configuration.
-
Why does Sourcery sometimes remove comments?
-
Some refactorings involve removing lines of code or moving them around, and these lines sometimes have comments associated with them. In these cases the refactoring will remove associated comments, but flag this to you so you can check if you want to keep them.
-
What permissions does Sourcery request for GitHub?
-
Sourcery requests read and write access to code, commit statuses, and pull requests. We need these permissions so that we can analyze your code and so that we can create new pull requests with suggested refactorings. We also request read access to issues and metadata.