Skip to content

Commit

Permalink
Merge pull request #6 from restfulhead/main
Browse files Browse the repository at this point in the history
chore: prepare release
  • Loading branch information
restfulhead authored Feb 16, 2024
2 parents 819f228 + cd02727 commit 768d057
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
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)
})
})

0 comments on commit 768d057

Please sign in to comment.