Skip to content

Conversation

@aflanagan
Copy link
Contributor

Summary

This PR adds GitHub API integration to the Cronitor GitHub Action, enabling it to automatically fetch and report workflow schedule information to Cronitor monitors.

Key Changes

  • Added @actions/github dependency to interact with GitHub's REST API
  • Implemented workflow schedule extraction with extractSchedule() function that parses YAML workflow files to find cron schedules
  • Added GitHub API integration via getWorkflowSchedule() function that:
    • Fetches workflow file content using the GitHub API
    • Extracts the cron schedule from the workflow YAML
    • Gracefully handles missing tokens or API errors
  • Updated monitor key generation from {repo-id}-{workflow-id} to gh-{slugified-workflow-name} for better readability
  • Added slugify() utility function to convert workflow names into URL-safe keys
  • Enhanced monitor payload to include the schedule field when available
  • Updated dependencies with new Octokit packages and related utilities (auth-token, core, endpoint, graphql, request, etc.)

Implementation Details

  • The schedule is fetched asynchronously during the putMonitorDetails() call
  • If no github_token is provided or the API call fails, the action continues without schedule information (non-blocking)
  • The YAML parser is regex-based and handles both quoted and unquoted cron values
  • All new dependencies are properly licensed and documented in dist/licenses.txt

- Add schedule field to Cronitor PUT request when workflow has a cron schedule
- Fetch workflow file content via GitHub API to extract schedule
- Change monitor key format from `{repo_id}-{workflow_id}` to `gh-{slugified-name}`
- Add @actions/github dependency for API calls
- Update actions/checkout from v3 to v4
- Update actions/setup-node from v3.5.0 to v4
- Update actions/upload-artifact from v3 to v4
- Export slugify, extractSchedule, getMonitorState, getKey for testing
- Add index.test.js with 15 tests covering:
  - slugify: space conversion, special char removal, hyphen handling
  - extractSchedule: cron parsing from workflow YAML
  - getMonitorState: action/conclusion state mapping
  - getKey: key generation with gh- prefix
- Only run main function when executed directly (not when imported)
- Add key_format input: "slugified" (default) or "legacy"
- Default uses new gh-{slugified-name} format
- Legacy format (repo-id-workflow-id) available for existing users
- Split getKey into getLegacyKey and getSlugifiedKey helpers
- Add tests for both key format functions
- Step values (*/15 * * * *)
- Ranges and lists (0,30 9-17 * * 1-5)
@aflanagan aflanagan force-pushed the claude/add-cronitor-schedule-s0MGD branch 2 times, most recently from a137b09 to a7a51cc Compare January 22, 2026 20:57
- Update example to use @v8
- Add key_format parameter to docs
- Update github_token description (now used for schedule fetching)
- Add Changelog section documenting v8 changes
@aflanagan aflanagan force-pushed the claude/add-cronitor-schedule-s0MGD branch from a7a51cc to 3b17b3c Compare January 22, 2026 20:59
- Rename getLegacyKey to getIdKey
- Update key_format option from 'legacy' to 'id'
- Simplify changelog wording
- Set Cronitor API version to 2025-11-28
- Rename extractSchedule to extractSchedules, returns array
- Use 'schedules' (plural) in API payload
- Add test for multiple cron schedules
- Upgrade @actions/github from 5.1.1 to 7.0.0
- Add undici override to fix remaining vulnerability
- All npm audit vulnerabilities resolved
@aflanagan aflanagan merged commit 64da8aa into main Jan 22, 2026
2 checks passed
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.

3 participants