Skip to content

Commit

Permalink
Allow the codeowners validation in integrations-core (#17199)
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorentClarret authored Mar 15, 2024
1 parent 047d852 commit 65aa58e
Show file tree
Hide file tree
Showing 6 changed files with 66 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-validations.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ jobs:
if: inputs.ci
run: ddev validate ci

- name: Validate every integration has a defined owner
- name: Validate the CODEOWNERS file
if: inputs.codeowners
run: ddev validate codeowners

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/validate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ jobs:
# Validations
agent-reqs: true
ci: true
codeowners: true
config: true
dashboards: true
dep: true
Expand Down
1 change: 1 addition & 0 deletions datadog_checks_dev/changelog.d/17199.added
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow the codeowners validation in integrations-core
Original file line number Diff line number Diff line change
Expand Up @@ -54,30 +54,34 @@ def create_codeowners_map():
@click.command(
context_settings=CONTEXT_SETTINGS, short_help='Validate `CODEOWNERS` file has an entry for each integration'
)
def codeowners():
@click.pass_context
def codeowners(ctx):
"""Validate that every integration has an entry in the `CODEOWNERS` file."""

has_failed = False
codeowner_map = create_codeowners_map()
codeowners_file = get_codeowners_file()
for integration, codeowner in codeowner_map.items():
if not codeowner:
has_failed = True
message = f"Integration {integration} does not have a valid `CODEOWNERS` entry."
echo_failure(message)
annotate_error(codeowners_file, message)
elif codeowner == "empty":
has_failed = True
message = f"Integration {integration} has a `CODEOWNERS` entry, but the codeowner is empty."
echo_failure(message)
annotate_error(codeowners_file, message)
elif not codeowner.startswith("@") and integration not in IGNORE_TILES:
has_failed = True
message = (
f"Integration {integration} has a `CODEOWNERS` entry, but the codeowner is not a username or team."
)
echo_failure(message)
annotate_error(codeowners_file, message)
is_core_check = ctx.obj['repo_choice'] == 'core'

if not is_core_check: # We do not need this rule in integrations-core
codeowner_map = create_codeowners_map()
codeowners_file = get_codeowners_file()
for integration, codeowner in codeowner_map.items():
if not codeowner:
has_failed = True
message = f"Integration {integration} does not have a valid `CODEOWNERS` entry."
echo_failure(message)
annotate_error(codeowners_file, message)
elif codeowner == "empty":
has_failed = True
message = f"Integration {integration} has a `CODEOWNERS` entry, but the codeowner is empty."
echo_failure(message)
annotate_error(codeowners_file, message)
elif not codeowner.startswith("@") and integration not in IGNORE_TILES:
has_failed = True
message = (
f"Integration {integration} has a `CODEOWNERS` entry, but the codeowner is not a username or team."
)
echo_failure(message)
annotate_error(codeowners_file, message)

if not has_failed:
echo_success("All integrations have valid codeowners.")
Expand Down
11 changes: 11 additions & 0 deletions ddev/tests/cli/validate/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,29 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
import pytest
from datadog_checks.dev.tooling.constants import set_root

from ddev.repo.core import Repository


def _fake_repo(tmp_path_factory, config_file, name):
set_root('') # for dcd compatibility running the tests
repo_path = tmp_path_factory.mktemp(name)
repo = Repository(name, str(repo_path))

config_file.model.repos[name] = str(repo.path)
config_file.model.repo = name
config_file.save()

write_file(
repo.path / '.github',
'CODEOWNERS',
"""
/dummy/ @DataDog/agent-integrations
/dummy2/ @DataDog/agent-integrations
""",
)

write_file(
repo_path / ".ddev",
'config.toml',
Expand Down
27 changes: 27 additions & 0 deletions ddev/tests/cli/validate/test_codeowners.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# (C) Datadog, Inc. 2024-present
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from .conftest import write_file


def test_codeowners_integrations_core(fake_repo, ddev):
result = ddev('validate', 'codeowners')
assert result.exit_code == 0, result.output


def test_codeowners_valid(fake_extras_repo, ddev):
result = ddev('-e', 'validate', 'codeowners')
assert result.exit_code == 0, result.output


def test_codeowners_invalid(fake_extras_repo, ddev):
write_file(
fake_extras_repo.path / '.github',
'CODEOWNERS',
"""
/dummy/ @DataDog/agent-integrations
""",
)
result = ddev('-e', 'validate', 'codeowners')
assert result.exit_code == 1, result.output
assert "Integration dummy2 does not have a valid `CODEOWNERS` entry." in result.output

0 comments on commit 65aa58e

Please sign in to comment.