feat: use public api for github metrics#26
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR migrates data fetching from the GitHub API to a new public API, removes GitHub token requirements, and enhances metadata parsing with deduplication logic.
- Switched all repository and stats endpoints to use
ZUPLO_API_BASEpublic API - Simplified server routes and removed token/rate-limit handling
- Added unique IDs, URL pattern support, and updated Svelte components to use
source.id
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/lib/github.ts | Replaced GitHub API calls with public API methods; added parsing, hashing, and dedupe logic |
| src/lib/types.ts | Added id to DataSource and created_at to GitHubModule |
| src/routes/api/sources/+server.ts | Updated import to use githubApi singleton |
| src/routes/api/modules/+server.ts | Removed token instantiation and rate-limit code; updated githubApi usage |
| src/components/SourceCard.svelte | Switched iteration key to source.id and updated imports |
| src/components/GitHubStats.svelte | Updated org URLs to use asimovModulesOrgUrl and asimovPlatformOrgUrl |
| src/lib/config.ts | Added ZUPLO_API_BASE and ASIMOV_PLATFORM_ORG_NAME constants |
| README.md | Removed token setup instructions; updated numbering and API description |
| .env.example | Removed GITHUB_TOKEN placeholder |
Comments suppressed due to low confidence (3)
README.md:53
- [nitpick] The step numbering jumps (the original steps were removed), which may confuse readers. Renumber the steps sequentially (e.g., change this from '3.' to '1.') or adjust the formatting for clarity.
3. **Start the development server**
src/lib/github.ts:36
- This new public API method (
fetchMetricsData) isn’t covered by existing tests. Consider adding unit or integration tests with mocked fetch responses to validate success and error paths.
private async fetchMetricsData(): Promise<ApiMetricsResponse> {
| const metadata = this.parseModuleMetadata(apiModule.manifestYAML || null); | ||
|
|
||
| return { | ||
| id: Math.abs(this.hashCode(apiModule.name)), |
There was a problem hiding this comment.
The convertApiModuleToGitHubModule method adds an id property to the returned object, but the GitHubModule interface in types.ts isn’t updated to include id. This mismatch will break your TypeScript checks; either add id to the GitHubModule interface or remove it here.
| } | ||
|
|
||
| export interface DataSource { | ||
| id: string; // Unique identifier for the data source |
There was a problem hiding this comment.
The DataSource interface defines id but missing other fields (module_name, module_label, flows, rdf) that are pushed in github.ts. This leads to type mismatches and runtime errors. Update the interface to include these properties.
| {#each endpointSources as source (source.module_name)} | ||
| {#each endpointSources as source (source.id)} | ||
| <a | ||
| href="https://github.com/asimov-modules/{source.module_name}" |
There was a problem hiding this comment.
The link references source.module_name, but after migrating to use source.id, many data sources (from URL prefixes) no longer have module_name defined. This will result in broken links. Ensure each DataSource includes module_name or update the template to use the correct field.
This pull request introduces significant changes to the codebase, primarily focused on migrating from GitHub API-based data fetching to a new public API, simplifying environment setup, and improving data handling and organization. Key updates include removing the dependency on GitHub tokens, introducing new API endpoints, and enhancing the metadata processing logic.
Migration to Public API:
src/lib/config.ts: AddedZUPLO_API_BASEandASIMOV_PLATFORM_ORG_NAMEconstants to support the new public API endpoints for fetching module and platform data. [1] [2]src/lib/github.ts: Replaced GitHub API-based methods with new methods (fetchMetricsDataandfetchPlatformData) to retrieve data from the public API. Removed token-based authentication and rate limit handling. [1] [2]Environment Setup Simplification:
.env.example: Removed theGITHUB_TOKENplaceholder since environment variables are no longer required.README.md: Updated setup instructions to reflect the removal of GitHub token requirements and clarified the data source as the ASIMOV Platform API. [1] [2]Metadata and Data Handling Enhancements:
src/lib/github.ts: Enhanced module metadata parsing and introduced deduplication logic for data sources using unique identifiers. Added support for handling URL patterns in addition to URL prefixes. [1] [2]src/lib/types.ts: Addedidfield to theDataSourceinterface for uniquely identifying data sources.Updates to Components:
src/components/GitHubStats.svelte: Updated links to use new organization URLs (asimovModulesOrgUrlandasimovPlatformOrgUrl). [1] [2]src/components/SourceCard.svelte: Modified data source iteration logic to use the newidfield instead ofmodule_name. [1] [2]Removal of Legacy Code:
src/routes/api/modules/+server.ts: Removed GitHub token initialization and replaced theGitHubAPIinstantiation with the updatedgithubApiobject.