Skip to content

Commit 65aa58e

Browse files
Allow the codeowners validation in integrations-core (#17199)
1 parent 047d852 commit 65aa58e

File tree

6 files changed

+66
-22
lines changed

6 files changed

+66
-22
lines changed

.github/workflows/run-validations.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ jobs:
151151
if: inputs.ci
152152
run: ddev validate ci
153153

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

.github/workflows/validate.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ jobs:
1919
# Validations
2020
agent-reqs: true
2121
ci: true
22+
codeowners: true
2223
config: true
2324
dashboards: true
2425
dep: true
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Allow the codeowners validation in integrations-core

datadog_checks_dev/datadog_checks/dev/tooling/commands/validate/codeowners.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,34 @@ def create_codeowners_map():
5454
@click.command(
5555
context_settings=CONTEXT_SETTINGS, short_help='Validate `CODEOWNERS` file has an entry for each integration'
5656
)
57-
def codeowners():
57+
@click.pass_context
58+
def codeowners(ctx):
5859
"""Validate that every integration has an entry in the `CODEOWNERS` file."""
5960

6061
has_failed = False
61-
codeowner_map = create_codeowners_map()
62-
codeowners_file = get_codeowners_file()
63-
for integration, codeowner in codeowner_map.items():
64-
if not codeowner:
65-
has_failed = True
66-
message = f"Integration {integration} does not have a valid `CODEOWNERS` entry."
67-
echo_failure(message)
68-
annotate_error(codeowners_file, message)
69-
elif codeowner == "empty":
70-
has_failed = True
71-
message = f"Integration {integration} has a `CODEOWNERS` entry, but the codeowner is empty."
72-
echo_failure(message)
73-
annotate_error(codeowners_file, message)
74-
elif not codeowner.startswith("@") and integration not in IGNORE_TILES:
75-
has_failed = True
76-
message = (
77-
f"Integration {integration} has a `CODEOWNERS` entry, but the codeowner is not a username or team."
78-
)
79-
echo_failure(message)
80-
annotate_error(codeowners_file, message)
62+
is_core_check = ctx.obj['repo_choice'] == 'core'
63+
64+
if not is_core_check: # We do not need this rule in integrations-core
65+
codeowner_map = create_codeowners_map()
66+
codeowners_file = get_codeowners_file()
67+
for integration, codeowner in codeowner_map.items():
68+
if not codeowner:
69+
has_failed = True
70+
message = f"Integration {integration} does not have a valid `CODEOWNERS` entry."
71+
echo_failure(message)
72+
annotate_error(codeowners_file, message)
73+
elif codeowner == "empty":
74+
has_failed = True
75+
message = f"Integration {integration} has a `CODEOWNERS` entry, but the codeowner is empty."
76+
echo_failure(message)
77+
annotate_error(codeowners_file, message)
78+
elif not codeowner.startswith("@") and integration not in IGNORE_TILES:
79+
has_failed = True
80+
message = (
81+
f"Integration {integration} has a `CODEOWNERS` entry, but the codeowner is not a username or team."
82+
)
83+
echo_failure(message)
84+
annotate_error(codeowners_file, message)
8185

8286
if not has_failed:
8387
echo_success("All integrations have valid codeowners.")

ddev/tests/cli/validate/conftest.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,29 @@
22
# All rights reserved
33
# Licensed under a 3-clause BSD style license (see LICENSE)
44
import pytest
5+
from datadog_checks.dev.tooling.constants import set_root
56

67
from ddev.repo.core import Repository
78

89

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

1315
config_file.model.repos[name] = str(repo.path)
1416
config_file.model.repo = name
1517
config_file.save()
1618

19+
write_file(
20+
repo.path / '.github',
21+
'CODEOWNERS',
22+
"""
23+
/dummy/ @DataDog/agent-integrations
24+
/dummy2/ @DataDog/agent-integrations
25+
""",
26+
)
27+
1728
write_file(
1829
repo_path / ".ddev",
1930
'config.toml',
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# (C) Datadog, Inc. 2024-present
2+
# All rights reserved
3+
# Licensed under a 3-clause BSD style license (see LICENSE)
4+
from .conftest import write_file
5+
6+
7+
def test_codeowners_integrations_core(fake_repo, ddev):
8+
result = ddev('validate', 'codeowners')
9+
assert result.exit_code == 0, result.output
10+
11+
12+
def test_codeowners_valid(fake_extras_repo, ddev):
13+
result = ddev('-e', 'validate', 'codeowners')
14+
assert result.exit_code == 0, result.output
15+
16+
17+
def test_codeowners_invalid(fake_extras_repo, ddev):
18+
write_file(
19+
fake_extras_repo.path / '.github',
20+
'CODEOWNERS',
21+
"""
22+
/dummy/ @DataDog/agent-integrations
23+
""",
24+
)
25+
result = ddev('-e', 'validate', 'codeowners')
26+
assert result.exit_code == 1, result.output
27+
assert "Integration dummy2 does not have a valid `CODEOWNERS` entry." in result.output

0 commit comments

Comments
 (0)