Skip to content

Commit 4bcb695

Browse files
authored
Add user model (#8)
1 parent af9f685 commit 4bcb695

File tree

2 files changed

+135
-0
lines changed

2 files changed

+135
-0
lines changed
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
# Generated by Array CLI - https://github.com/posthog/array
2+
# Blocks stacked PRs until their downstack dependencies are merged
3+
# Only runs for PRs managed by Array (detected via stack comment marker)
4+
5+
name: Stack Check
6+
7+
on:
8+
pull_request:
9+
types: [opened, synchronize, reopened, edited]
10+
pull_request_target:
11+
types: [closed]
12+
13+
permissions:
14+
contents: read
15+
16+
jobs:
17+
check:
18+
runs-on: ubuntu-latest
19+
if: github.event_name == 'pull_request'
20+
permissions:
21+
pull-requests: read
22+
issues: read
23+
steps:
24+
- name: Check stack dependencies
25+
uses: actions/github-script@v7
26+
with:
27+
script: |
28+
const pr = context.payload.pull_request;
29+
30+
// Check if this is an Array-managed PR by looking for stack comment
31+
const { data: comments } = await github.rest.issues.listComments({
32+
owner: context.repo.owner,
33+
repo: context.repo.repo,
34+
issue_number: pr.number
35+
});
36+
37+
const isArrayPR = comments.some(c =>
38+
c.body.includes('<!-- array-stack-comment -->')
39+
);
40+
41+
if (!isArrayPR) {
42+
console.log('Not an Array PR, skipping');
43+
return;
44+
}
45+
46+
const baseBranch = pr.base.ref;
47+
const trunk = ['main', 'master', 'develop'];
48+
49+
if (trunk.includes(baseBranch)) {
50+
console.log('Base is trunk, no dependencies');
51+
return;
52+
}
53+
54+
async function getBlockers(base, visited = new Set()) {
55+
if (trunk.includes(base) || visited.has(base)) {
56+
return [];
57+
}
58+
visited.add(base);
59+
60+
const { data: prs } = await github.rest.pulls.list({
61+
owner: context.repo.owner,
62+
repo: context.repo.repo,
63+
state: 'open',
64+
head: `${context.repo.owner}:${base}`
65+
});
66+
67+
if (prs.length === 0) {
68+
return [];
69+
}
70+
71+
const blocker = prs[0];
72+
const upstream = await getBlockers(blocker.base.ref, visited);
73+
return [{ number: blocker.number, title: blocker.title }, ...upstream];
74+
}
75+
76+
const blockers = await getBlockers(baseBranch);
77+
78+
if (blockers.length > 0) {
79+
const list = blockers.map(b => `#${b.number} (${b.title})`).join('\n - ');
80+
core.setFailed(`Blocked by:\n - ${list}\n\nMerge these PRs first (bottom to top).`);
81+
} else {
82+
console.log('All dependencies merged, ready to merge');
83+
}
84+
85+
recheck-dependents:
86+
runs-on: ubuntu-latest
87+
if: >-
88+
github.event_name == 'pull_request_target' &&
89+
github.event.action == 'closed' &&
90+
github.event.pull_request.merged == true
91+
permissions:
92+
pull-requests: write
93+
issues: read
94+
steps:
95+
- name: Trigger recheck of dependent PRs
96+
uses: actions/github-script@v7
97+
with:
98+
script: |
99+
const pr = context.payload.pull_request;
100+
101+
// Check if this is an Array-managed PR
102+
const { data: comments } = await github.rest.issues.listComments({
103+
owner: context.repo.owner,
104+
repo: context.repo.repo,
105+
issue_number: pr.number
106+
});
107+
108+
const isArrayPR = comments.some(c =>
109+
c.body.includes('<!-- array-stack-comment -->')
110+
);
111+
112+
if (!isArrayPR) {
113+
console.log('Not an Array PR, skipping');
114+
return;
115+
}
116+
117+
const mergedBranch = pr.head.ref;
118+
119+
const { data: dependentPRs } = await github.rest.pulls.list({
120+
owner: context.repo.owner,
121+
repo: context.repo.repo,
122+
base: mergedBranch,
123+
state: 'open'
124+
});
125+
126+
for (const dependentPR of dependentPRs) {
127+
console.log(`Re-checking PR #${dependentPR.number}`);
128+
await github.rest.pulls.update({
129+
owner: context.repo.owner,
130+
repo: context.repo.repo,
131+
pull_number: dependentPR.number,
132+
base: 'main'
133+
});
134+
}

user_model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
user model

0 commit comments

Comments
 (0)