Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: prepare release #6

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions packages/filter-by-workspace-path/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ import * as path from 'path'
function shouldOmitCommit(currentDir: string, currentWorkspace: string, commit: IExtendedCommit, logger: ILogger): boolean {
// auto adds the current path to the file paths reported from git, so we need to undo this
const fixedFiles = commit.files.map((file) => path.relative(currentDir, file))
const wsDir = path.join(currentWorkspace, path.sep)

const atLeastOneFileInCurrentDir = fixedFiles.find((file) => file.startsWith(currentWorkspace))
const atLeastOneFileInCurrentDir = fixedFiles.find((file) => file.startsWith(wsDir))
if (!atLeastOneFileInCurrentDir) {
logger.verbose.log(`All files are outside the current workspace directory ('${currentWorkspace}'). Omitting commit '${commit.hash}'.`)
logger.verbose.log(`All files are outside the current workspace directory ('${wsDir}'). Omitting commit '${commit.hash}'.`)
return true
} else {
if (commit.labels?.includes('skip-release') || commit.subject?.includes('[skip ci]')) {
logger.verbose.log('Skipping commit because it is marked as skip-release of [skip-ci]:', commit.hash, commit.labels, commit.subject)
return true
}

logger.verbose.log(`At least one file is in the current workspace ('${currentWorkspace}'). Including commit '${commit.hash}'.`)
logger.verbose.log(`At least one file is in the current workspace ('${wsDir}'). Including commit '${commit.hash}'.`)
return false
}
}
Expand Down
18 changes: 12 additions & 6 deletions packages/filter-by-workspace-path/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@ const setup = () => {
}

describe('Omit Commits Plugin', () => {
test('should not filter the commit single file', async () => {
it('should not filter the commit single file', async () => {
const hooks = setup()
const commit = makeCommitFromMsg('foo', { files: [path.resolve('.', 'packages/filter-by-workspace-path/src/index.ts')] })
expect(await hooks.omitCommit.promise(commit)).toBeUndefined()
})

test('should filter the commit single file', async () => {
it('should filter the commit single file', async () => {
const hooks = setup()
const commit = makeCommitFromMsg('foo', { files: ['/outside'] })
expect(await hooks.omitCommit.promise(commit)).toBe(true)
})

test('should not filter the commit multi file', async () => {
it('should not filter the commit multi file', async () => {
const hooks = setup()
const commit = makeCommitFromMsg('foo', { files: [path.resolve('.', 'packages/filter-by-workspace-path/src/index.ts'), '/outside'] })
expect(await hooks.omitCommit.promise(commit)).toBeUndefined()
})

test('should filter the commit single file', async () => {
it('should filter the commit single file', async () => {
const hooks = setup()
const commit = makeCommitFromMsg('foo', { files: ['/outside', '/anotheroutsider'] })
expect(await hooks.omitCommit.promise(commit)).toBe(true)
})

test('should skip commit labeled as skip-release', async () => {
it('should skip commit labeled as skip-release', async () => {
const hooks = setup()
const commit = makeCommitFromMsg('foo', {
labels: ['skip-release'],
Expand All @@ -57,11 +57,17 @@ describe('Omit Commits Plugin', () => {
expect(await hooks.omitCommit.promise(commit)).toBe(true)
})

test('should skip commit marked as skip-ci', async () => {
it('should skip commit marked as skip-ci', async () => {
const hooks = setup()
const commit = makeCommitFromMsg('foo [skip ci]', {
files: [path.resolve('.', 'packages/filter-by-workspace-path/src/index.ts')],
})
expect(await hooks.omitCommit.promise(commit)).toBe(true)
})

it('should skip commit in a sub-directory with the same prefix', async () => {
const hooks = setup()
const commit = makeCommitFromMsg('foo', { files: [path.resolve('.', 'packages/filter-by-workspace-path-sub-dir/src/index.ts')] })
expect(await hooks.omitCommit.promise(commit)).toBe(true)
})
})