Repository navigation
feat: add draft-segment-schema-pr action - #294
NicolasMassart wants to merge 3 commits into
Conversation
Open a Consensys/segment-schema draft from Mobile or Extension analytics diffs after the PR author agrees, using the GitHub API for the client file list. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
|
All alerts resolved. Learn more about Socket for GitHub. This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored. Ignoring alerts on:
|
|
@SocketSecurity ignore npm/yaml@2.9.0 official parser; we only call parseDocument(text), no reviver/onAnchor. |
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Analytics detection, YAML generation, comment ownership, and existing branch updates contain correctness and reliability issues.
Review effort: Balanced
Findings: 1
Open (11)
Detect slug collisions before writing event files · New Fetch branch into remote-tracking ref · New Duplicate prefilter recognizes addSensitiveProperties · New Count changed PR files, not renamed paths · New Quote event names in generated YAML · New Base writability output on generated file changes · New Prefilter recognizes addSensitiveProperties · New Diff unresolved expressions against base model · New Restrict marker matches to workflow-authored comments · New Offer agreement only when files will change · New Document dry-run summary behavior accurately · New
What changed in this PR
Adds a reusable composite action that detects Mobile/Extension analytics changes and manages draft Segment schema PRs.
Changes:
- Adds analytics extraction, schema generation, and GitHub publishing.
- Adds gating for proposal, creation, update, and closure workflows.
- Adds tests, documentation, dependencies, and lint/coverage configuration.
| File | Description |
|---|---|
yarn.lock |
Locks the YAML dependency. |
src/segment-schema-draft-pr/types.ts |
Defines action data models. |
src/segment-schema-draft-pr/schema-index.ts |
Indexes existing schema YAML. |
src/segment-schema-draft-pr/publish.ts |
Publishes comments and schema PRs. |
src/segment-schema-draft-pr/publish.test.ts |
Tests publishing behavior. |
src/segment-schema-draft-pr/pr-body.ts |
Renders proposal and PR text. |
src/segment-schema-draft-pr/pr-body.test.ts |
Tests rendered text and splicing. |
src/segment-schema-draft-pr/parse-args.ts |
Parses CLI arguments. |
src/segment-schema-draft-pr/parse-args.test.ts |
Tests argument parsing. |
src/segment-schema-draft-pr/names.ts |
Normalizes schema names. |
src/segment-schema-draft-pr/names.test.ts |
Tests name normalization. |
src/segment-schema-draft-pr/github-output.ts |
Writes action outputs. |
src/segment-schema-draft-pr/github-output.test.ts |
Tests output writing. |
src/segment-schema-draft-pr/github-api.ts |
Wraps GitHub API operations. |
src/segment-schema-draft-pr/github-api.test.ts |
Tests GitHub API helpers. |
src/segment-schema-draft-pr/generate.ts |
Orchestrates schema generation. |
src/segment-schema-draft-pr/generate.test.ts |
Tests end-to-end generation. |
src/segment-schema-draft-pr/diff-models.ts |
Computes analytics changesets. |
src/segment-schema-draft-pr/diff-models.test.ts |
Tests changeset calculation. |
src/segment-schema-draft-pr/constants.ts |
Defines shared action constants. |
src/segment-schema-draft-pr/config.ts |
Defines platform configuration. |
src/segment-schema-draft-pr/config.test.ts |
Tests platform configuration. |
src/segment-schema-draft-pr/client-diff.ts |
Reads PR TypeScript diffs. |
src/segment-schema-draft-pr/client-diff.test.ts |
Tests PR diff handling. |
src/segment-schema-draft-pr/cli.ts |
Provides the action CLI entrypoint. |
src/segment-schema-draft-pr/apply-changes.ts |
Creates and updates schema YAML. |
src/segment-schema-draft-pr/apply-changes.test.ts |
Tests schema mutations. |
src/segment-schema-draft-pr/analytics-model.ts |
Extracts analytics from TypeScript. |
src/segment-schema-draft-pr/analytics-model.test.ts |
Tests analytics extraction. |
src/env-utils.ts |
Exposes process environment access. |
src/env-utils.test.ts |
Tests environment helpers. |
README.md |
Documents action usage and workflows. |
package.json |
Adds scripts, YAML, and action tests. |
jest.config.js |
Raises coverage thresholds. |
CHANGELOG.md |
Records the new action. |
.github/actions/draft-segment-schema-pr/gate.test.mjs |
Tests pre-install gating. |
.github/actions/draft-segment-schema-pr/gate.mjs |
Implements pre-install gating. |
.github/actions/draft-segment-schema-pr/action.yml |
Defines the composite action. |
.eslintrc.js |
Adds linting for action modules. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| const relative = path.join( | ||
| 'libraries', | ||
| 'events', | ||
| config.defaultLibrary, | ||
| `${toKebabSlug(event.eventName)}.yaml`, |
| git config user.name "github-actions[bot]" | ||
| git config user.email "41898282+github-actions[bot]@users.noreply.github.com" | ||
| git checkout -B "$BRANCH" | ||
| git fetch origin "$BRANCH" || true |
| export const DIFF_PREFILTER = | ||
| /EVENT_NAME|MetaMetricsEventName|trackEvent|addProperties|createEventBuilder/u; |
| let tooManyFiles = false; | ||
| if (input.mode !== 'close') { | ||
| const diff = collectTsDiff(input.pullFiles ?? []); | ||
| tooManyFiles = diff.files.length > MAX_CHANGED_TS_FILES; |
| ): Document { | ||
| const doc = parseDocument( | ||
| [ | ||
| `name: ${eventName}`, |
| export const DIFF_PREFILTER = | ||
| /EVENT_NAME|MetaMetricsEventName|trackEvent|addProperties|createEventBuilder/u; |
| const unresolved = [...head.events.values()].flatMap( | ||
| (event) => event.unresolved, | ||
| ); |
| }, | ||
| ); | ||
|
|
||
| return comments.find((comment) => comment.body?.includes(PROPOSAL_MARKER)); |
| '', | ||
| ]; | ||
|
|
||
| if (changesetHasWritableChanges(changeset)) { |
| --head-sha <pr-head-sha> | ||
| ``` | ||
|
|
||
| `--phase publish --dry-run` prints the summary path and skips GitHub writes. |



Summary
draft-segment-schema-prcomposite action that reads Mobile/Extension analytics diffs through the GitHub API, comments one proposal, and opens a draftConsensys/segment-schemaPR after the author commentsI agree to open a draft Segment schema PR.pulls.listFiles(three-dot PR comparison). Schema YAML is still committed and pushed with git. Helper, not a merge gate.@v1exists.fixes MCWP-575
See also platform implementation PRs:
Test plan
yarn testandyarn linton this branchproposeposts or edits a single sticky proposal comment and does not comment on PRs with no analytics changescreateopens a draft schema PR only after the author agreement comment on an open, same-repo PRproposeruns update the same bot branch when a schema PR is already openclosecloses the schema PR when the client PR closes unmerged, and leaves it open when mergedMade with Cursor