Skip to content

Commit

Permalink
feat: allow parsing version from branch name with extra path (#22)
Browse files Browse the repository at this point in the history
* Allow parsing version from branch name with extra path

* chore: update binary

* test: add extractVersion test

---------

Co-authored-by: bang9 <gusrn1423@naver.com>
  • Loading branch information
hoon-sung and bang9 authored Jan 12, 2024
1 parent 429bc07 commit 5c6dd1b
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
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+)`)
}

0 comments on commit 5c6dd1b

Please sign in to comment.