Skip to content

Commit

Permalink
Enable pre-commit (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Feb 9, 2024
1 parent 77ea757 commit a53293d
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 5 deletions.
67 changes: 67 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
ci:
# format compatible with commitlint
autoupdate_commit_msg: "chore: pre-commit autoupdate"
autoupdate_schedule: monthly
autofix_commit_msg: |
chore: auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
repos:
- repo: meta
hooks:
- id: check-useless-excludes
- repo: https://github.com/pre-commit/mirrors-prettier
# keep it before yamllint
rev: v4.0.0-alpha.8
hooks:
- id: prettier
always_run: true
additional_dependencies:
- prettier
- prettier-plugin-toml
- prettier-plugin-sort-json
- repo: https://github.com/python-jsonschema/check-jsonschema
rev: 0.28.0
hooks:
- id: check-github-workflows
- repo: https://github.com/pre-commit/pre-commit-hooks.git
rev: v4.5.0
hooks:
- id: end-of-file-fixer
- id: trailing-whitespace
- id: mixed-line-ending
- id: fix-byte-order-marker
- id: check-executables-have-shebangs
- id: check-merge-conflict
- id: debug-statements
language_version: python3
- repo: https://github.com/codespell-project/codespell
rev: v2.2.6
hooks:
- id: codespell
additional_dependencies:
- tomli
- repo: https://github.com/adrienverge/yamllint.git
rev: v1.34.0
hooks:
- id: yamllint
files: \.(yaml|yml)$
types: [file, yaml]
entry: yamllint --strict
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: "v0.2.1"
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
- repo: https://github.com/psf/black
rev: 24.1.1
hooks:
- id: black
language_version: python3
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.8.0
hooks:
- id: mypy
# empty args needed in order to match mypy cli behavior
args: [--strict]
20 changes: 15 additions & 5 deletions codecov-status.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,21 @@

if __name__ == "__main__":

if os.environ.get("GITHUB_REPOSITORY", "") and os.environ.get("GITHUB_REPOSITORY", ""):
if os.environ.get("GITHUB_REPOSITORY", "") and os.environ.get(
"GITHUB_REPOSITORY", ""
):
org, repo = os.environ.get("GITHUB_REPOSITORY", "").split("/")
pr = os.environ.get("GITHUB_REF_NAME", "").split("/")[0]
else:
print("::warning::GITHUB_REPOSITORY and GITHUB_REF_NAME are needed to determine current pull request.")
print(
"::warning::GITHUB_REPOSITORY and GITHUB_REF_NAME are needed to determine current pull request."
)
sys.exit(0)

if not pr.isnumeric():
print("::warning::Codecov.io status check skipped because a pull request was not detected.")
print(
"::warning::Codecov.io status check skipped because a pull request was not detected."
)
sys.exit(0)

url = f"https://api.codecov.io/api/v2/github/{org}/repos/{repo}/pulls/{pr}/"
Expand All @@ -35,6 +41,10 @@
msg = f"{abs(delta_coverage):.2f}% ({base_cov:.2f}% on base -> {head_cov:.2f}% on head).\n"
msg += f"See https://app.codecov.io/gh/{org}/{repo}/pull/{pr} for details."
if delta_coverage < 0:
print(f"::error::Setting coverage check as failed due to coverage going down by {msg}")
print(
f"::error::Setting coverage check as failed due to coverage going down by {msg}"
)
sys.exit(2)
print(f"::notice::Setting coverage check as passed due to coverage going up by {msg}")
print(
f"::notice::Setting coverage check as passed due to coverage going up by {msg}"
)

0 comments on commit a53293d

Please sign in to comment.