Skip to content

Commit

Permalink
Add PD migrator lint & test steps to CI (grafana#1053)
Browse files Browse the repository at this point in the history
# What this PR does

- Add PD migrator related hooks to `.pre-commit-config.yaml`
- Add Github Actions step for running PD migrator tests
  • Loading branch information
vstpme authored Dec 30, 2022
1 parent 282e58d commit 1b67a8e
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,17 @@ jobs:
pip install -r requirements.txt
ONCALL_TESTING_RBAC_ENABLED=${{ matrix.rbac_enabled }} pytest -x
unit-test-pd-migrator:
runs-on: ubuntu-latest
container: python:3.9
steps:
- uses: actions/checkout@v2
- name: Unit Test PD Migrator
run: |
cd tools/pagerduty-migrator
pip install -r requirements.txt
pytest -x
docker-build:
runs-on: ubuntu-latest
steps:
Expand Down
13 changes: 13 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,20 @@ repos:
- id: isort
files: ^engine
args: [--settings-file=engine/pyproject.toml, --filter-files]
- id: isort
name: isort - pd-migrator
files: ^tools/pagerduty-migrator
args: [--settings-file=tools/pagerduty-migrator/.isort.cfg, --filter-files]

- repo: https://github.com/psf/black
rev: 22.3.0
hooks:
- id: black
files: ^engine
args: [--config=engine/pyproject.toml]
- id: black
name: black - pd-migrator
files: ^tools/pagerduty-migrator

- repo: https://github.com/pycqa/flake8
rev: 3.9.2
Expand All @@ -21,6 +28,12 @@ repos:
args: [--config=engine/tox.ini]
additional_dependencies:
- flake8-tidy-imports
- id: flake8
name: flake8 - pd-migrator
files: ^tools/pagerduty-migrator
# Make sure config is compatible with black
# https://black.readthedocs.io/en/stable/the_black_code_style/current_style.html#line-length
args: [--max-line-length=88, "--select=C,E,F,W,B,B950", "--extend-ignore=E203,E501"]

- repo: https://github.com/pre-commit/mirrors-eslint
rev: v8.25.0
Expand Down
8 changes: 4 additions & 4 deletions tools/pagerduty-migrator/migrator/report.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ def escalation_policy_report(policies: list[dict]) -> str:
for policy in sorted(
policies, key=lambda p: bool(p["unmatched_users"] or p["flawed_schedules"])
):
result += f"\n" + TAB + format_escalation_policy(policy)
result += "\n" + TAB + format_escalation_policy(policy)

for user in policy["unmatched_users"]:
result += f"\n" + TAB * 2 + format_user(user)
result += "\n" + TAB * 2 + format_user(user)

for schedule in policy["flawed_schedules"]:
result += f"\n" + TAB * 2 + format_schedule(schedule)
result += "\n" + TAB * 2 + format_schedule(schedule)

if (
not policy["unmatched_users"]
Expand All @@ -135,7 +135,7 @@ def integration_report(integrations: list[dict]) -> str:
key=lambda i: bool(i["oncall_type"] and not i["is_escalation_policy_flawed"]),
reverse=True,
):
result += f"\n" + TAB + format_integration(integration)
result += "\n" + TAB + format_integration(integration)
if (
integration["oncall_type"]
and not integration["is_escalation_policy_flawed"]
Expand Down
2 changes: 0 additions & 2 deletions tools/pagerduty-migrator/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
requests==2.27.1
pdpyras==4.5.0
isort==5.10.1
black==22.3.0
pytest==7.1.2
pytest-env==0.6.2

0 comments on commit 1b67a8e

Please sign in to comment.