-
Notifications
You must be signed in to change notification settings - Fork 2
fix: preserve CODEOWNERS scope and require Node.js 22+ #30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4bfe8cd
test: cover repository-relative CODEOWNERS paths (#17)
its-ho 80b38cc
fix: report output read errors before syncing (#18)
its-ho 4c178f3
fix: preserve CODEOWNERS pattern matching scope (#20)
its-ho fd4ff38
chore: require Node.js 22+ and remove picocolors
its-ho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,5 @@ | ||
| --- | ||
| '@pull-up/cli': patch | ||
| --- | ||
|
|
||
| Preserve CODEOWNERS pattern scope when merging files. Unanchored patterns such as `*.ts` and `docs/` now match at every depth within their source directory, while anchored patterns and root-level rules retain their meaning. |
This file contains hidden or 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,5 @@ | ||
| --- | ||
| '@pull-up/cli': patch | ||
| --- | ||
|
|
||
| Report output read failures with their file path instead of treating unreadable files as missing. Check no longer suggests syncing on read errors, and sync stops before overwriting any outputs. |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,97 @@ | ||
| import { spawnSync } from 'node:child_process'; | ||
| import { mkdir, rm, writeFile } from 'node:fs/promises'; | ||
| import { devNull } from 'node:os'; | ||
| import path from 'node:path'; | ||
|
|
||
| import { Fixture } from '@fixture-kit/core'; | ||
|
|
||
| import { codeownersJob } from './codeowners-job'; | ||
|
|
||
| const sourceDir = 'packages/web'; | ||
| const sourceFiles = [ | ||
| 'index.ts', | ||
| 'index.js', | ||
| 'src/index.ts', | ||
| 'src/nested/index.ts', | ||
| 'lib/src/index.ts', | ||
| 'docs/readme.md', | ||
| 'docs/deep/readme.md', | ||
| 'src/docs/readme.md', | ||
| 'src/docs/deep/readme.md', | ||
| 'file-only/docs', | ||
| ]; | ||
| const outsideFiles = [ | ||
| 'index.ts', | ||
| 'docs/readme.md', | ||
| 'packages/mobile/src/index.ts', | ||
| 'packages/web-other/docs/readme.md', | ||
| ]; | ||
| const allFiles = [...sourceFiles.map((file) => `${sourceDir}/${file}`), ...outsideFiles]; | ||
|
|
||
| function matchedFiles(rootDir: string) { | ||
| const result = spawnSync( | ||
| 'git', | ||
| [ | ||
| '-c', | ||
| `core.excludesFile=${devNull}`, | ||
| '-c', | ||
| 'core.ignoreCase=false', | ||
| 'check-ignore', | ||
| '--no-index', | ||
| '--', | ||
| ...allFiles, | ||
| ], | ||
| { cwd: rootDir, encoding: 'utf8' }, | ||
| ); | ||
| expect(result.error).toBeUndefined(); | ||
| expect([0, 1]).toContain(result.status); | ||
| return result.stdout.trim().split('\n').filter(Boolean).sort(); | ||
| } | ||
|
|
||
| // CODEOWNERS follows gitignore's pattern scoping for these supported patterns. | ||
| // Compare relocation against Git itself rather than a copy of the rewrite logic. | ||
| // Negation, character ranges, and Git's excluded-directory precedence are not tested here. | ||
| describe('CODEOWNERS pattern scope', () => { | ||
| it.each([ | ||
| '*.ts', | ||
| '/*.ts', | ||
| 'docs/', | ||
| '/docs/', | ||
| 'docs', | ||
| 'src/*.ts', | ||
| '/src/*.ts', | ||
| 'src/docs/', | ||
| '**/docs/', | ||
| 'src/**/index.ts', | ||
| '*', | ||
| ])('preserves files matched by %s without escaping the source subtree', async (pattern) => { | ||
| await using fixture = await Fixture.create({}); | ||
| const rootDir = fixture.root; | ||
| const init = spawnSync('git', ['init', '--quiet', '--template='], { cwd: rootDir, encoding: 'utf8' }); | ||
| expect(init.error).toBeUndefined(); | ||
| expect(init.status).toBe(0); | ||
| await Promise.all( | ||
| allFiles.map(async (file) => { | ||
| const filePath = path.join(rootDir, file); | ||
| await mkdir(path.dirname(filePath), { recursive: true }); | ||
| await writeFile(filePath, ''); | ||
| }), | ||
| ); | ||
|
|
||
| const originalIgnore = path.join(rootDir, sourceDir, '.gitignore'); | ||
| await writeFile(originalIgnore, `${pattern}\n`); | ||
| const originalMatches = matchedFiles(rootDir); | ||
| expect(originalMatches.length).toBeGreaterThan(0); | ||
| await rm(originalIgnore); | ||
|
|
||
| const result = await codeownersJob().transform( | ||
| [{ path: `${sourceDir}/CODEOWNERS`, contents: `${pattern} @frontend-team\n` }], | ||
| { rootDir, outputPath: path.join(rootDir, '.github/CODEOWNERS') }, | ||
| ); | ||
| await writeFile(path.join(rootDir, '.gitignore'), `${result.trim().split(' ')[0]}\n`); | ||
| const relocatedMatches = matchedFiles(rootDir); | ||
|
|
||
| expect(relocatedMatches).toEqual(originalMatches); | ||
| expect(relocatedMatches.every((file) => file.startsWith(`${sourceDir}/`))).toBe(true); | ||
| }); | ||
| }); |
This file contains hidden or 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,41 @@ | ||
| import fs from 'node:fs/promises'; | ||
|
|
||
| import { readFileOrNull } from './utils'; | ||
|
|
||
| describe('readFileOrNull', () => { | ||
| const outputPath = '/repository/.github/CODEOWNERS'; | ||
|
|
||
| afterEach(() => { | ||
| vi.restoreAllMocks(); | ||
| }); | ||
|
|
||
| it('returns existing file contents, including an empty file', async () => { | ||
| const readFile = vi.spyOn(fs, 'readFile').mockResolvedValueOnce('contents').mockResolvedValueOnce(''); | ||
|
|
||
| expect(await readFileOrNull(outputPath)).toBe('contents'); | ||
| expect(await readFileOrNull(outputPath)).toBe(''); | ||
| expect(readFile).toHaveBeenCalledWith(outputPath, 'utf-8'); | ||
| }); | ||
|
|
||
| it('returns null for a missing file', async () => { | ||
| vi.spyOn(fs, 'readFile').mockRejectedValue(Object.assign(new Error('No such file'), { code: 'ENOENT' })); | ||
|
|
||
| expect(await readFileOrNull(outputPath)).toBeNull(); | ||
| }); | ||
|
|
||
| it.each(['EISDIR', 'EACCES', 'EIO'])('propagates %s with the output path', async (code) => { | ||
| const error = Object.assign(new Error(`${code}: read failed`), { code, syscall: 'read' }); | ||
| vi.spyOn(fs, 'readFile').mockRejectedValue(error); | ||
|
|
||
| await expect(readFileOrNull(outputPath)).rejects.toMatchObject({ | ||
| cause: error, | ||
| message: expect.stringContaining(outputPath), | ||
| }); | ||
| }); | ||
|
|
||
| it('does not hide unexpected read failures', async () => { | ||
| vi.spyOn(fs, 'readFile').mockRejectedValue(new Error('Unexpected read failure')); | ||
|
|
||
| await expect(readFileOrNull(outputPath)).rejects.toThrow('Unexpected read failure'); | ||
| }); | ||
| }); |
This file contains hidden or 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 hidden or 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 @@ | ||
| import { execFile } from 'node:child_process'; | ||
| import { fileURLToPath } from 'node:url'; | ||
| import { promisify } from 'node:util'; | ||
|
|
||
| export default async function buildCli() { | ||
| await promisify(execFile)('yarn', ['build'], { | ||
| cwd: fileURLToPath(new URL('../', import.meta.url)), | ||
| }); | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.