Skip to content

Commit 7301acf

Browse files
authored
Merge pull request #1 from teambit/fix/component-ids-array-node24
fix: accept componentIds as an array; run on Node 24
2 parents 223af0e + e13ece3 commit 7301acf

6 files changed

Lines changed: 65 additions & 7 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# CI for the action itself: unit tests for the components, and a check that the
2+
# committed bundle (dist/index.js, which action.yml runs verbatim) is fresh and
3+
# loads under Node.
4+
name: ci
5+
on:
6+
pull_request:
7+
push:
8+
branches: [main]
9+
10+
permissions:
11+
contents: read
12+
13+
jobs:
14+
test:
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/checkout@v5
18+
- uses: actions/setup-node@v5
19+
with:
20+
node-version: 24
21+
- name: Install bit
22+
run: |
23+
npx --yes @teambit/bvm install 2.2.115
24+
echo "$HOME/bin" >> "$GITHUB_PATH"
25+
- name: Install dependencies
26+
run: bit install
27+
- name: Test
28+
run: bit test
29+
- name: Verify the committed bundle
30+
run: node scripts/verify-bundle.mjs

‎action.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ inputs:
1919
required: false
2020
default: bit-sync/main
2121
runs:
22-
using: node20
22+
using: node24
2323
# Committed esbuild bundle -- see scripts/bundle-action.mjs. Must be ESM
2424
# (the root package.json is `"type": "module"`); `npm run verify-bundle`
2525
# asserts it is both fresh and loadable.

‎dist/index.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ function scopesInComponentIds(componentIds) {
4545
function isLaneRelevantToScope(componentIds, repoScope) {
4646
if (!componentIds || !repoScope)
4747
return true;
48-
const scopes = scopesInComponentIds(componentIds);
48+
const scopes = scopesInComponentIds(Array.isArray(componentIds) ? componentIds.join(",") : String(componentIds));
4949
if (scopes.length === 0)
5050
return true;
5151
return scopes.includes(repoScope);

‎git-sync/git-sync/event-router/event-router.spec.ts‎

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,33 @@ describe('routeEvent', () => {
7272
});
7373
});
7474

75+
it('accepts componentIds as an array (API-created webhooks, hand-rolled dispatches)', () => {
76+
expect(
77+
routeEvent({
78+
...base,
79+
eventName: 'repository_dispatch',
80+
dispatchType: 'bit-export',
81+
repoScope: 'acme.cards',
82+
clientPayload: {
83+
laneId: 'acme.cards/cross-scope',
84+
componentIds: ['acme.shop/bar@2.0.0', 'acme.cards/foo@1.0.0'],
85+
},
86+
})
87+
).toEqual({ kind: 'run', args: ['sync', 'acme.cards/cross-scope'] });
88+
});
89+
90+
it('treats an empty componentIds array as absent (fails open)', () => {
91+
expect(
92+
routeEvent({
93+
...base,
94+
eventName: 'repository_dispatch',
95+
dispatchType: 'bit-export',
96+
repoScope: 'acme.cards',
97+
clientPayload: { laneId: '', componentIds: [] },
98+
})
99+
).toEqual({ kind: 'run', args: ['sync', '--main'] });
100+
});
101+
75102
it('fails open (routes) when componentIds is absent, even with repoScope set', () => {
76103
expect(
77104
routeEvent({

‎git-sync/git-sync/event-router/event-router.ts‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,10 @@ export type RouterInput = {
2828
* cross-scope-lane relevance filter (see `repoScope` below) to decide
2929
* whether this repo has any stake in a lane export before routing it.
3030
* Absent/empty is NOT a signal of anything — it just means the filter
31-
* can't run, so it fails open (see `isLaneRelevantToScope`).
31+
* can't run, so it fails open (see `isLaneRelevantToScope`). A webhook
32+
* created through the API, or a hand-rolled dispatch, may send an array.
3233
*/
33-
componentIds?: string;
34+
componentIds?: string | string[];
3435
};
3536
/** push: refs/heads/<branch>. */
3637
ref?: string;
@@ -179,9 +180,9 @@ function scopesInComponentIds(componentIds: string): string[] {
179180
* whose content isn't entirely inside `defaultScope`, so failing open here
180181
* only means the halt happens in `bit ci` instead of being pre-empted here.
181182
*/
182-
function isLaneRelevantToScope(componentIds: string | undefined, repoScope: string | undefined): boolean {
183+
function isLaneRelevantToScope(componentIds: string | string[] | undefined, repoScope: string | undefined): boolean {
183184
if (!componentIds || !repoScope) return true;
184-
const scopes = scopesInComponentIds(componentIds);
185+
const scopes = scopesInComponentIds(Array.isArray(componentIds) ? componentIds.join(',') : String(componentIds));
185186
if (scopes.length === 0) return true;
186187
return scopes.includes(repoScope);
187188
}

‎scripts/bundle-action.mjs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export const bundleOptions = {
2727
entryPoints: [join(repoRoot, 'git-sync/git-sync/action/run.ts')],
2828
bundle: true,
2929
platform: 'node',
30-
target: 'node20',
30+
target: 'node24',
3131
format: 'esm',
3232
absWorkingDir: repoRoot,
3333
};

0 commit comments

Comments
 (0)