raiden00pl commented on PR #16962: URL: https://github.com/apache/nuttx/pull/16962#issuecomment-3244125446
> Is this possible to auto-generate this file contents based on git logs? I mean by hand with some script in nuttx/tools/ for instance that later can be used to update the file? For now it seems to be generated by hand? I played around with vibe-coding for a moment and got this script: ``` import subprocess import argparse from collections import Counter from pathlib import Path def get_files(): """Get list of all tracked files in repo.""" result = subprocess.run( ["git", "ls-files"], stdout=subprocess.PIPE, text=True, check=True ) return result.stdout.strip().split("\n") def get_files_in_directory(directory): """Get list of tracked files inside a given directory.""" result = subprocess.run( ["git", "ls-files", directory], stdout=subprocess.PIPE, text=True, check=True ) return result.stdout.strip().split("\n") def get_author_stats(file_path): """Return a Counter of authors by blamed lines in a file.""" result = subprocess.run( ["git", "blame", "--line-porcelain", file_path], stdout=subprocess.PIPE, text=True, check=True ) authors = [] for line in result.stdout.splitlines(): if line.startswith("author "): author = line[len("author "):].strip() authors.append(author) return Counter(authors) def print_top_authors(file_path, top_n): """Print top N authors for a file with counts and percentages.""" counter = get_author_stats(file_path) if not counter: return total = sum(counter.values()) print(f"{file_path}:") for author, count in counter.most_common(top_n): percent = (count / total) * 100 print(f" {author} - {count} lines ({percent:.1f}%)") def main(): parser = argparse.ArgumentParser( description="Find the author(s) with the most blamed lines per file in a Git repo." ) parser.add_argument( "path", nargs="?", help="Specific file or directory to check (if omitted, checks all repo files)" ) parser.add_argument( "--top", type=int, default=1, help="Show top N authors instead of just the top one (default: 1)" ) args = parser.parse_args() if args.path: p = Path(args.path) if p.is_file(): print_top_authors(str(p), args.top) elif p.is_dir(): files = get_files_in_directory(str(p)) for f in files: print_top_authors(f, args.top) else: print(f"Path not found in repo: {args.path}") else: files = get_files() for f in files: print_top_authors(f, args.top) if __name__ == "__main__": main() ``` It shows the primary contributor of a given file based on `git blame`. Works on the entire repo, on directories within the repo or on single files. You can also specify `--top N` options to see the top N authors. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org