Skip to content

Commit 93b854a

Browse files
authored
v7.7.1 (#2)
* v7.7.1 Update from 7.6.3 to 7.7.1 * Lint * v7.7.1
1 parent c4b627d commit 93b854a

10 files changed

+173
-54
lines changed

README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Options:
8585
-i --increment [<level>]
8686
Increment a version by the specified level. Level can
8787
be one of: major, minor, patch, premajor, preminor,
88-
prepatch, or prerelease. Default level is 'patch'.
88+
prepatch, prerelease, or release. Default level is 'patch'.
8989
Only one version may be specified.
9090
9191
--preid <identifier>
@@ -239,6 +239,13 @@ zcl_semver_cli=>main( 'semver 1.2.4-beta.0 -i prerelease' ).
239239
" 1.2.4-beta.1
240240
```
241241

242+
To get out of the prerelease phase, use the `release` option:
243+
244+
```abap
245+
zcl_semver_cli=>main( 'semver 1.2.4-beta.1 -i release' ).
246+
1.2.4
247+
```
248+
242249
#### Prerelease Identifier Base
243250

244251
The method `.inc` takes an optional parameter 'identifierBase' string
@@ -249,7 +256,7 @@ If you do not specify this parameter, it will default to zero-based.
249256
```abap
250257
zcl_semver_functions=>inc(
251258
version = '1.2.3'
252-
release = 'prerelease'
259+
release_type = 'prerelease'
253260
identifier = 'beta'
254261
identifier_base = '1' ).
255262
" '1.2.4-beta.1'
@@ -258,7 +265,7 @@ zcl_semver_functions=>inc(
258265
```abap
259266
zcl_semver_functions=>inc(
260267
version = '1.2.3'
261-
release = 'prerelease'
268+
release_type = 'prerelease'
262269
identifier = 'beta'
263270
identifier_base = '' ).
264271
" '1.2.4-beta'
@@ -425,17 +432,18 @@ Strict-mode Comparators and Ranges will be strict about the SemVer
425432
strings that they parse.
426433

427434
* `valid(v)`: Return the parsed version, or null if it's not valid.
428-
* `inc(v, release, options, identifier, identifierBase)`:
435+
* `inc(v, release_type, options, identifier, identifier_base)`:
429436
Return the version incremented by the release
430437
type (`major`, `premajor`, `minor`, `preminor`, `patch`,
431-
`prepatch`, or `prerelease`), or null if it's not valid
438+
`prepatch`, `prerelease`, or `release`), or null if it's not valid
432439
* `premajor` in one call will bump the version up to the next major
433440
version and down to a prerelease of that major version.
434441
`preminor`, and `prepatch` work the same way.
435442
* If called from a non-prerelease version, `prerelease` will work the
436443
same as `prepatch`. It increments the patch version and then makes a
437444
prerelease. If the input version is already a prerelease it simply
438445
increments it.
446+
* `release` will remove any prerelease part of the version.
439447
* `identifier` can be used to prefix `premajor`, `preminor`,
440448
`prepatch`, or `prerelease` version increments. `identifierBase`
441449
is the base to be used for the `prerelease` identifier.
@@ -487,7 +495,7 @@ strings that they parse.
487495

488496
### Ranges
489497

490-
* `validRange(range)`: Return the valid range or null if it's not valid
498+
* `validRange(range)`: Return the valid range or null if it's not valid.
491499
* `satisfies(version, range)`: Return true if the version satisfies the
492500
range.
493501
* `maxSatisfying(versions, range)`: Return the highest version in the list

src/classes/zcl_semver.clas.abap

Lines changed: 59 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ CLASS zcl_semver DEFINITION
7979

8080
METHODS inc
8181
IMPORTING
82-
release TYPE string
82+
release_type TYPE string
8383
identifier TYPE string OPTIONAL
8484
identifier_base TYPE string OPTIONAL
8585
RETURNING
@@ -90,10 +90,20 @@ CLASS zcl_semver DEFINITION
9090
PROTECTED SECTION.
9191
PRIVATE SECTION.
9292

93+
CONSTANTS false TYPE string VALUE 'false'.
94+
9395
DATA:
9496
raw TYPE string,
9597
options TYPE zif_semver_options=>ty_options.
9698

99+
METHODS _inc_check
100+
IMPORTING
101+
release_type TYPE string
102+
identifier TYPE string OPTIONAL
103+
identifier_base TYPE string OPTIONAL
104+
RAISING
105+
zcx_error.
106+
97107
ENDCLASS.
98108

99109

@@ -316,36 +326,44 @@ CLASS zcl_semver IMPLEMENTATION.
316326

317327
METHOD inc.
318328

319-
CONSTANTS false TYPE string VALUE 'false'.
320-
321329
DATA prerelease_tab LIKE prerelease.
322330

323-
CASE release.
331+
_inc_check(
332+
release_type = release_type
333+
identifier = identifier
334+
identifier_base = identifier_base ).
335+
336+
CASE release_type.
324337
WHEN 'premajor'.
325338
CLEAR prerelease.
326339
patch = 0.
327340
minor = 0.
328341
major = major + 1.
329-
inc( release = 'pre' identifier = identifier identifier_base = identifier_base ).
342+
inc( release_type = 'pre' identifier = identifier identifier_base = identifier_base ).
330343
WHEN 'preminor'.
331344
CLEAR prerelease.
332345
patch = 0.
333346
minor = minor + 1.
334-
inc( release = 'pre' identifier = identifier identifier_base = identifier_base ).
347+
inc( release_type = 'pre' identifier = identifier identifier_base = identifier_base ).
335348
WHEN 'prepatch'.
336349
" If this is already a prerelease, it will bump to the next version
337350
" drop any prereleases that might already exist, since they are not
338351
" relevant at this point.
339352
CLEAR prerelease.
340-
inc( release = 'patch' identifier = identifier identifier_base = identifier_base ).
341-
inc( release = 'pre' identifier = identifier identifier_base = identifier_base ).
353+
inc( release_type = 'patch' identifier = identifier identifier_base = identifier_base ).
354+
inc( release_type = 'pre' identifier = identifier identifier_base = identifier_base ).
342355
WHEN 'prerelease'.
343356
" If the input is a non-prerelease version, this acts the same as
344357
" prepatch.
345358
IF prerelease IS INITIAL.
346-
inc( release = 'patch' identifier = identifier identifier_base = identifier_base ).
359+
inc( release_type = 'patch' identifier = identifier identifier_base = identifier_base ).
347360
ENDIF.
348-
inc( release = 'pre' identifier = identifier identifier_base = identifier_base ).
361+
inc( release_type = 'pre' identifier = identifier identifier_base = identifier_base ).
362+
WHEN 'release'.
363+
IF prerelease IS INITIAL.
364+
zcx_error=>raise( |Version { raw } is not a prerelease| ).
365+
ENDIF.
366+
CLEAR prerelease.
349367
WHEN 'major'.
350368
" If this is a pre-major version, bump up to the same major version.
351369
" Otherwise increment major.
@@ -385,10 +403,6 @@ CLASS zcl_semver IMPLEMENTATION.
385403
base = COND #( WHEN zcl_semver_utils=>is_numeric( identifier_base ) THEN `1` ELSE `0` ).
386404
ENDIF.
387405

388-
IF identifier IS INITIAL AND identifier_base = false.
389-
zcx_error=>raise( 'Invalid increment argument: identifier is empty' ).
390-
ENDIF.
391-
392406
IF prerelease IS INITIAL.
393407
prerelease = VALUE #( ( base ) ).
394408
ELSE.
@@ -431,7 +445,7 @@ CLASS zcl_semver IMPLEMENTATION.
431445
" Used by zcl_semver_ranges->min_version
432446
INSERT identifier_base INTO TABLE prerelease.
433447
WHEN OTHERS.
434-
zcx_error=>raise( |Invalid increment argument { release }| ).
448+
zcx_error=>raise( |Invalid release type argument { release_type }| ).
435449
ENDCASE.
436450

437451
format( ).
@@ -450,4 +464,34 @@ CLASS zcl_semver IMPLEMENTATION.
450464
METHOD to_string.
451465
result = version.
452466
ENDMETHOD.
467+
468+
469+
METHOD _inc_check.
470+
471+
IF release_type CP 'pre*'.
472+
IF identifier IS INITIAL AND identifier_base = false.
473+
zcx_error=>raise( 'Invalid increment argument: identifier is empty' ).
474+
ENDIF.
475+
476+
" Avoid an invalid semver results
477+
IF identifier IS NOT INITIAL.
478+
DATA(regex) = COND #(
479+
WHEN options-loose = abap_true
480+
THEN |^{ zcl_semver_re=>token-prereleaseloose-safe_src }$|
481+
ELSE |^{ zcl_semver_re=>token-prerelease-safe_src }$| ).
482+
483+
TRY.
484+
DATA(r) = NEW cl_abap_regex( pattern = regex ).
485+
DATA(m) = r->create_matcher( text = |-{ identifier }| ).
486+
487+
IF NOT m->match( ) OR m->get_submatch( 1 ) <> identifier.
488+
zcx_error=>raise( |Invalid identifier: { identifier }| ).
489+
ENDIF.
490+
CATCH cx_sy_matcher.
491+
zcx_error=>raise( |Error evaluating regex for { identifier }| ).
492+
ENDTRY.
493+
ENDIF.
494+
ENDIF.
495+
496+
ENDMETHOD.
453497
ENDCLASS.

src/classes/zcl_semver.clas.testclasses.abap

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ CLASS ltcl_semver DEFINITION FOR TESTING RISK LEVEL HARMLESS
1111
options FOR TESTING RAISING zcx_error,
1212
really_big FOR TESTING RAISING zcx_error,
1313
incrementing FOR TESTING RAISING zcx_error,
14+
invalid_increments FOR TESTING RAISING zcx_error,
15+
increment_side_effects FOR TESTING RAISING zcx_error,
1416
compare_main_vs_pre FOR TESTING RAISING zcx_error,
1517
compare_build FOR TESTING RAISING zcx_error.
1618

@@ -122,7 +124,7 @@ CLASS ltcl_semver IMPLEMENTATION.
122124
DATA(s) = zcl_semver=>create( version = increments-version loose = increments-loose ).
123125

124126
s->inc(
125-
release = increments-release
127+
release_type = increments-release
126128
identifier = increments-identifier
127129
identifier_base = increments-identifier_base ).
128130
cl_abap_unit_assert=>fail( msg = msg ).
@@ -133,7 +135,7 @@ CLASS ltcl_semver IMPLEMENTATION.
133135
s = zcl_semver=>create( version = increments-version loose = increments-loose ).
134136

135137
DATA(inc) = s->inc(
136-
release = increments-release
138+
release_type = increments-release
137139
identifier = increments-identifier
138140
identifier_base = increments-identifier_base ).
139141

@@ -158,6 +160,63 @@ CLASS ltcl_semver IMPLEMENTATION.
158160

159161
ENDMETHOD.
160162

163+
METHOD invalid_increments.
164+
165+
TRY.
166+
zcl_semver=>create( '1.2.3' )->inc(
167+
release_type = 'prerelease'
168+
identifier = ''
169+
identifier_base = 'false' ).
170+
cl_abap_unit_assert=>fail( ).
171+
CATCH zcx_error INTO DATA(error).
172+
cl_abap_unit_assert=>assert_equals(
173+
act = error->get_text( )
174+
exp = 'Invalid increment argument: identifier is empty' ).
175+
ENDTRY.
176+
177+
TRY.
178+
zcl_semver=>create( '1.2.3-dev' )->inc(
179+
release_type = 'prerelease'
180+
identifier = 'dev'
181+
identifier_base = 'false' ).
182+
cl_abap_unit_assert=>fail( ).
183+
CATCH zcx_error INTO error.
184+
cl_abap_unit_assert=>assert_equals(
185+
act = error->get_text( )
186+
exp = 'Invalid increment argument: identifier already exists' ).
187+
ENDTRY.
188+
189+
TRY.
190+
zcl_semver=>create( '1.2.3' )->inc(
191+
release_type = 'prerelease'
192+
identifier = 'invalid/preid' ).
193+
cl_abap_unit_assert=>fail( ).
194+
CATCH zcx_error INTO error.
195+
cl_abap_unit_assert=>assert_equals(
196+
act = error->get_text( )
197+
exp = 'Invalid identifier: invalid/preid' ).
198+
ENDTRY.
199+
200+
ENDMETHOD.
201+
202+
METHOD increment_side_effects.
203+
204+
DATA(v) = zcl_semver=>create( '1.0.0' ).
205+
206+
TRY.
207+
v->inc(
208+
release_type = 'prerelease'
209+
identifier = 'hot/mess' ).
210+
CATCH zcx_error ##NO_HANDLER.
211+
" ignore but check that the version has not changed
212+
ENDTRY.
213+
214+
cl_abap_unit_assert=>assert_equals(
215+
act = v->to_string( )
216+
exp = '1.0.0' ).
217+
218+
ENDMETHOD.
219+
161220
METHOD compare_main_vs_pre.
162221

163222
DATA(s) = zcl_semver=>create( '1.2.3' ).

src/cli/zcl_semver_cli.clas.abap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ CLASS zcl_semver_cli IMPLEMENTATION.
117117
WHEN '-i' OR '--inc' OR '--increment'.
118118
val = VALUE #( argv[ idx + 1 ] OPTIONAL ).
119119
CASE val.
120-
WHEN 'major' OR 'minor' OR 'patch' OR 'prerelease' OR 'premajor' OR 'preminor' OR 'prepatch'.
120+
WHEN 'major' OR 'minor' OR 'patch' OR 'prerelease' OR 'premajor' OR 'preminor' OR 'prepatch' OR 'release'.
121121
idx = idx + 1.
122122
inc = VALUE #( argv[ idx ] OPTIONAL ).
123123
WHEN OTHERS.
@@ -175,7 +175,7 @@ CLASS zcl_semver_cli IMPLEMENTATION.
175175
( `-i --increment [<level>]` )
176176
( ` Increment a version by the specified level. Level can` )
177177
( ` be one of: major, minor, patch, premajor, preminor,` )
178-
( ` prepatch, or prerelease. Default level is 'patch'.` )
178+
( ` prepatch, prerelease, or release. Default level is 'patch'.` )
179179
( ` Only one version may be specified.` )
180180
( `` )
181181
( `--preid <identifier>` )
@@ -228,7 +228,7 @@ CLASS zcl_semver_cli IMPLEMENTATION.
228228
LOOP AT versions ASSIGNING <version>.
229229
DATA(semver) = zcl_semver_functions=>inc(
230230
version = <version>
231-
release = inc
231+
release_type = inc
232232
identifier = identifier
233233
identifier_base = identifier_base
234234
loose = loose

src/functions/zcl_semver_functions.clas.abap

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ CLASS zcl_semver_functions DEFINITION
121121
CLASS-METHODS inc
122122
IMPORTING
123123
version TYPE any
124-
release TYPE string
124+
release_type TYPE string
125125
identifier TYPE string OPTIONAL
126126
identifier_base TYPE string OPTIONAL
127127
loose TYPE abap_bool DEFAULT abap_false
@@ -513,23 +513,15 @@ CLASS zcl_semver_functions IMPLEMENTATION.
513513
RETURN.
514514
ENDIF.
515515

516-
" Otherwise it can be determined by checking the high version
517-
518-
IF high_version->patch IS NOT INITIAL.
519-
" anything higher than a patch bump would result in the wrong version
516+
" If the main part has no difference
517+
IF low_version->compare_main( high_version ) = 0.
518+
IF low_version->minor IS NOT INITIAL AND low_version->patch IS INITIAL.
519+
result = 'minor'.
520+
RETURN.
521+
ENDIF.
520522
result = 'patch'.
521523
RETURN.
522524
ENDIF.
523-
524-
IF high_version->minor IS NOT INITIAL.
525-
" anything higher than a minor bump would result in the wrong version
526-
result = 'minor'.
527-
RETURN.
528-
ENDIF.
529-
530-
" bumping major/minor/patch all have same result
531-
result = 'major'.
532-
RETURN.
533525
ENDIF.
534526

535527
" add the `pre` prefix if we are going to a prerelease version
@@ -616,7 +608,7 @@ CLASS zcl_semver_functions IMPLEMENTATION.
616608

617609
CHECK result IS BOUND.
618610

619-
result->inc( release = release identifier = identifier identifier_base = identifier_base ).
611+
result->inc( release_type = release_type identifier = identifier identifier_base = identifier_base ).
620612
CATCH zcx_error.
621613
CLEAR result.
622614
ENDTRY.

0 commit comments

Comments
 (0)