KatInterview

Build a File Owner Aggregator for Code Review Assignment

Trees & GraphsModel answer
MediumModel answerTrees & Graphsgitfile-iocsv

Last updated

Parse Git diffs and a CSV ownership map to identify which contributor owns the most modified files in a branch comparison.

You're building tooling to suggest code reviewers based on file ownership.

Write a Java program that accepts:

  1. A path to a Git repository on disk
  2. Two branch names: a base branch and a comparison branch
  3. A CSV file mapping file paths to their designated owners

Your program must:

  1. Use a Git library (such as JGit) to determine which files differ between the two branches
  2. Load the ownership mapping from the CSV file, which follows this format:
    file_path,owner
    src/payments/ChargeService.java,alice
    src/payments/RefundService.java,bob
    src/common/JsonUtil.java,alice
    
  3. For each modified file that appears in the CSV, record which owner is responsible
  4. Return the owner responsible for the greatest number of changed files

Rules:

  • If a changed file doesn't appear in the CSV, skip it
  • If multiple owners tie for the most files, return any one of them
  • If no changed files have owners, return an empty result

What to consider:

  • Should you compare the branch tips directly, or find their merge base first?
  • How should you handle CSV edge cases (headers, blank lines, paths with commas)?
  • What if a branch name doesn't exist?

Hints

Hint 1

Break the solution into three independent stages: Git diff extraction, CSV parsing into a map, and pure aggregation logic. Each can be unit-tested separately.

Hint 2

A pull request typically shows the three-dot diff (merge base vs target branch), not a two-dot diff (base tip vs target tip). Choose your comparison points accordingly.

Hint 3

Use JGit's diff API to walk tree objects directly—never check out branches to the working directory. For each DiffEntry, extract the path and accumulate ownership counts in a hash map.