Skip to content

Commit

Permalink
Merge pull request #49 from mansona/add-list-command
Browse files Browse the repository at this point in the history
  • Loading branch information
beaugunderson authored Nov 19, 2024
2 parents 67b7542 + 53c4021 commit fbeca09
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
28 changes: 28 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,34 @@ program
}
});

program
.command('list <path>')
.description('list users/teams that own a specific path')
.option(
'-c, --codeowners-filename <codeowners_filename>',
'specify CODEOWNERS filename',
'CODEOWNERS'
)
.action((checkPath, options) => {
let codeowners;

// instantiate new Codeowners obj
try {
codeowners = new Codeowners(rootPath, options.codeownersFilename);
} catch (e) {
console.error(e.message);
process.exit(1);
}

// call getOwner() on `path`
const owners = codeowners.getOwner(checkPath);

// print owners
for (const currOwner of owners) {
console.log(`${currOwner}`);
}
})

if (!process.argv.slice(2).length) {
program.outputHelp();
}
Expand Down
11 changes: 11 additions & 0 deletions cli.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,15 @@ tests/ @mansona`,
expect(result).to.be.undefined;
});
});

describe('list', () => {
it('shows the codeowner for a file', async () => {
const result = await execa({
cwd: project.baseDir,
})`${cliPath} list index.js`;

expect(result.exitCode).to.equal(0);
expect(result.stdout).to.toMatchInlineSnapshot(`"@beaugunderson"`);
});
});
});

0 comments on commit fbeca09

Please sign in to comment.