Skip to content

feat: add draft-segment-schema-pr action - #294

Draft
NicolasMassart wants to merge 3 commits into
mainfrom
feat/mcwp-575-schema-pr-workflow
Draft

NicolasMassart wants to merge 3 commits into
mainfrom
feat/mcwp-575-schema-pr-workflow

Conversation

@NicolasMassart

@NicolasMassart NicolasMassart commented Sep 14, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • Adds a reusable draft-segment-schema-pr composite action that reads Mobile/Extension analytics diffs through the GitHub API, comments one proposal, and opens a draft Consensys/segment-schema PR after the author comments I agree to open a draft Segment schema PR.
  • Client file list uses pulls.listFiles (three-dot PR comparison). Schema YAML is still committed and pushed with git. Helper, not a merge gate.
  • Consumer workflows stay in Mobile/Extension; pin a commit SHA until @v1 exists.

fixes MCWP-575

See also platform implementation PRs:

Test plan

  • yarn test and yarn lint on this branch
  • Confirm propose posts or edits a single sticky proposal comment and does not comment on PRs with no analytics changes
  • Confirm create opens a draft schema PR only after the author agreement comment on an open, same-repo PR
  • Confirm later propose runs update the same bot branch when a schema PR is already open
  • Confirm close closes the schema PR when the client PR closes unmerged, and leaves it open when merged

Made with Cursor

NicolasMassart and others added 2 commits September 14, 2026 18:46
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>
@socket-security

socket-security Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedyaml@​2.9.010010010090100

View full report

@socket-security

socket-security Bot commented Sep 14, 2026 •

Copy link
Copy Markdown

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:

  • yaml@2.9.0

View full report

@NicolasMassart

Copy link
Copy Markdown
Contributor Author

@SocketSecurity ignore npm/yaml@2.9.0

official parser; we only call parseDocument(text), no reviver/onAnchor.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 High severity · 9 Medium severity · 1 Low severity

Open (11)
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.

Comment on lines +52 to +56
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
Comment on lines +15 to +16
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}`,
Comment on lines +13 to +14
export const DIFF_PREFILTER =
/EVENT_NAME|MetaMetricsEventName|trackEvent|addProperties|createEventBuilder/u;
Comment on lines +77 to +79
const unresolved = [...head.events.values()].flatMap(
(event) => event.unresolved,
);
},
);

return comments.find((comment) => comment.body?.includes(PROPOSAL_MARKER));
'',
];

if (changesetHasWritableChanges(changeset)) {
Comment thread README.md
--head-sha <pr-head-sha>
```

`--phase publish --dry-run` prints the summary path and skips GitHub writes.

This branch has not been deployed

No deployments
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.

2 participants