-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* adding a validate command to help validate CODEOWNERS file * fixing vuln in dev dependency
- Loading branch information
1 parent
355446d
commit 46f5cf7
Showing
17 changed files
with
277 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"files" : [ | ||
{ "path": "valid.js" }, | ||
{ "path": "duplicate-rule.js" } | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import path from 'path'; | ||
|
||
import { FixturePaths } from '../types'; | ||
|
||
const paths: FixturePaths = { | ||
files: path.resolve(__dirname, 'files.json'), | ||
codeowners: path.resolve(__dirname, 'owners'), | ||
gitignores: [], | ||
}; | ||
|
||
export const invalidOwnerFixtures: FixturePaths = { | ||
...paths, | ||
codeowners: path.resolve(__dirname, 'owners-invalid-format'), | ||
}; | ||
|
||
export default paths; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
valid.js @some-owner | ||
duplicate-rule.js @some-owner | ||
file-does-not-exist.md @some-owner | ||
duplicate-rule.js @some-owner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
file-exists-duplicate-rule.md @valid-owner not-a-valid-owner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`validate when all owners are valid output the result of all validation checks: stderr 1`] = ` | ||
"Found duplicate rules [ 'duplicate-rule.js @some-owner' ] | ||
Found rules which did not match any files [ 'file-does-not-exist.md @some-owner' ] | ||
" | ||
`; | ||
|
||
exports[`validate when all owners are valid output the result of all validation checks: stdout 1`] = `""`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { v4 as uuidv4 } from 'uuid'; | ||
import fixtures, { invalidOwnerFixtures } from './__fixtures__/validate'; | ||
import { generateProject } from './__fixtures__/project-builder.test.helper'; | ||
|
||
import util from 'util'; | ||
|
||
const exec = util.promisify(require('child_process').exec); | ||
|
||
describe('validate', () => { | ||
describe('when all owners are valid', () => { | ||
const testId = uuidv4(); | ||
|
||
let testDir = 'not set'; | ||
|
||
beforeAll(async () => { | ||
testDir = await generateProject(testId, fixtures); | ||
// tslint:disable-next-line:no-console | ||
console.log(`test scratch dir: ${testDir}`); | ||
}); | ||
|
||
const runCli = async (args: string) => { | ||
return exec(`node ../../../dist/cli.js ${args}`, { cwd: testDir }); | ||
}; | ||
|
||
it('output the result of all validation checks', async () => { | ||
const { stdout, stderr } = await runCli('validate'); | ||
expect(stdout).toMatchSnapshot('stdout'); | ||
expect(stderr).toMatchSnapshot('stderr'); | ||
}); | ||
}); | ||
|
||
|
||
describe('when owners are invalid', () => { | ||
const testId = uuidv4(); | ||
|
||
let testDir = 'not set'; | ||
|
||
beforeAll(async () => { | ||
testDir = await generateProject(testId, invalidOwnerFixtures); | ||
// tslint:disable-next-line:no-console | ||
console.log(`test scratch dir: ${testDir}`); | ||
}); | ||
|
||
const runCli = async (args: string) => { | ||
return exec(`node ../../../dist/cli.js ${args}`, { cwd: testDir }); | ||
}; | ||
|
||
it('should throw on invalid users', async () => { | ||
await expect(() => runCli('validate')).rejects.toThrow(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// import { writeOwnedFile, writeStats } from '../lib/writers'; | ||
import { validate as assertValidRules } from '../lib/ownership'; | ||
import { log } from '../lib/logger'; | ||
|
||
interface ValidateOptions { | ||
codeowners: string; | ||
dir: string; | ||
root: string; | ||
} | ||
|
||
export const validate = async (options: ValidateOptions) => { | ||
const results = await assertValidRules(options); // will throw on errors such as badly formatted rules | ||
|
||
if(results.duplicated.size > 0){ | ||
log.warn('Found duplicate rules', Array.from(results.duplicated.values())); | ||
} | ||
|
||
if(results.unmatched.size > 0){ | ||
log.warn('Found rules which did not match any files', Array.from(results.unmatched.values())); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
export { OwnedFile } from './lib/OwnedFile'; | ||
export { OwnershipEngine } from './lib/OwnershipEngine'; | ||
export { getFileOwnership } from './file'; | ||
export { validate } from './validate'; | ||
export { Matcher, FileOwnershipMatcher } from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.