Skip to content
This repository was archived by the owner on Apr 8, 2026. It is now read-only.

Commit 355446d

Browse files
authored
shuffling deck chairs to allow solution to grow nicely (#30)
1 parent 8631512 commit 355446d

23 files changed

Lines changed: 293 additions & 291 deletions

src/cli.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { who } from './commands/who';
88
import { git } from './commands/git';
99
import { log } from './lib/logger';
1010

11-
import { OUTPUT_FORMAT } from './lib/types';
11+
import { OUTPUT_FORMAT } from './lib/writers/types';
1212

1313
commander.command('audit')
1414
.description('list the owners for all files')

src/commands/audit.ts

Lines changed: 3 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import * as path from 'path';
2-
import { OwnershipEngine } from '../lib/OwnershipEngine';
3-
import { OwnedFile } from '../lib/OwnedFile';
4-
import { OUTPUT_FORMAT } from '../lib/types';
1+
import { OUTPUT_FORMAT, writeOwnedFile, writeStats } from '../lib/writers';
52
import { calcFileStats } from '../lib/stats';
6-
import { writeOwnedFile, writeStats } from '../lib/writers';
7-
import { readDirRecursively } from '../lib/dir';
3+
import { getFileOwnership } from '../lib/ownership';
84

95
interface AuditOptions {
106
codeowners: string;
@@ -16,7 +12,7 @@ interface AuditOptions {
1612
}
1713

1814
export const audit = async (options: AuditOptions) => {
19-
const files = await getFilesWithOwnership(options);
15+
const files = await getFileOwnership(options);
2016

2117
if (options.stats) {
2218
const stats = calcFileStats(files);
@@ -34,23 +30,3 @@ export const audit = async (options: AuditOptions) => {
3430
}
3531
}
3632
};
37-
38-
const getFilesWithOwnership = async (options: AuditOptions): Promise<OwnedFile[]> => {
39-
const engine = OwnershipEngine.FromCodeownersFile(options.codeowners);
40-
41-
let filePaths = await readDirRecursively(options.dir, ['.git']);
42-
43-
if(options.root){ // We need to re-add the root so that later ops can find the file
44-
filePaths = filePaths.map(filePath => path.join(options.root, filePath));
45-
}
46-
47-
filePaths.sort();
48-
49-
const files: OwnedFile[] = [];
50-
51-
for (const filePath of filePaths) {
52-
files.push(await OwnedFile.FromPath(filePath, engine));
53-
}
54-
55-
return files;
56-
};

src/commands/git.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
import { execSync } from 'child_process';
2-
3-
import { OwnedFile } from '../lib/OwnedFile';
4-
import { OwnershipEngine } from '../lib/OwnershipEngine';
5-
import { OUTPUT_FORMAT, Stats } from '../lib/types';
2+
import { OwnedFile, OwnershipEngine } from '../lib/ownership';
3+
import { OUTPUT_FORMAT, writeOwnedFile, writeStats } from '../lib/writers';
64
import { calcFileStats } from '../lib/stats';
7-
import { writeOwnedFile, writeStats } from '../lib/writers';
85

96
interface GitOptions {
107
dir: string;

src/commands/who.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
import { OwnershipEngine } from '../lib/OwnershipEngine';
2-
import { OwnedFile } from '../lib/OwnedFile';
3-
import { OUTPUT_FORMAT } from '../lib/types';
4-
import { writeOwnedFile } from '../lib/writers';
1+
import { OwnershipEngine, OwnedFile } from '../lib/ownership';
2+
import { writeOwnedFile, OUTPUT_FORMAT } from '../lib/writers';
53

64
interface WhoOptions {
75
file: string;

src/lib/dir.test.ts

Lines changed: 0 additions & 196 deletions
This file was deleted.

src/lib/logger/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { log } from './logger';
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ class Logger {
33
// tslint:disable-next-line:no-console
44
console.error(msg, error);
55
}
6+
7+
public warn(msg: string, error?: Error): void {
8+
// tslint:disable-next-line:no-console
9+
console.warn(msg, error);
10+
}
611
}
712

813
export const log = new Logger();

src/lib/ownership/file.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import { OwnedFile } from './lib/OwnedFile';
2+
import { OwnershipEngine } from './lib/OwnershipEngine';
3+
import { readDirRecursively } from './lib/readDirRecursively';
4+
import * as path from 'path';
5+
6+
export const getFileOwnership = async (options: { codeowners: string, dir: string, root?: string }): Promise<OwnedFile[]> => {
7+
const engine = OwnershipEngine.FromCodeownersFile(options.codeowners);
8+
9+
let filePaths = await readDirRecursively(options.dir, ['.git']);
10+
11+
if (options.root) { // We need to re-add the root so that later ops can find the file
12+
filePaths = filePaths.map(filePath => path.join(<string>options.root, filePath));
13+
}
14+
15+
filePaths.sort();
16+
17+
const files: OwnedFile[] = [];
18+
19+
for (const filePath of filePaths) {
20+
files.push(await OwnedFile.FromPath(filePath, engine));
21+
}
22+
23+
return files;
24+
};

src/lib/ownership/index.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export { OwnedFile } from './lib/OwnedFile';
2+
export { OwnershipEngine } from './lib/OwnershipEngine';
3+
export { getFileOwnership } from './file';
4+
export { Matcher, FileOwnershipMatcher } from './types';
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { OwnershipEngine } from './OwnershipEngine';
22
import * as fs from 'fs';
3-
import { log } from './logger';
3+
import { log } from '../../logger';
44

55
export class OwnedFile {
66
// tslint:disable-next-line:variable-name

0 commit comments

Comments
 (0)