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

feat: allow parsing version from branch name with extra path #22

Merged
merged 3 commits into from
Jan 12, 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
24 changes: 24 additions & 0 deletions __tests__/utils.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {describe, test, expect} from '@jest/globals'
import {extractVersion} from '../src/utils'

describe('extractVersion', () => {
test('should return the version if the branch convention is valid', () => {
expect(extractVersion('hotfix/1.2.3')).toBe('1.2.3')
expect(extractVersion('hotfix/v1.2.3')).toBe('1.2.3')
expect(extractVersion('hotfix/ktx/v1.2.3')).toBe('1.2.3')

expect(extractVersion('release/1.2.3')).toBe('1.2.3')
expect(extractVersion('release/v1.2.3')).toBe('1.2.3')
expect(extractVersion('release/ktx/v1.2.3')).toBe('1.2.3')
})

test('Should return an empty string if the branch convention is invalid', () => {
expect(extractVersion('v1.2.3')).toBe('')
expect(extractVersion('1.2.3')).toBe('')
expect(extractVersion('unknown/1.2.3')).toBe('')
expect(extractVersion('hotfixx/1.2.3')).toBe('')
expect(extractVersion('hotfixx/v1.2.3')).toBe('')
expect(extractVersion('releases/1.2.3')).toBe('')
expect(extractVersion('releases/v1.2.3')).toBe('')
})
})
6 changes: 4 additions & 2 deletions dist/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/index.js.map

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export function extractVersion(branch: string): string {
BRANCH_HOTFIX_PREFIX
])
const match = branch.match(versionRegex)
if (match) return match[2]
if (match) return match[match.length - 1]
return ''
}

Expand Down Expand Up @@ -79,5 +79,7 @@ function capitalize(str: string): string {

function getVersionRegex(inputs: string[]): RegExp {
const joinedInputs = inputs.join('|')
return new RegExp(`(${joinedInputs})\\/v?(\\d+\\.\\d+\\.\\d+)`)
// release/0.0.0
// release/ktx/0.0.0
return new RegExp(`(${joinedInputs})\\/\\w*\\/*v?(\\d+\\.\\d+\\.\\d+)`)
}