Skip to content

Refactor (script/github/close-prs.ts): Complex binary expression 319 - #90

Open
slu8 wants to merge 2 commits into
CMU-313:mainfrom
slu8:feature/refactor-close-prs
Open

Refactor (script/github/close-prs.ts): Complex binary expression 319#90
slu8 wants to merge 2 commits into
CMU-313:mainfrom
slu8:feature/refactor-close-prs

Conversation

@slu8

@slu8 slu8 commented Sep 7, 2026

Copy link
Copy Markdown

P1B: Starter Task: Refactoring PR

1. Issue

Link to the associated GitHub issue:

**Full path to the refactored file:

  • /workspaces/opencode/script/github/close-prs.ts
  • /workspaces/opencode/script/github/close-prs-retry-helper.ts **

What do you think this file does?

  • This file acts as clean up helper to determine if certain PRs in the repo should be closed or not
  • For example, if they have less than 2 positive reaction or are too old and untouched, they are automatically closed

What is the scope of your refactoring within that file?
(Name specific functions/blocks/regions touched.)

  • I edited a conditional statement within the async function githubRequest
  • Instead of a long string of conditionals that was hard to read, I have replaced them with clearly named helper functions

Which Qlty‑reported issue did you address?
(Name the rule/metric and include the BEFORE value; e.g., “Cognitive Complexity 18 in render()”.)

  • Complex binary expression
  • 319 if ((response.status === 403 || response.status === 429 || response.status >= 500) && retryMs > 0 && attempt < 10) {
  • High total complexity (count = 51)

2. Refactoring

How did the specific issue you chose impact the codebase’s maintainability?

  • The original conditional was complex because it had multiple conditions combined under one singular if statement
  • This made it difficult to read and quickly determine what the criteria for retrying a GitHub request was

What changes did you make to resolve the issue?

  • In order to improve readability, I created a separate helper function that was clearly named
  • Placing it in a separate file helped to break the logic down and prevent it from clogging the rest of the function

How do your changes improve maintainability? Did you consider alternatives?

  • At first, I tried to keep the helper within the same file, but the "repo is required" error due to the rest of the script's behaviors prevented me from being able to test the conditional independently
  • Therefore, the next best option was to separate it from the main file for easier testing and to avoid changing anything else in the close-prs.ts file

3. Validation

How did you validate that the change is correct?

  • I created a new test file specific to close-prs.ts, and wrote a series of tests based on the outlined criteria for closing a PR
  • I tested for cases in which a PR should be closed, as well as when it should not

Attach a screenshot of the test coverage showing the lines were executed by the tests.
image

Attach a screenshot showing the tests that cover the change passing during CI
Passing New
image

Bun Lint BEFORE:
image

Bun Lint AFTER (no change, except for total file count +2 as expected):
image

Attach a screenshot of qlty smells --no-snippets <full/path/to/file.ts> showing fewer reported issues after the changes.
BEFORE:
image

AFTER:
image

@slu8 slu8 changed the title Feature/refactor close prs Refactor (script/github/close-prs.ts): Complex binary expression 319 Sep 7, 2026
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