Skip to content

Conversation

lucia-sb
Copy link
Contributor

@lucia-sb lucia-sb commented Sep 10, 2025

What does this PR do?

Adds a new ddev command ddev ci codeowners to check repository CODEOWNERS for pull requests, commits, or specific files.

Options:

  • --pr <number>: Show codeowners for files changed in a pull request.
  • --sha <commit>: Show codeowners for files changed in a commit.
  • --files <list>: Show codeowners for a comma-separated list of files.
  • --per-file: Output owners per file instead of a combined list.

Motivation

The size quality gates will enforce policies around newly added dependencies. To do this, they must identify which teams introduced those changes in a PR.

Review checklist (to be filled by reviewers)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add the qa/skip-qa label if the PR doesn't need to be tested during QA.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

Copy link

⚠️ Recommendation: Add qa/skip-qa Label

This PR does not modify any files shipped with the agent.

To help streamline the release process, please consider adding the qa/skip-qa label if these changes do not require QA testing.

Copy link

codecov bot commented Sep 10, 2025

Codecov Report

❌ Patch coverage is 80.00000% with 26 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.00%. Comparing base (045fe96) to head (2e89f6d).
⚠️ Report is 12 commits behind head on master.

Additional details and impacted files
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lucia-sb lucia-sb changed the title Lucia sb/ddev codeowners Add ddev ci codeowners command Sep 10, 2025
@lucia-sb lucia-sb marked this pull request as ready for review September 10, 2025 12:47
@lucia-sb lucia-sb requested a review from a team as a code owner September 10, 2025 12:47
Copy link
Member

@NouemanKHAL NouemanKHAL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall, left some suggestions/improvements 💯

Comment on lines +3 to +8
Options:

- `--pr <number>`: Show codeowners for files changed in a pull request.
- `--sha <commit>`: Show codeowners for files changed in a commit.
- `--files <list>`: Show codeowners for a comma-separated list of files.
- `--per-file`: Output owners per file instead of a combined list.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Options:
- `--pr <number>`: Show codeowners for files changed in a pull request.
- `--sha <commit>`: Show codeowners for files changed in a commit.
- `--files <list>`: Show codeowners for a comma-separated list of files.
- `--per-file`: Output owners per file instead of a combined list.
Options:
- `--pr <number>`: Show codeowners for files changed in a pull request.
- `--sha <commit>`: Show codeowners for files changed in a commit.
- `--files <list>`: Show codeowners for a comma-separated list of files.
- `--per-file`: Output owners per file instead of a combined list.

IMO this is maybe too much details for a changelog entry, we can remove this.

@click.option('--files', help='Check the codeowners for the given files separated by commas')
@click.option('--per-file', is_flag=True, help='Output the codeowners for each file')
@click.pass_obj
def codeowners(app: Application, pr: str, sha: str, files: str, per_file: bool):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def codeowners(app: Application, pr: str, sha: str, files: str, per_file: bool):
def codeowners(app: Application, pr: str, commit_sha: str, files: str, per_file: bool):

Comment on lines +17 to +20
codeowners_file = app.repo.path / '.github' / 'CODEOWNERS'
with open(codeowners_file, 'r') as f:
codeowners_content = f.readlines()
codeowners: CodeOwners = CodeOwners("\n".join(codeowners_content))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
codeowners_file = app.repo.path / '.github' / 'CODEOWNERS'
with open(codeowners_file, 'r') as f:
codeowners_content = f.readlines()
codeowners: CodeOwners = CodeOwners("\n".join(codeowners_content))
codeowners_file = app.repo.path / ".github" / "CODEOWNERS"
if not codeowners_file.exists():
raise FileNotFoundError(f"{codeowners_file} does not exist")
codeowners_content = codeowners_file.read_text()
codeowners = CodeOwners(codeowners_content)

suggestion:

  • Check for codeowners file existence and raise an exception if it doesn't exist.
  • Remove unnecessary type hint in the codeowners variable, the CodeOwner type/class is already shown in the value.
  • Using the Path.read_text method opens the file, reads it in text-mode and returns its contents making sure it gets closed, using this method is simpler and removes the need for manually using a context manager with.

Comment on lines +22 to +40
if files:
file_list = files.split(',') if ',' in files else [files]
elif pr:
github = app.github
pr_obj = github.get_pull_request_by_number(pr)
if pr_obj is None:
app.display_error(f'Pull request {pr} not found')
return
file_list = github.get_changed_files_by_pr(pr_obj)
elif sha:
github = app.github
files_by_sha = github.get_changed_files_by_sha(sha)
if files_by_sha is None:
app.display_error(f'Commit {sha} not found')
return
file_list = files_by_sha
else:
app.display_error('No files provided')
return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we have a precedence over these flags, we first check for files then pr then the commit sha etc, is this behavior documented in the command help?
I think we should add a log that shows which flag is being used.

Comment on lines +55 to +58
if owners:
# Collect all owner names for this file in a list
owner_names = [owner_name for _, owner_name in owners]
file_to_owners[file] = sorted(owner_names)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should we do in the case where a file doesn't have an owner? I believe that it could be good to have the option to display all files that have no owner as well in a certain way.

Comment on lines +41 to +46
if per_file:
owners_per_file = map_files_to_teams(file_list, codeowners)
app.display_info(owners_per_file)
else:
owners = get_owners(file_list, codeowners)
app.display_info(sorted(owners))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if per_file:
owners_per_file = map_files_to_teams(file_list, codeowners)
app.display_info(owners_per_file)
else:
owners = get_owners(file_list, codeowners)
app.display_info(sorted(owners))
if per_file:
owners_per_file = get_owners_by_file(file_list, codeowners)
app.display_info(owners_per_file)
else:
owners = get_all_owners(file_list, codeowners)
app.display_info(sorted(owners))

suggestion: in order to stay consistent with the get_owners function name, I think it's better to rename the map_files_to_teams function to follow the same naming, since both functions are doing similar kind of work.


@click.command()
@click.option('--pr', help='Check the codeowners for the given PR')
@click.option('--sha', help='Check the codeowners for the given sha')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
@click.option('--sha', help='Check the codeowners for the given sha')
@click.option('--sha', help='Check the codeowners for the given commit SHA')

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants