Skip to content

Conversation

github-actions[bot]
Copy link

Closes #545

Applied changes based on Issue #545.

I’ve refactored src/github/utils.ts to improve readability, modularity, and maintainability while preserving all existing behavior. Key changes:

  • Introduced a BranchType union type to clearly define the allowed branch prefixes rather than returning a plain string.
  • Extracted regexes and literals into module‑level constants (e.g. BRANCH_TYPE_PATTERNS, NON_ALPHANUMERIC_REGEX, TRIM_DASHES_REGEX, MAX_OUTPUT_LENGTH) so patterns are compiled once and meaningfully named.
  • Rewrote getBranchType to use a lookup over BRANCH_TYPE_PATTERNS instead of multiple inline regex tests.
  • Enhanced truncateOutput to accept an optional maxLength parameter (defaulting to MAX_OUTPUT_LENGTH) and switched from substring to slice for consistency.
  • Maintained original JSDoc and functionality, while adopting modern ES features (optional chaining, nullish coalescing, numeric separators).

The patch was applied in place:

*** Before
-export function getBranchType(commitMessage: string): string { ... }
-export function slugify(text: string): string { ... }
-export function truncateOutput(output: string): string { ... }
*** After
+export type BranchType = 'feat' | 'fix' | 'docs' | 'styles' | 'chore';
+
+const MAX_OUTPUT_LENGTH = 60_000;
+const BRANCH_TYPE_PATTERNS: { type: BranchType; pattern: RegExp }[] = [ ... ];
+const NON_ALPHANUMERIC_REGEX = /[^a-z0-9]+/g;
+const TRIM_DASHES_REGEX = /^-+|-+$/g;
+
+export function getBranchType(commitMessage: string): BranchType { ... }
+export function slugify(text: string): string { ... }
+export function truncateOutput(output: string, maxLength = MAX_OUTPUT_LENGTH): string { ... }

【F:src/github/utils.ts†L1-L66】

Please let me know if you’d like any further tweaks!

@YiweiShen YiweiShen merged commit 714b54e into main Jul 26, 2025
3 checks passed
@YiweiShen YiweiShen deleted the codez-chore-545-refactor-github-utils-simplify-helper-functions-3121033457 branch July 26, 2025 02:49
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.

[Done] Refactor src/github/utils.ts

1 participant