Skip to content

Commit

Permalink
feat(version-dispatch): support scoped packages (#51)
Browse files Browse the repository at this point in the history
* feat(version-dispatch): support scoped packages

* build: update dist

* chore: linting
  • Loading branch information
sparten11740 authored Jul 8, 2024
1 parent d71ceb4 commit 18ca1c8
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 10 deletions.
5 changes: 2 additions & 3 deletions dist/version-dispatch/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/version-dispatch/index.js.map

Large diffs are not rendered by default.

37 changes: 36 additions & 1 deletion src/version-dispatch.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,42 @@ describe('versionDispatch', () => {
inputs: {
assignee: 'brucewayne',
'version-strategy': 'conventional-commits',
packages: 'libraries/atoms,modules/blockchain-metadata,modules/balances',
packages: '@exodus/atoms,@exodus/blockchain-metadata,@exodus/balances',
},
})
})

it('should invoke version workflow with packages affected by PR when using scoped labels', async () => {
github.context.payload = {
pull_request: {
title: 'feat: added a lot of new features',
number: 123,
merged: true,
user: {
login: 'brucewayne',
},
base: {
ref,
},
labels: [
{ name: '@exodus/blockchain-metadata' },
{ name: '@exodus/balances' },
{ name: '@exodus/atoms' },
{ name: 'refactor' },
],
},
}

await versionDispatch({ filesystem: fs as never })

expect(client.rest.actions.createWorkflowDispatch).toHaveBeenCalledWith({
...repo,
ref,
workflow_id: workflowId,
inputs: {
assignee: 'brucewayne',
'version-strategy': 'conventional-commits',
packages: '@exodus/atoms,@exodus/blockchain-metadata,@exodus/balances',
},
})
})
Expand Down
12 changes: 7 additions & 5 deletions src/version-dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import * as github from '@actions/github'
import { VersionDispatchInput as Input } from './constants'
import { Filesystem } from './utils/types'
import * as fs from 'fs'
import { getPackagePaths } from '@exodus/lerna-utils'
import * as path from 'path'
import { getPathsByPackageNames } from '@exodus/lerna-utils'
import { VersionStrategy } from './version/strategy'
import { parseMessage } from './utils/conventional-commits'

Expand Down Expand Up @@ -57,9 +56,12 @@ export async function versionDispatch({ filesystem = fs }: Params = {}) {
return
}

const packagePaths = await getPackagePaths({ filesystem })
const affected = packagePaths.filter((it) =>
pr.labels.some((label: { name: string }) => label.name === path.basename(it))
const byPackageName = await getPathsByPackageNames({ filesystem })

const affected = Object.keys(byPackageName).filter((name) =>
pr.labels.some(
(label: { name: string }) => label.name === name || label.name === name.split('/').pop()
)
)

if (affected.length === 0) {
Expand Down

0 comments on commit 18ca1c8

Please sign in to comment.