Skip to content

Commit 4b2aa60

Browse files
feat: add draft-segment-schema-pr action (#294)
* feat: add draft-segment-schema-pr action 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> * Update Jest configuration coverage thresholds and enhance Segment schema draft action - Increased coverage thresholds for branches, functions, lines, and statements in jest.config.js. - Improved README.md to clarify the usage of the Segment schema draft CLI. - Modified the draft-segment-schema-pr action to ensure proper fetching of remote branches and handle analytics hits more accurately. - Updated various functions to correctly count and manage TypeScript file changes, including handling renamed files and ensuring unique event paths in the schema. - Added tests to validate new functionality and ensure existing behavior remains intact. * fix: format the draft Segment schema action README Prettier rejects the unaligned markdown table in CI. Co-authored-by: Cursor <cursoragent@cursor.com> * fix: list schema pulls with the schema app token The github-script client replaces Authorization, so schema reads need their own client. Co-authored-by: Cursor <cursoragent@cursor.com> * fix: use the github-script getOctokit global Declaring getOctokit again throws because github-script already injects it. Co-authored-by: Cursor <cursoragent@cursor.com> * fix: identify proposal comments by the workflow bot login Publish called GET /user, and the workflow token rejects that request. Co-authored-by: Cursor <cursoragent@cursor.com> * docs: record the schema create open and opt-out checks Callers re-read the client pull request under the write lock before minting the App token. Co-authored-by: Cursor <cursoragent@cursor.com> * fix: give colliding event names distinct schema filenames Names that share a kebab slug now get a stable suffixed YAML path so each event is written to its own file. Co-authored-by: Cursor <cursoragent@cursor.com> --------- Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent b1b556f commit 4b2aa60

41 files changed

Lines changed: 5823 additions & 13 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.eslintrc.js‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ module.exports = {
1717
extends: ['@metamask/eslint-config-nodejs'],
1818
},
1919

20+
{
21+
files: ['*.mjs'],
22+
parserOptions: {
23+
sourceType: 'module',
24+
ecmaVersion: 2022,
25+
},
26+
extends: ['@metamask/eslint-config-nodejs'],
27+
rules: {
28+
'import/extensions': 'off',
29+
},
30+
},
31+
2032
{
2133
files: ['*.test.ts', '*.test.js'],
2234
extends: ['@metamask/eslint-config-jest'],
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# Draft Segment schema PR
2+
3+
Composite action that detects analytics event and property changes on a Mobile or Extension pull request, posts one proposal comment, and opens one draft pull request on `Consensys/segment-schema` after the author agrees.
4+
5+
One client pull request maps to branch `metamaskbot/<platform>-pr-<N>`. The action is a helper.
6+
7+
The [CLI](../../../src/segment-schema-draft-pr/README.md) is what this action runs for generate and publish. Inputs live in `action.yml`.
8+
9+
## Modes
10+
11+
| Mode | Event | What it does |
12+
| --------- | -------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
13+
| `propose` | `pull_request` opened, synchronize, reopened, ready_for_review | Generates YAML and posts or edits one proposal comment. Pushes the bot branch when an open schema pull request already exists. |
14+
| `create` | `issue_comment` created | Pushes the bot branch and opens a draft schema pull request when the commenter is the pull request author, the client pull request is open, the head is in the same repository, and generate produced additive YAML. |
15+
| `close` | `pull_request` closed | When a schema pull request exists and the client pull request is unmerged, comments on the schema pull request and closes it. A merged client pull request leaves the schema draft open. Close leaves the bot branch in place. |
16+
17+
The agreement sentence is the first line of the author's comment, with optional trailing whitespace:
18+
19+
```
20+
I agree to open a draft Segment schema PR
21+
```
22+
23+
The label `no-schema-pr` opts that pull request out.
24+
25+
## Gate
26+
27+
A `github-script` step runs before github-tools is installed. It ends the job for a fork head, the opt-out label, a comment that is not the agreement sentence, `close` when no schema pull request exists, and a file list with no analytics signal and no sticky proposal to edit.
28+
29+
`propose` runs when the event is `pull_request`, the action is not `closed`, the pull request is ready for review, the author is not a Bot, the head repository is this repository, and the opt-out label is absent.
30+
31+
A pull request that changes more than 150 non-test TypeScript files skips YAML generation. The sticky comment tells the author to open the schema pull request. A rename counts as one file.
32+
33+
`propose` and `close` use a same-repository head. `create` runs after `did-user-agree-to-create-pr` and `is-cross-repo-pr`. That second job records `IS_CROSS_REPO_PR`, `CLIENT_PR_OPEN`, and `HAS_OPT_OUT_LABEL`. `create` queues when those are `false`, `true`, and `false`. Its first step reads the pull request again after the job holds `draft-segment-schema-write-<N>`, and mints the App token when that read still matches. Agreement sits outside the lock, so an unmerged close can finish first. The action gate repeats the open and opt-out checks before the schema write.
34+
35+
## Tokens
36+
37+
`github-token` reads the client pull request and posts comments on it. It defaults to `github.token`.
38+
39+
`segment-schema-token` checks out the schema repository, pushes the bot branch, and opens, updates, or closes the schema pull request. Callers mint it with `actions/create-github-app-token` for owner `Consensys` and repository `segment-schema`, from the `segment-schema` environment, and pass `steps.app-token.outputs.token`.
40+
41+
## Callers
42+
43+
Mobile and Extension each keep `.github/workflows/draft-segment-schema-pr.yml`. Mobile sets `platform: mobile`. Extension sets `platform: extension`.
44+
45+
Pin this action to a github-tools commit SHA. The `@v1` tag follows a github-tools release.
46+
47+
`issue_comment` runs the workflow file from the default branch. `pull_request` runs the workflow file from the merge commit.
48+
49+
`propose` uses concurrency group `draft-segment-schema-propose-<N>` and cancels an in-progress run. `create` and `close` share `draft-segment-schema-write-<N>` and keep the in-progress run, so a propose does not cancel a create between `git push` and `pulls.create`.

0 commit comments

Comments
 (0)