refactor: extract duplicated status/report logic into shared utilities - #5
Open
devin-ai-integration[bot] wants to merge 1 commit into
Open
devin-ai-integration[bot] wants to merge 1 commit into
devin-ai-integration[bot] wants to merge 1 commit into
Conversation
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Five patterns were duplicated across
formatter.ts,report.ts,scanner.ts,cli.tsandgithub.ts. They now live in one place, so adding a status or a summary counter is a single-file change instead of four. Output is unchanged (verified byte-for-byte against the pre-refactor code, see below).New
src/link-status.tsowns everything keyed byLinkStatus:STATUS_DISPLAY— replaces the parallelstatusEmoji()(report) /statusIcon()(formatter) switch statements, which drifted apart forinsecure-http. Stores{ emoji, symbol, color }withcoloras a name ('green' | ...) so the module stays chalk-free;formatter.tsmaps names to chalk via a localCOLORSrecord.SUMMARY_ROWS— the Markdown summary table and the console counters line were two hand-maintained lists of the same 7 counters, in the same order, with different labels. Now one list of{ key, emoji, label, shortLabel, color }:isFailureStatus/isHealthy/hasIssue— the filter predicates previously inlined in both reporters (r.status === 'broken' || r.status === 'malformed' || r.status === 'timeout', etc.). They accept a structuralLinkFacets, so no import cycle withscanner.ts.STATUS_SUMMARY_KEY—summarize()inscanner.tshad oneifper status; it now looks up the counter key.insecure-httpmaps tonull(it is counted via theisHttpflag), preserving current behaviour.shouldFailScan(counts, thresholds)— the identical 3-clause exit-code expression incli.tsandgithub.ts. Both call sites passconfig, which already satisfiesFailureThresholds.ScanSummarynowextends StatusCountsinstead of re-declaring the 7 counters.Also deduplicated:
URLDN_SHORTENER_URLwas defined twice →src/constants.ts.error instanceof Error ? error.message : String(error)appeared 4× →toErrorMessage()inutils.ts;isValidUrl/isInsecureHttpshared a try/catchnew URL()→parseUrl().printConsoleReportrepeated the same "heading, loop, per-entry line, dimmed detail lines" block 5× → oneprintSection({ heading, icon, color, results, limit?, suffix?, details?, footer? })helper.checkUrlbuilt the sameCheckResultliteral 5× → a localresult()closure fillingurl/isHttp/durationMs/redirectChain, plusclassifyStatusCode()for the 2xx/3xx/else branching.INLINE_LINK_REandIMAGE_MARKDOWN_REwere the same pattern modulo a leading!→ composed from sharedLINK_LABEL/LINK_TARGETsources.upsertPullRequestCommentspreadcontext.repoinstead of repeatingowner:/repo:three times.Verification
Beyond
lint,format:check,typecheckand the suite (newtest/link-status.test.ts, plus tests forparseUrl/toErrorMessage), I ran a throwaway parity test that imported the pre-refactorsrc/fromgit archive HEADalongside the new one and asserted identical output for: the console report (over all 48 status/flag combinations, including the ">20 ok links" truncation branch), every verbose line, the Markdown report (issues and no-issues paths),checkUrlacross status codes100..500with and without redirects,extractLinksFromMarkdown, and scan summaries. All matched exactly; the scaffold was deleted and is not part of this PR.Link to Devin session: https://app.devin.ai/sessions/5084b99d963a4a8db00d7c0bcbce1c74
Requested by: @lahcenassmira