Add comprehensive API command with resource management#39
Open
Add comprehensive API command with resource management#39
Conversation
Implements comprehensive CLI interface for all Cronitor API resources:
- monitors: list, get, create, update, delete, pause/unpause
- issues: list, get, create, update, delete, bulk operations
- statuspages: list, get, create, update, delete
- components: list, get, create, update, delete
- incidents: list, get, create, update, resolve
- metrics: list with time ranges, aggregates
- notifications: list, get, create, update, delete
- environments: list, get, create, update, delete
Features:
- Generic API client with proper authentication and error handling
- Support for --data and --file flags for JSON input
- Support for stdin JSON input via piping
- Table and JSON output formats
- Pagination support with --page flag
- Environment filtering with --env flag
- Monitor-specific --with-events flag for latest events
- Comprehensive BATS test suite
Usage examples:
cronitor api monitors
cronitor api monitors get <key>
cronitor api monitors create --data '{"key":"my-job","type":"job"}'
cronitor api issues --state open
cronitor api metrics --monitor <key> --aggregates
https://claude.ai/code/session_01UDueW9A6SuxugCcsbAMfdB
Replace action-word subcommands (list, get, create, update, delete) with
a cleaner flag-based pattern inspired by Vercel and Sentry CLIs:
- `cronitor api monitors` lists all monitors
- `cronitor api monitors <key>` gets a specific monitor
- `cronitor api monitors --new '{...}'` creates a new monitor
- `cronitor api monitors <key> --update '{...}'` updates a monitor
- `cronitor api monitors <key> --delete` deletes a monitor
Applied consistently across all API resources: monitors, issues,
statuspages, components, incidents, notifications, and environments.
https://claude.ai/code/session_01UDueW9A6SuxugCcsbAMfdB
Incidents are the same as issues, and components are part of status pages rather than standalone API resources. https://claude.ai/code/session_01UDueW9A6SuxugCcsbAMfdB
Replace `cronitor api <resource>` with `cronitor <resource> <action>`:
cronitor monitor list
cronitor monitor get <key>
cronitor monitor create --data '{...}'
cronitor monitor update <key> --data '{...}'
cronitor monitor delete <key>
cronitor monitor pause <key>
cronitor monitor unpause <key>
Same pattern for: statuspage, issue, notification, environment
Features:
- Beautiful table output using lipgloss styling
- Colored status indicators (passing/failing/paused)
- Consistent --format, --output, --page flags
- Aliases: `env` for environment, `notifications` for notification
https://claude.ai/code/session_01UDueW9A6SuxugCcsbAMfdB
- Create internal/testutil package with shared MockAPI server, CaptureStdout helper, and ExecuteCommand helper for command-level testing - Refactor lib/api_client_test.go to use shared testutil package - Add MergePagedJSON and FetchAllPages unit tests in cmd/ui_test.go - Add integration tests in cmd/integration_test.go covering table, JSON, YAML output formats, file output, pagination metadata, and --all flag - Add API documentation URLs to all resource command help text Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Run `go test ./...` on both Linux and Windows before the BATS integration tests. All Go tests use mock servers and need no secrets. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
…bility
- Inject key into PUT request body for all update commands (environment,
group, issue, notification, maintenance, site, statuspage, component)
- Fix issue resolve to fetch current issue before PUT (API requires all fields)
- Fix JSON response key mismatches: issue, maintenance, site, statuspage,
and component list commands used wrong keys (e.g. "issues" vs "data")
- Fix statuspage list subdomain field ("subdomain" → "hosted_subdomain")
- Update test fixtures to match actual API response structure
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Document search, clone, bulk delete, YAML support, components, bulk issue actions, and additional filter flags. https://claude.ai/code/session_01UDueW9A6SuxugCcsbAMfdB
…spages The --all flag could result in fetching hundreds of pages for high-volume resources like issues. Keep --all only on monitors where accounts typically have ~500 monitors max (~18 pages). Add integration tests for monitor list --all that run when CRONITOR_API_KEY is available on CI. https://claude.ai/code/session_01UDueW9A6SuxugCcsbAMfdB
The --all flag is not the right approach for any resource. Users can paginate explicitly with --page. Replace --all example with --format yaml to highlight YAML config export capability. https://claude.ai/code/session_01UDueW9A6SuxugCcsbAMfdB
- convertWeekOfMonth: Replace map iteration with ordered slices to ensure deterministic output order (Go maps iterate randomly) - TimeTrigger: Add description "Runs once at <time>" instead of returning empty description - TestCompleteScenario_StartupTask: Fix string length check from 13 to 19 to match "Runs on system boot" (19 chars) https://claude.ai/code/session_01XhBKxwYS2NYdHX7KsuTZHn
TimeTrigger is a one-time trigger that intentionally returns no description. Remove the test case that incorrectly expected one rather than changing production code to satisfy it. https://claude.ai/code/session_01XhBKxwYS2NYdHX7KsuTZHn
Replace the --all flag with dedicated export subcommands: - `cronitor monitor export` - exports all monitors as YAML config (uses two-pass: JSON for page count, then YAML for each page) - `cronitor group export` - exports all groups as JSON Remove --all from maintenance, site, and all other list commands. Add groups section to README documentation. https://claude.ai/code/session_01UDueW9A6SuxugCcsbAMfdB
f17f938 to
ecb79c4
Compare
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
This PR introduces a new
apicommand that provides full access to the Cronitor API, allowing users to manage monitors, issues, status pages, environments, notifications, and view metrics directly from the CLI.Key Changes
New API Command Structure
Resource Management Subcommands
API Client Library
Notable Implementation Details
--dataflag,--fileflag, or stdin--pageflag--env,--monitoracross commandsUsage Examples
https://claude.ai/code/session_01UDueW9A6SuxugCcsbAMfdB