Skip to content

Commit

Permalink
remove prefix v for commit hash version (#10597)
Browse files Browse the repository at this point in the history
* addv ignore commit hash

some services might return version as a commit hash like aur.
it makes no sense to prefix v before the commit.

Fixes #10591

* add addv commit hash tests

add both full commit hash and short commit hash tests to addv.
expected result - no v prefix.
  • Loading branch information
jNullj authored Oct 12, 2024
1 parent e3808c1 commit f767fab
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions services/text-formatters.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,12 @@ function omitv(version) {
return version
}

const ignoredVersionPatterns = /^[^0-9]|[0-9]{4}-[0-9]{2}-[0-9]{2}/
const ignoredVersionPatterns =
/^[^0-9]|[0-9]{4}-[0-9]{2}-[0-9]{2}|^[a-f0-9]{7,40}$/

/**
* Add a starting v to the version unless it doesn't starts with a digit or is a date (yyyy-mm-dd)
* For example, addv("1.2.3") returns "v1.2.3", but addv("hello") or addv("2021-10-31"), returns "hello" and "2021-10-31" respectively.
* Add a starting v to the version unless it doesn't starts with a digit, is a date (yyyy-mm-dd), or is a commit hash.
* For example, addv("1.2.3") returns "v1.2.3", but addv("hello"), addv("2021-10-31"), addv("abcdef1"), returns "hello", "2021-10-31", and "abcdef1" respectively.
*
* @param {string} version - Version string
* @returns {string} Version string with the starting v
Expand Down
4 changes: 4 additions & 0 deletions services/text-formatters.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ describe('Text formatters', function () {
given('v0.6').expect('v0.6')
given('hello').expect('hello')
given('2017-05-05-Release-2.3.17').expect('2017-05-05-Release-2.3.17')
given('5aa272da7924fa76581fd5ea83b24cfbb3528b8a').expect(
'5aa272da7924fa76581fd5ea83b24cfbb3528b8a',
)
given('5aa272da79').expect('5aa272da79')
})

test(maybePluralize, () => {
Expand Down

0 comments on commit f767fab

Please sign in to comment.