[TW-4734] refactor(cli): reduce code duplication across commands and adapters#42
Merged
qasim-nylas merged 2 commits intomainfrom Mar 28, 2026
Merged
Conversation
…adapters Centralize repeated patterns into shared helpers to improve maintainability: - Add common.StatusColor/StatusIcon/ColorSprint for status-to-color mapping, replacing duplicate functions in scheduler, webhook, and notetaker packages - Add common.SetupPagination with explicit PaginationMode (SinglePage/WithCap/All) to eliminate duplicate limit/maxItems logic in list commands - Add common.NormalizePageSize and FetchCursorPages to reduce pagination boilerplate - Extract dashboard setDPoPProof() from duplicate blocks in doPostRaw/doGetRaw - Add testutil.WriteJSONResponse() with buffer-first encoding (goroutine-safe, returns proper 500 on encode failure) - Consolidate email list command into shared fetchListMessages/applyListFolderFilter Includes unit tests for all new helpers and updated consumer tests.
…arnings - Remove NEVER git commit/push rules (handled by global CLAUDE.md) - Add learnings for new shared helpers: StatusColor, SetupPagination, NormalizePageSize, FetchCursorPages, WriteJSONResponse - Consolidate Testing/Hooks/Context sections to reduce redundancy
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
common.StatusColor()/StatusIcon()/ColorSprint(), replacing duplicate functions in scheduler, webhook, and notetaker packagescommon.SetupPagination()with explicitPaginationMode(SinglePage / WithCap / All) to eliminate duplicate limit/maxItems resolution logic across list commandscommon.NormalizePageSize()andFetchCursorPages()to reduce cursor-based pagination boilerplatedashboard.setDPoPProof()from duplicate blocks indoPostRaw()anddoGetRaw()testutil.WriteJSONResponse()— goroutine-safe, buffer-first encoding with proper 500 on failure — for the JSON response pattern repeated 186 times across 38 test filesfetchListMessages()/applyListFolderFilter()/resolveListPagination()Changed Files
New files (7)
common/status.goStatusColor,StatusIcon,ColorSprint— 17 status valuescommon/status_test.godashboard/http_test.gocalendar/events_list_test.gocontacts/list_test.goemail/list_test.gowebhook/render_test.goModified files (16)
common/pagination.goSetupPagination,PaginationMode,NormalizePageSize,FetchCursorPagescommon/pagination_test.godashboard/http.gosetDPoPProof()from 2 duplicate blockstestutil/helpers.goWriteJSONResponse()with buffer-first encodingtestutil/helpers_test.goscheduler/bookings.gogetStatusColor()+ inline switch →common.ColorSprint()webhook/list.gogetStatusIcon()→common.StatusIcon()webhook/show.godisplayWebhookDetails()+common.StatusIcon()webhook/update.gogetStatusIcon()→common.StatusIcon()webhook/webhook_advanced_test.gocommon.StatusIcon()notetaker/list.goformatState()from 22 lines to 7 viacommon.StatusColor()contacts/list.gocommon.SetupPagination()email/list.goresolveListPagination,fetchListMessages,applyListFolderFilteremail/search.goNormalizePageSize()andFetchCursorPages()calendar/events_list.goSetupPagination()andFetchCursorPages()CLAUDE.mdStats
Test plan
make cipasses (fmt, vet, lint, unit tests, race detection, security, vuln, build)TestFetchMessages,TestFormatState,StatusIcon_*etc.nylas email list --allpagination behavior preserved (3-mode PaginationMode)testutil.WriteJSONResponseencode-failure returns HTTP 500 (not original status)JIRA: TW-4734