ref(commands): add listCommand factory and migrate all list commands - #270
Closed
BYK wants to merge 6 commits into
Closed
ref(commands): add listCommand factory and migrate all list commands#270BYK wants to merge 6 commits into
BYK wants to merge 6 commits into
Conversation
… errors
When the @sentry/api SDK returns a non-2xx response, the error object is
the parsed JSON body (e.g. { detail: "Not found" }). The throwApiError
function was using String(error) as fallback, which produces the
unhelpful "[object Object]" for any plain object.
Introduce stringifyUnknown() in errors.ts as a central utility that
safely converts unknown values to readable strings: strings pass through,
Error instances yield .message, objects are JSON-serialized, and
primitives use String(). Replace all 8 call sites across the codebase
that had the same String(error) / ternary pattern with this utility.
Closes #256
Wrap JSON.stringify in try/catch to gracefully handle circular references and BigInt values. Falls back to String() which is always safe. Add tests for both edge cases. Addresses Cursor BugBot feedback on PR #259.
…e/log list commands Introduces src/lib/list-helpers.ts with: - listCommand() factory wrapping buildCommand with standard flags (--limit, --json, optional --query/--sort/--cursor/--follow), output pipeline, and cursor cache management - fetchFromOrgs() — parallel multi-org fetch with graceful per-org error handling - resolveOrgsForList() — org resolution chain (explicit → default → DSN auto-detect) - resolveSingleTarget() — single org+project resolution for trace/log commands - makeValidateLimit() — range-checked limit parser factory - writeSelfHostedWarning(), resolveCursorFlag(), updateCursorCache() helpers Migrated 5 list commands to use the factory: - org/list.ts: ~120 → ~104 lines - team/list.ts: ~270 → ~127 lines (eliminates fetchOrgTeamsSafe + resolveOrgsToFetch duplicates) - repo/list.ts: ~270 → ~130 lines (eliminates fetchOrgRepositoriesSafe + resolveOrgsToFetch duplicates) - trace/list.ts: ~230 → ~126 lines (also fixes @stricli/core import → lib/command.js) - log/list.ts: ~360 → ~238 lines (keeps streaming loop, uses factory for non-follow path) All 1723 unit tests pass.
…d helpers - Replace fetchAllOrgProjects sequential for-loop with fetchFromOrgs() (parallel) - Replace resolveOrgsForAutoDetect (120 lines) with thin wrapper around resolveOrgsForList - Remove now-unused imports: listOrganizations, getDefaultOrganization, resolveAllTargets
…ssues via raw requests - team/list: add --cursor/-c flag using listTeamsPaginated for single-org fetches - repo/list: add --cursor/-c flag using listRepositoriesPaginated for single-org fetches - api-client: rewrite listTeams/listRepositories to use orgScopedPaginateAll (fixes silent truncation) - api-client: add listTeamsPaginated, listRepositoriesPaginated, listIssuesPaginated helpers - api-client: rewrite listIssues to bypass @sentry/api SDK, enabling access to Link header
Eliminates ~150 lines of boilerplate by using the shared listCommand factory. All resolution, alias, sorting, and fetch logic stays in the fetch callback. JSON output uses formatJson override; footer tip uses function form to pick the right tip text based on single vs multi-project mode.
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Build
Other
Bug Fixes 🐛Telemetry
Other
Internal Changes 🔧
Other
🤖 This preview updates automatically when you update the PR. |
Member
Author
|
Closing in favour of a rebased version — PR #262 landed a very similar refactor on main (dispatchOrgScopedList + buildOrgListCommand). Will open a fresh PR from main that only adds what's new: migrating org/list to the existing buildOrgListCommand factory. |
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
Introduces a shared
listCommandfactory insrc/lib/list-helpers.tsthat eliminates ~800 lines of duplicated boilerplate across the 7sentry * listcommands.What changed
New factory (
src/lib/list-helpers.ts)listCommand<T>()— wrapsbuildCommandwith shared flags (--limit,--json, optional--query,--sort,--cursor,--follow), the full output pipeline (JSON → empty state → render → truncation → footer tip), and cursor cache managementfetchFromOrgs,resolveOrgsForList,resolveSingleTarget,makeValidateLimit,resolveCursorFlag,updateCursorCacheMigrated commands — each now a thin config object; all boilerplate removed:
org/list,team/list,repo/list,trace/list,log/list,issue/listproject/list— partially improved (parallel fetch viafetchFromOrgs, shared org resolution)Cursor pagination added to
team/listandrepo/list(--cursor/-c last)API client fixes (
src/lib/api-client.ts):listTeams/listRepositoriesrewritten viaorgScopedPaginateAll— fixes silent truncation at 100 itemslistIssuesrewritten to bypass@sentry/apiSDK which discardsLinkresponse headerslistTeamsPaginated,listRepositoriesPaginated,listIssuesPaginatedOther fixes:
trace/listwas incorrectly importing from@stricli/coredirectly, bypassing the telemetry wrapper — fixedfetchAll*loops inproject/listreplaced with parallelPromise.allviafetchFromOrgs