Skip to content

Refactor git status parsing into reusable utilities#189

Closed
bestdan wants to merge 2 commits into
codex-upgrade-upstream-hook-fixesfrom
claude/fix-quality-checks-VKOYK
Closed

Refactor git status parsing into reusable utilities#189
bestdan wants to merge 2 commits into
codex-upgrade-upstream-hook-fixesfrom
claude/fix-quality-checks-VKOYK

Conversation

@bestdan
Copy link
Copy Markdown
Owner

@bestdan bestdan commented Mar 28, 2026

Summary

This PR refactors duplicated git status parsing logic into shared utility functions and improves type safety in git-based checks. The changes eliminate code duplication between the GraphQL and CODEOWNERS checks while making the parsing logic more robust and maintainable.

Key Changes

  • Extract shared git status parsing: Created parseGitStatusEntries() and getNewlyChangedFiles() utility functions used by both dartHookGraphqlCheck and gitCodeownersCheck
  • Add file filtering logic: Introduced isGraphqlOwnedFile() and isCodeownersFile() predicates to filter changed files by type
  • Improve type safety: Replace conditional checks with explicit null guards after ensureCondition() calls, with v8 ignore comments for coverage
  • Simplify error handling: Remove try-catch blocks and complex string parsing in favor of the new utility functions
  • Handle git rename operations: The new parseGitStatusEntries() function properly handles git rename operations (paths with ->) by extracting the destination path
  • Add GraphQL codegen suffix filtering: Import and use COMMON_DART_CODEGEN_SUFFIXES to filter only GraphQL-relevant generated files (.gql.dart and .fakes.dart)
  • Update test expectations: Fix upgrade test to include the new version parameter in upgradeFromGitHub() calls

Implementation Details

  • The parseGitStatusEntries() function parses git porcelain format status output into a Map for easier comparison
  • getNewlyChangedFiles() compares before/after status maps to identify files with changed states
  • Both check commands now use the same parsing logic, reducing maintenance burden and ensuring consistent behavior

https://claude.ai/code/session_01RobTdhpRAXuPkyQ8CknbWd

bestdan added 2 commits March 28, 2026 09:50
…sues

Add explicit null guards after ensureCondition calls (which exit but don't
narrow types) and add undefined checks for regex match destructuring in
both codeowners and graphql check commands. Fix Prettier formatting in 3 files.
Keep TypeScript null-safety fixes and Prettier formatting while
merging upstream changes.
@bestdan bestdan closed this Mar 28, 2026
bestdan added a commit that referenced this pull request Mar 28, 2026
## Summary
- **Fix 6 TypeScript errors** in `codeowners/check.ts` and
`graphql/check.ts`: Add explicit null guards after `ensureCondition()`
calls (which call `process.exit` but don't narrow types), and add
undefined checks for regex match destructuring of `state`/`rawPath`
- **Fix Prettier formatting** in 3 files: line length violations in
`codeowners/check.ts`, `graphql/check.ts`, and `upgrade.test.ts`

## Test plan
- [x] `pnpm typecheck` passes (0 errors)
- [x] `pnpm lint` passes (ESLint + Prettier)
- [x] `pnpm format:check` passes

Supersedes #189 (rebased onto correct base branch).

https://claude.ai/code/session_01RobTdhpRAXuPkyQ8CknbWd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant