codejson-core Refactor - #138
Draft
sachin-panayil wants to merge 8 commits into
Draft
Conversation
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.
codejson-core Refactor
Problem
This repository owned the code.json schema, its Zod validation rules, and the
logic that merges repository metadata into an existing file. That put four separate concerns in one action: talking to GitHub, measuring the repository, deciding what a valid code.json is, and deciding how a new observation merges over an old file.
Two costs followed:
had to reimplement the schema.
Solution
The schema, validation, and merge logic now come from
codejson-core, a library shared the provides logic to validate and assemble code.json's. This action binds to the libraries CMS profile in a single file,src/codejson.ts, and owns only what core leaves out:A generated code.json is a draft by design so things like status, longDescription, and the other unobservable fields are blank for a human to complete from the PR. The pull_request status check is unchanged and remains the gate that keeps invalid files off main.
AI Usage
Result
The schema is version-pinned by the
codejson-corerelease, so schema updates reach this action as a Dependabot bump rather than a code change, and theupdate-codejson-schemaworkflow is deleted. Roughly 2,300 lines leave this repository and the action is more lightweight. This repo is now simply a wrapper around core logic and an interface to Github Actions, significantly reducing its concerns and introducing more separation.One known follow-up:
src/codejson.tsworks around two gaps incodejson-core. Itsassemblerejects in-progress drafts, and its CMS baseline leaves enum keysundefinedso they vanish on serialization. Both get fixed upstream incodejson-core0.2.0, after which the code becomes even more simpler.Test Plan
To verify manually, run the action against a repository with an existing
code.json and confirm the generated file is unchanged apart from
date.metadataLastUpdated, then run it against one with no code.json andconfirm the log lists the blank fields as warnings while the PR is still opened. I'm gonna actually test these on repos of different cases and paste the links here: