Skip to content

Refactor (packages/opencode/src/util/repository.ts:139): Function with many returns (count = 8): parseRepositoryReference - #176

Open
Wl1u4 wants to merge 7 commits into
CMU-313:mainfrom
Wl1u4:fix-repository-many-returns
Open

Refactor (packages/opencode/src/util/repository.ts:139): Function with many returns (count = 8): parseRepositoryReference#176
Wl1u4 wants to merge 7 commits into
CMU-313:mainfrom
Wl1u4:fix-repository-many-returns

Conversation

@Wl1u4

@Wl1u4 Wl1u4 commented Sep 8, 2026

Copy link
Copy Markdown

Closes #171

Closes #

Type of change

  • Bug fix
  • New feature
  • [ Check] Refactor / code improvement
  • Documentation

What does this PR do?

Fixes #171. Qlty flagged parseRepositoryReference in packages/opencode/src/util/repository.ts for having too many return statements (8). The func try several parsing strats in a row: GitHub shorthand like "owner/repo", "github:owner/repo" prefix, SCP-style git URLs, direct host/path, and full URLs. returning as soon as one matches.

I pulled each strategy out into its own small func (matchGithubPrefixed, matchScpStyle, matchDirectHostPath, matchGithubShorthand, matchUrl), put them in an array, and looped through them, returning the first non null result. This keeps exact same order and fallback behavior as before, but main func now only has 2 return statements instead of 8, and each strategy is easier to read/test on its own.

If you paste a large clearly AI generated description here your PR may be IGNORED or CLOSED!

How did you verify your code works?

Ran qlty smells before and after. the "many returns" warning is gone and no new smells were introduced.

Ran existing test suite (test/util/repository.test.ts) all 6 tests still pass with no changes needed.

Also ran the full test suite (bun test --coverage) to make sure nothing else broke: 3254 pass, 4 fail (those 4 failures are pre exisitng ones and unrelated to this file).

Checked coverage on the changed file specifically

and confirmed the few uncovered lines

Also ran bun run typecheck with no errors.

Screenshot 2026-09-07 at 9 29 06 PM Screenshot 2026-09-07 at 9 29 36 PM Screenshot 2026-09-07 at 10 24 10 PM Screenshot 2026-09-07 at 10 22 41 PM Screenshot 2026-09-07 at 10 21 40 PM Screenshot 2026-09-07 at 10 23 45 PM

Checklist

  • [ Check] I have tested my changes locally
  • [Check ] I have not included unrelated changes in this PR

If you do not follow this template your PR will be automatically rejected.

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.

P1B: Refactor (packages/opencode/src/util/repository.ts:139): Function with many returns (count = 8): parseRepositoryReference

1 participant