-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[invoke] Add tasks to query CODEOWNERS files (#24112)
* [invoke] Add tasks to use CODEOWNERS files * Add unit tests * Apply suggestions from code review Co-authored-by: Nicolas Schweitzer <[email protected]> --------- Co-authored-by: Nicolas Schweitzer <[email protected]>
- Loading branch information
Showing
11 changed files
with
69 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from typing import Any, List | ||
|
||
|
||
def read_owners(owners_file: str) -> Any: | ||
from codeowners import CodeOwners | ||
|
||
with open(owners_file, 'r') as f: | ||
return CodeOwners(f.read()) | ||
|
||
|
||
def search_owners(search: str, owners_file: str) -> List[str]: | ||
parsed_owners = read_owners(owners_file) | ||
# owners.of returns a list in the form: [('TEAM', '@DataDog/agent-build-and-releases')] | ||
return [owner[1] for owner in parsed_owners.of(search)] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from invoke import task | ||
|
||
from tasks.libs.owners.parsing import search_owners | ||
|
||
|
||
@task | ||
def find_jobowners(_, job, owners_file=".gitlab/JOBOWNERS"): | ||
print(", ".join(search_owners(job, owners_file))) | ||
|
||
|
||
@task | ||
def find_codeowners(_, path, owners_file=".github/CODEOWNERS"): | ||
print(", ".join(search_owners(path, owners_file))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import unittest | ||
|
||
from tasks.libs.owners.parsing import search_owners | ||
|
||
|
||
class TestSearchCodeOwners(unittest.TestCase): | ||
CODEOWNERS_FILE = './tasks/unit-tests/testdata/codeowners.txt' | ||
JOBOWNERS_FILE = './tasks/unit-tests/testdata/jobowners.txt' | ||
|
||
def test_search_codeowners(self): | ||
self.assertListEqual(search_owners("no_owners/file", self.CODEOWNERS_FILE), []) | ||
self.assertListEqual(search_owners(".dotfile", self.CODEOWNERS_FILE), ["@DataDog/agent-platform"]) | ||
self.assertListEqual( | ||
search_owners("doc.md", self.CODEOWNERS_FILE), ["@DataDog/agent-platform", "@DataDog/documentation"] | ||
) | ||
self.assertListEqual(search_owners(".gitlab/security.yml", self.CODEOWNERS_FILE), ["@DataDog/agent-security"]) | ||
|
||
def test_search_jobowners(self): | ||
self.assertListEqual(search_owners("default_job", self.JOBOWNERS_FILE), ["@DataDog/agent-ci-experience"]) | ||
self.assertListEqual(search_owners("tests_default", self.JOBOWNERS_FILE), ["@DataDog/multiple"]) | ||
self.assertListEqual(search_owners("tests_ebpf_x64", self.JOBOWNERS_FILE), ["@DataDog/ebpf-platform"]) | ||
self.assertListEqual( | ||
search_owners("security_go_generate_check", self.JOBOWNERS_FILE), ["@DataDog/agent-security"] | ||
) | ||
self.assertListEqual( | ||
search_owners("security_go_generate_checks", self.JOBOWNERS_FILE), ["@DataDog/agent-ci-experience"] | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Extract of the .gitab/JOBOWNERS file, for testing purposes | ||
|
||
* @DataDog/agent-ci-experience | ||
|
||
tests_* @DataDog/multiple | ||
tests_ebpf* @DataDog/ebpf-platform | ||
security_go_generate_check @DataDog/agent-security |