mirror of
https://github.com/grafana/grafana.git
synced 2026-06-12 18:12:00 -04:00
21 lines
793 B
TypeScript
21 lines
793 B
TypeScript
import path from 'path';
|
|
import { OwnershipEngine } from 'github-codeowners/dist/lib/ownership/index.js';
|
|
|
|
const CODEOWNERS_PATH = path.resolve('.github/CODEOWNERS');
|
|
|
|
let engine: { calcFileOwnership(filePath: string): string[] } | null = null;
|
|
|
|
const getEngine = (): { calcFileOwnership(filePath: string): string[] } => {
|
|
engine ??= OwnershipEngine.FromCodeownersFile(CODEOWNERS_PATH);
|
|
return engine;
|
|
};
|
|
|
|
/**
|
|
* Returns the owners for the given file path.
|
|
* Uses the same OwnershipEngine as the CI/CD codeowners tooling.
|
|
* Returns undefined when no rule matches.
|
|
*/
|
|
export const resolveOwner = (relativeFilePath: string): string | undefined => {
|
|
const owners: string[] = getEngine().calcFileOwnership(relativeFilePath);
|
|
return owners.length > 0 ? owners.join(', ') : undefined;
|
|
};
|