-
Notifications
You must be signed in to change notification settings - Fork 728
feat: implement rubygems registry [CM-1241] #4322
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
mbani01
wants to merge
10
commits into
main
Choose a base branch
from
feat/implement_rubygems_registry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
e2d60a1
feat: add RubyGems types and HTTP client
mbani01 6fb9792
feat: add RubyGems normalize functions
mbani01 bfaf69b
feat: add generic recordDownloadSnapshot DAL function
mbani01 3cabf60
feat: add RubyGems package-selection DAL functions
mbani01 6d8c9cf
feat: add RubyGems tier 1 core ingestion loop
mbani01 ec1aa93
feat: add RubyGems tier 2 critical-details enrichment loop
mbani01 4d82dce
feat: wire RubyGems config, workflows, and activities
mbani01 f2acf32
feat: add RubyGems worker schedules, entrypoint, and package scripts
mbani01 43d82e7
chore: add rubygems worker to packages.env
mbani01 ac19f22
fix: correct owners-fetch handling and add config to rubygems critica…
mbani01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| DOCKERFILE="./services/docker/Dockerfile.packages" | ||
| CONTEXT="../" | ||
| REPO="sjc.ocir.io/axbydjxa5zuh/packages" | ||
| SERVICES="github-repos-enricher bq-dataset-ingest npm-worker pypi-worker maven-worker osv-worker dockerhub-sync cargo-worker go-worker nuget-worker security-contacts-worker" | ||
| SERVICES="github-repos-enricher bq-dataset-ingest npm-worker pypi-worker maven-worker osv-worker dockerhub-sync cargo-worker go-worker nuget-worker security-contacts-worker rubygems-worker" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| version: '3.1' | ||
|
|
||
| x-env-args: &env-args | ||
| DOCKER_BUILDKIT: 1 | ||
| NODE_ENV: docker | ||
| SERVICE: rubygems-worker | ||
| SHELL: /bin/sh | ||
| SUPPRESS_NO_CONFIG_WARNING: 'true' | ||
| CROWD_TEMPORAL_TASKQUEUE: rubygems-worker | ||
|
|
||
| services: | ||
| rubygems-worker: | ||
| build: | ||
| context: ../../ | ||
| dockerfile: ./scripts/services/docker/Dockerfile.packages | ||
| command: 'pnpm run start:rubygems-worker' | ||
| working_dir: /usr/crowd/app/services/apps/packages_worker | ||
| env_file: | ||
| - ../../backend/.env.dist.local | ||
| - ../../backend/.env.dist.composed | ||
| - ../../backend/.env.override.local | ||
| - ../../backend/.env.override.composed | ||
| environment: | ||
| <<: *env-args | ||
| restart: always | ||
| networks: | ||
| - crowd-bridge | ||
|
|
||
| rubygems-worker-dev: | ||
| build: | ||
| context: ../../ | ||
| dockerfile: ./scripts/services/docker/Dockerfile.packages | ||
| command: 'pnpm run dev:rubygems-worker' | ||
| working_dir: /usr/crowd/app/services/apps/packages_worker | ||
| env_file: | ||
| - ../../backend/.env.dist.local | ||
| - ../../backend/.env.dist.composed | ||
| - ../../backend/.env.override.local | ||
| - ../../backend/.env.override.composed | ||
| environment: | ||
| <<: *env-args | ||
| hostname: rubygems-worker | ||
| networks: | ||
| - crowd-bridge | ||
| volumes: | ||
| - ../../services/libs/audit-logs/src:/usr/crowd/app/services/libs/audit-logs/src | ||
| - ../../services/libs/common/src:/usr/crowd/app/services/libs/common/src | ||
| - ../../services/libs/common_services/src:/usr/crowd/app/services/libs/common_services/src | ||
| - ../../services/libs/data-access-layer/src:/usr/crowd/app/services/libs/data-access-layer/src | ||
| - ../../services/libs/database/src:/usr/crowd/app/services/libs/database/src | ||
| - ../../services/libs/integrations/src:/usr/crowd/app/services/libs/integrations/src | ||
| - ../../services/libs/logging/src:/usr/crowd/app/services/libs/logging/src | ||
| - ../../services/libs/nango/src:/usr/crowd/app/services/libs/nango/src | ||
| - ../../services/libs/opensearch/src:/usr/crowd/app/services/libs/opensearch/src | ||
| - ../../services/libs/queue/src:/usr/crowd/app/services/libs/queue/src | ||
| - ../../services/libs/redis/src:/usr/crowd/app/services/libs/redis/src | ||
| - ../../services/libs/snowflake/src:/usr/crowd/app/services/libs/snowflake/src | ||
| - ../../services/libs/telemetry/src:/usr/crowd/app/services/libs/telemetry/src | ||
| - ../../services/libs/temporal/src:/usr/crowd/app/services/libs/temporal/src | ||
| - ../../services/libs/types/src:/usr/crowd/app/services/libs/types/src | ||
| - ../../services/apps/packages_worker/src:/usr/crowd/app/services/apps/packages_worker/src | ||
|
|
||
| networks: | ||
| crowd-bridge: | ||
| external: true | ||
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import { scheduleRubyGemsCriticalIngestion, scheduleRubyGemsIngestion } from '../rubygems/schedule' | ||
| import { svc } from '../service' | ||
|
|
||
| setImmediate(async () => { | ||
| await svc.init() | ||
| await scheduleRubyGemsIngestion() | ||
| await scheduleRubyGemsCriticalIngestion() | ||
| await svc.start() | ||
| }) |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { getServiceChildLogger } from '@crowd/logging' | ||
|
|
||
| import { getRubyGemsConfig, getRubyGemsCriticalConfig } from '../config' | ||
| import { getPackagesDb } from '../db' | ||
|
|
||
| import { processBatch as processCoreBatch } from './runRubyGemsCoreLoop' | ||
| import { processBatch as processCriticalBatch } from './runRubyGemsCriticalLoop' | ||
| import { BatchResult } from './types' | ||
|
|
||
| const log = getServiceChildLogger('rubygems-activity') | ||
|
|
||
| export async function processRubyGemsCoreBatch(): Promise<BatchResult> { | ||
| const config = getRubyGemsConfig() | ||
| const qx = await getPackagesDb() | ||
| const today = new Date().toISOString().split('T')[0] | ||
| const result = await processCoreBatch(qx, config, today) | ||
| log.info({ ...result }, 'RubyGems core batch complete') | ||
| return result | ||
| } | ||
|
|
||
| export async function processRubyGemsCriticalBatch(): Promise<BatchResult> { | ||
| const config = getRubyGemsCriticalConfig() | ||
| const qx = await getPackagesDb() | ||
| const result = await processCriticalBatch(qx, config) | ||
| log.info({ ...result }, 'RubyGems critical batch complete') | ||
| return result | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| import axios from 'axios' | ||
|
|
||
| import { | ||
| RubyGemsFetchError, | ||
| RubyGemsFetchResult, | ||
| RubyGemsGemResponse, | ||
| RubyGemsOwner, | ||
| RubyGemsVersionItem, | ||
| } from './types' | ||
|
|
||
| function classifyError(err: unknown): RubyGemsFetchError | null { | ||
| if (!axios.isAxiosError(err)) return null | ||
| const status = err.response?.status | ||
| if (status === 404) return { kind: 'NOT_FOUND', status, message: err.message } | ||
| if (status === 429) return { kind: 'RATE_LIMIT', status, message: err.message } | ||
| return null | ||
| } | ||
|
|
||
| export async function fetchGem(name: string): Promise<RubyGemsFetchResult<RubyGemsGemResponse>> { | ||
| try { | ||
| const resp = await axios.get<RubyGemsGemResponse>( | ||
| `https://rubygems.org/api/v1/gems/${encodeURIComponent(name)}.json`, | ||
| { timeout: 15000 }, | ||
| ) | ||
| return resp.data | ||
| } catch (err) { | ||
| const classified = classifyError(err) | ||
| if (classified) return classified | ||
| throw err | ||
| } | ||
| } | ||
|
|
||
| export async function fetchVersions( | ||
| name: string, | ||
| ): Promise<RubyGemsFetchResult<RubyGemsVersionItem[]>> { | ||
| try { | ||
| const resp = await axios.get<RubyGemsVersionItem[]>( | ||
| `https://rubygems.org/api/v1/versions/${encodeURIComponent(name)}.json`, | ||
| { timeout: 15000 }, | ||
| ) | ||
| return resp.data | ||
| } catch (err) { | ||
| const classified = classifyError(err) | ||
| if (classified) return classified | ||
| throw err | ||
| } | ||
| } | ||
|
|
||
| export async function fetchOwners(name: string): Promise<RubyGemsFetchResult<RubyGemsOwner[]>> { | ||
| try { | ||
| const resp = await axios.get<RubyGemsOwner[]>( | ||
| `https://rubygems.org/api/v1/gems/${encodeURIComponent(name)}/owners.json`, | ||
| { timeout: 15000 }, | ||
| ) | ||
| return resp.data | ||
| } catch (err) { | ||
| const classified = classifyError(err) | ||
| if (classified) return classified | ||
| throw err | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| import { | ||
| NormalizedRubyGemsOwner, | ||
| NormalizedRubyGemsPackage, | ||
| NormalizedRubyGemsVersion, | ||
| RubyGemsGemResponse, | ||
| RubyGemsOwner, | ||
| RubyGemsVersionItem, | ||
| } from './types' | ||
|
|
||
| function nonEmpty(value: string | null | undefined): string | null { | ||
| if (!value) return null | ||
| const trimmed = value.trim() | ||
| return trimmed === '' ? null : trimmed | ||
| } | ||
|
|
||
| export function normalizeRubyGemsPackage(doc: RubyGemsGemResponse): NormalizedRubyGemsPackage { | ||
| const licenses = doc.licenses && doc.licenses.length > 0 ? doc.licenses : null | ||
| return { | ||
| description: nonEmpty(doc.info), | ||
| homepage: nonEmpty(doc.homepage_uri), | ||
| declaredRepositoryUrl: nonEmpty(doc.source_code_uri), | ||
| licenses, | ||
| licensesRaw: licenses ? licenses.join(', ') : null, | ||
| latestVersion: nonEmpty(doc.version), | ||
| totalDownloads: doc.downloads ?? 0, | ||
| } | ||
| } | ||
|
|
||
| function parseCreatedAt(value: string | undefined): Date | null { | ||
| if (!value) return null | ||
| const date = new Date(value) | ||
| return isNaN(date.getTime()) ? null : date | ||
| } | ||
|
|
||
| export function normalizeRubyGemsVersions( | ||
| items: RubyGemsVersionItem[], | ||
| ): NormalizedRubyGemsVersion[] { | ||
| return items.map((item) => ({ | ||
| number: item.number, | ||
| publishedAt: parseCreatedAt(item.created_at), | ||
| isPrerelease: item.prerelease ?? false, | ||
| licenses: item.licenses && item.licenses.length > 0 ? item.licenses : null, | ||
| })) | ||
| } | ||
|
|
||
| export function pickLatestRubyGemsVersion( | ||
| versions: NormalizedRubyGemsVersion[], | ||
| ): NormalizedRubyGemsVersion | null { | ||
| if (versions.length === 0) return null | ||
| const sorted = [...versions].sort((a, b) => { | ||
| const at = a.publishedAt ? a.publishedAt.getTime() : 0 | ||
| const bt = b.publishedAt ? b.publishedAt.getTime() : 0 | ||
| return bt - at | ||
| }) | ||
| const stable = sorted.find((v) => !v.isPrerelease) | ||
| return stable ?? sorted[0] | ||
| } | ||
|
mbani01 marked this conversation as resolved.
|
||
|
|
||
| export function normalizeRubyGemsOwners(owners: RubyGemsOwner[]): NormalizedRubyGemsOwner[] { | ||
| return owners | ||
| .filter((o): o is RubyGemsOwner & { handle: string } => !!o.handle && o.handle.trim() !== '') | ||
| .map((o) => ({ username: o.handle, email: nonEmpty(o.email) })) | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.