Keep low-quality changes out of your codebase by using Code Quality thresholds to block pull requests that don't meet your standards.
You can block pull requests that don't meet your code quality standards by adding Code Quality thresholds to a ruleset. If a pull request doesn't meet a threshold, it can't be merged.
You can set thresholds for:
You can enforce these thresholds at the repository level, or at the organization level to apply the same standard across many repositories at once. Choose the organization level when you want a consistent quality bar across teams, and the repository level when a single project needs its own standard. Code Quality AI findings cannot be set as a threshold.
Note
The threshold will have an impact only if the repository has code in one or more of the supported languages, see Enabling GitHub Code Quality.
Before you add or update a ruleset to include a threshold for Code Quality, confirm that the Code Quality workflow is running and reporting results back to pull requests. Otherwise, the ruleset could block the merging of all pull requests.
For more information, see CodeQL-powered analysis for Code Quality.
The following steps create or update a ruleset at the repository level. To enforce the same threshold across multiple repositories at once, create an organization ruleset with the same Require code quality results rule instead. See Creating rulesets for repositories in your organization.
If you selected "Evaluate", review the ruleset insights to see which pull requests would have been blocked. When the results match the quality bar you want, change the enforcement status to "Active."
You can also block pull requests that fall below a code coverage threshold. This uses a separate Restrict code coverage rule, not the Require code quality results rule used above, and your repository must upload code coverage data first. For the full procedure, see Setting code coverage thresholds for pull requests.