-
Notifications
You must be signed in to change notification settings - Fork 52
feat: [CG-10650] codebase.codeowners interface #290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
clee-codegen
merged 19 commits into
develop
from
clee-cg-10650-for-file-in-codebasecodeowners0
Feb 11, 2025
Merged
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
39ef96a
wip: initial implementation of a codeowners interface
clee-codegen d6e2a27
Automated pre-commit update
clee-codegen 7e546c7
add: symbols property to codeowner
clee-codegen 2cf9a36
add: fuller directory API refactor
clee-codegen 1a0925f
Merge remote-tracking branch 'origin/develop' into clee-cg-10650-for-…
clee-codegen 9107c34
fix: move remove to directory specific impl.
clee-codegen 3bf3053
add: unit tests for directory/interface/codeowner
clee-codegen 0ac6601
fix: move cache utils and add unit tests
clee-codegen 1e4ea6a
fix: rename fileinterface to hassymbols and add noapidoc
clee-codegen 6375e19
add: files property test
clee-codegen 28ffbb5
fix: implement uncache system integrated lru_cache
clee-codegen 30f0cce
fix: move py_noapidoc in dec stack
clee-codegen 6e7d197
Automated pre-commit update
clee-codegen fe659e8
fix: use noapidoc instead of py_noapidoc
clee-codegen ceaba3f
Automated pre-commit update
clee-codegen fa302eb
add: docstring codeowner.files
clee-codegen 34756ad
Automated pre-commit update
clee-codegen d55d9e6
add: codeowner.name docstring
clee-codegen 790b457
Merge branch 'develop' into clee-cg-10650-for-file-in-codebasecodeown…
clee-codegen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,97 @@ | ||
import logging | ||
from collections.abc import Iterable, Iterator | ||
from typing import Callable, Generic, Literal | ||
|
||
from codeowners import CodeOwners as CodeOwnersParser | ||
|
||
from codegen.sdk._proxy import proxy_property | ||
from codegen.sdk.core.interfaces.has_symbols import ( | ||
FilesParam, | ||
HasSymbols, | ||
TClass, | ||
TFile, | ||
TFunction, | ||
TGlobalVar, | ||
TImport, | ||
TImportStatement, | ||
TSymbol, | ||
) | ||
from codegen.sdk.core.utils.cache_utils import cached_generator | ||
from codegen.shared.decorators.docs import apidoc, noapidoc | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
@apidoc | ||
class CodeOwner( | ||
HasSymbols[TFile, TSymbol, TImportStatement, TGlobalVar, TClass, TFunction, TImport], | ||
Generic[TFile, TSymbol, TImportStatement, TGlobalVar, TClass, TFunction, TImport], | ||
): | ||
"""CodeOwner is a class that represents a code owner in a codebase. | ||
|
||
It is used to iterate over all files that are owned by a specific owner. | ||
|
||
Attributes: | ||
owner_type: The type of the owner (USERNAME, TEAM, EMAIL). | ||
owner_value: The value of the owner. | ||
files_source: A callable that returns an iterable of all files in the codebase. | ||
""" | ||
|
||
owner_type: Literal["USERNAME", "TEAM", "EMAIL"] | ||
owner_value: str | ||
files_source: Callable[FilesParam, Iterable[TFile]] | ||
|
||
def __init__( | ||
self, | ||
files_source: Callable[FilesParam, Iterable[TFile]], | ||
owner_type: Literal["USERNAME", "TEAM", "EMAIL"], | ||
owner_value: str, | ||
): | ||
self.owner_type = owner_type | ||
self.owner_value = owner_value | ||
self.files_source = files_source | ||
|
||
@classmethod | ||
def from_parser( | ||
cls, | ||
parser: CodeOwnersParser, | ||
file_source: Callable[FilesParam, Iterable[TFile]], | ||
) -> list["CodeOwner"]: | ||
"""Create a list of CodeOwner objects from a CodeOwnersParser. | ||
|
||
Args: | ||
parser (CodeOwnersParser): The CodeOwnersParser to use. | ||
file_source (Callable[FilesParam, Iterable[TFile]]): A callable that returns an iterable of all files in the codebase. | ||
|
||
Returns: | ||
list[CodeOwner]: A list of CodeOwner objects. | ||
""" | ||
codeowners = [] | ||
for _, _, owners, _, _ in parser.paths: | ||
for owner_label, owner_value in owners: | ||
codeowners.append(CodeOwner(file_source, owner_label, owner_value)) | ||
return codeowners | ||
|
||
@cached_generator(maxsize=16) | ||
Check failure on line 75 in src/codegen/sdk/core/codeowner.py
|
||
@noapidoc | ||
def files_generator(self, *args: FilesParam.args, **kwargs: FilesParam.kwargs) -> Iterable[TFile]: | ||
for source_file in self.files_source(*args, **kwargs): | ||
# Filter files by owner value | ||
if self.owner_value in source_file.owners: | ||
yield source_file | ||
|
||
@proxy_property | ||
def files(self, *args: FilesParam.args, **kwargs: FilesParam.kwargs) -> Iterable[TFile]: | ||
"""Recursively iterate over all files in the codebase that are owned by the current code owner.""" | ||
return self.files_generator(*args, **kwargs) | ||
|
||
@property | ||
def name(self) -> str: | ||
"""The name of the code owner.""" | ||
return self.owner_value | ||
|
||
def __iter__(self) -> Iterator[TFile]: | ||
return iter(self.files_generator()) | ||
|
||
def __repr__(self) -> str: | ||
return f"CodeOwner(owner_type={self.owner_type}, owner_value={self.owner_value})" |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.