mirror of
https://github.com/abapGit/abapGit.git
synced 2025-04-30 20:03:20 +08:00
Issue 3042: Error author regex (#3070)
* Create pull.yml * Update zcl_abapgit_git_transport.clas.abap * Update zcl_abapgit_git_transport.clas.abap * Update pull.yml * Delete pull.yml * Tags: Error author regex > Regex couldn't match with string "pull[bot] <39814207+pull[bot]@users.noreply.github.com> 1573216988 +0000" because "[]" weren't allowed * abapLint * Added unit test for author_regex #3042 * Any character in author name and Unit Tests #3042 #3069 * Unit Tests and utils method for author regex #3042 #3069 > Unit Tests for author_regex (zif_abapgit_definitions) > New utils method for regex check as utils method in zcl_abapgit_utils > Regex for author expects now at least one character for the author name ('^(.+)'...) > Use zif_abapgit_definitions%3D>ty_commit_tt instead of local type of the same type in class zcl_abapgit_branch_overview * Changed utils method/tests and moved unit tests #3042 - Error author regex #3069 - Add unit tests > Renamed is_author to extract_author_data and moved related source code from branch_overview to utils class > Changed related unit tests to handle exception or not > Moved unit tests to local class of zcl_abapgit_utils * abapLint * abapLint * abapLint * abapLint * exclude 7bit test for testclass
This commit is contained in:
parent
191916e94a
commit
064e006c88
|
@ -61,7 +61,10 @@
|
|||
"check_text_elements": true,
|
||||
"type_begin_single_include": true,
|
||||
"types_naming": false,
|
||||
"7bit_ascii": {},
|
||||
"7bit_ascii": {
|
||||
"enabled": true,
|
||||
"exclude": ["zcl_abapgit_utils.clas.testclasses.abap"]
|
||||
},
|
||||
"abapdoc": {
|
||||
"enabled": false,
|
||||
"checkLocal": false
|
||||
|
|
|
@ -10,13 +10,22 @@ CLASS zcl_abapgit_utils DEFINITION
|
|||
!iv_data TYPE xstring
|
||||
RETURNING
|
||||
VALUE(rv_yes) TYPE abap_bool .
|
||||
CLASS-METHODS extract_author_data
|
||||
IMPORTING
|
||||
!iv_author TYPE string
|
||||
EXPORTING
|
||||
!ev_author TYPE zif_abapgit_definitions=>ty_commit-author
|
||||
!ev_email TYPE zif_abapgit_definitions=>ty_commit-email
|
||||
!ev_time TYPE zif_abapgit_definitions=>ty_commit-time
|
||||
RAISING
|
||||
zcx_abapgit_exception .
|
||||
PROTECTED SECTION.
|
||||
PRIVATE SECTION.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS ZCL_ABAPGIT_UTILS IMPLEMENTATION.
|
||||
CLASS zcl_abapgit_utils IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD is_binary.
|
||||
|
@ -47,4 +56,20 @@ CLASS ZCL_ABAPGIT_UTILS IMPLEMENTATION.
|
|||
ENDDO.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD extract_author_data.
|
||||
|
||||
" unix time stamps are in same time zone, so ignore the zone
|
||||
FIND REGEX zif_abapgit_definitions=>c_author_regex IN iv_author
|
||||
SUBMATCHES
|
||||
ev_author
|
||||
ev_email
|
||||
ev_time ##NO_TEXT.
|
||||
|
||||
IF sy-subrc <> 0.
|
||||
zcx_abapgit_exception=>raise( |Error author regex value='{ iv_author }'| ).
|
||||
ENDIF.
|
||||
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
|
|
|
@ -4,22 +4,76 @@ CLASS ltcl_utils_test DEFINITION FINAL
|
|||
RISK LEVEL HARMLESS.
|
||||
|
||||
PRIVATE SECTION.
|
||||
|
||||
METHODS is_binary FOR TESTING.
|
||||
METHODS extract_author_data FOR TESTING.
|
||||
|
||||
ENDCLASS.
|
||||
|
||||
CLASS ltcl_utils_test IMPLEMENTATION.
|
||||
|
||||
METHOD is_binary.
|
||||
METHOD extract_author_data.
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = zcl_abapgit_utils=>is_binary( '616263' ) " abc
|
||||
exp = abap_false ).
|
||||
TRY.
|
||||
zcl_abapgit_utils=>extract_author_data(
|
||||
'Volker Jägle äÖüß <github@beimir.net> 1573216988 +0000' ).
|
||||
CATCH zcx_abapgit_exception.
|
||||
cl_abap_unit_assert=>fail( |Language-related special characters in author name are allowed.| ).
|
||||
ENDTRY.
|
||||
|
||||
cl_abap_unit_assert=>assert_equals(
|
||||
act = zcl_abapgit_utils=>is_binary( '010203' )
|
||||
exp = abap_true ).
|
||||
TRY.
|
||||
zcl_abapgit_utils=>extract_author_data(
|
||||
'pull[bot&%#$] <39814207+pull[bot]@users.noreply.github.com> 1573216988 +0000' ).
|
||||
CATCH zcx_abapgit_exception.
|
||||
cl_abap_unit_assert=>fail( |Special characters in author name are allowed.| ).
|
||||
ENDTRY.
|
||||
|
||||
TRY.
|
||||
zcl_abapgit_utils=>extract_author_data(
|
||||
'pull[bot] <39814207+pull[bot]@users.noreply.github.com> 1573216988 +00001' ).
|
||||
cl_abap_unit_assert=>fail( |+00001 shouldn't be valid cause it's too long.| ).
|
||||
CATCH zcx_abapgit_exception.
|
||||
ENDTRY.
|
||||
|
||||
TRY.
|
||||
zcl_abapgit_utils=>extract_author_data(
|
||||
'pull[bot] <39814207+pull[bot]@users.noreply.github.com> 15732169881 +0000' ).
|
||||
cl_abap_unit_assert=>fail( |Value shouldn't be valid cause time is invalid.| ).
|
||||
CATCH zcx_abapgit_exception.
|
||||
ENDTRY.
|
||||
|
||||
TRY.
|
||||
zcl_abapgit_utils=>extract_author_data(
|
||||
'<39814207+pull[bot]@users.noreply.github.com> 1573216988 +0000' ).
|
||||
cl_abap_unit_assert=>fail( |Value shouldn't be valid cause no author name was supplied.| ).
|
||||
CATCH zcx_abapgit_exception.
|
||||
ENDTRY.
|
||||
|
||||
TRY.
|
||||
zcl_abapgit_utils=>extract_author_data(
|
||||
'pull[bot] 1573216988 +0000' ).
|
||||
cl_abap_unit_assert=>fail( |Value shouldn't be valid cause no email was supplied.| ).
|
||||
CATCH zcx_abapgit_exception.
|
||||
ENDTRY.
|
||||
|
||||
TRY.
|
||||
zcl_abapgit_utils=>extract_author_data(
|
||||
'pull[bot] <39814207+pull[bot]@users.noreply.github.com> +0000' ).
|
||||
cl_abap_unit_assert=>fail( |Value shouldn't be valid cause no time was supplied.| ).
|
||||
CATCH zcx_abapgit_exception.
|
||||
ENDTRY.
|
||||
|
||||
TRY.
|
||||
zcl_abapgit_utils=>extract_author_data(
|
||||
'pull[bot] <39814207+pull[bot]@users.noreply.github.com> 1573216988' ).
|
||||
cl_abap_unit_assert=>fail( |Value shouldn't be valid cause +0000 wasn't supplied.| ).
|
||||
CATCH zcx_abapgit_exception.
|
||||
ENDTRY.
|
||||
|
||||
TRY.
|
||||
zcl_abapgit_utils=>extract_author_data(
|
||||
'<pull[bot]()> <39814207+pull[bot]@users.noreply.github.com> 1573216988 +0000' ).
|
||||
CATCH zcx_abapgit_exception.
|
||||
cl_abap_unit_assert=>fail( |Value should be valid though brackets are in author name.| ).
|
||||
ENDTRY.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
|
|
@ -7,7 +7,6 @@ CLASS zcl_abapgit_branch_overview DEFINITION
|
|||
PUBLIC SECTION.
|
||||
|
||||
INTERFACES zif_abapgit_branch_overview .
|
||||
TYPES: ty_commits TYPE STANDARD TABLE OF zif_abapgit_definitions=>ty_commit WITH DEFAULT KEY .
|
||||
CONSTANTS c_deleted_branch_name_prefix TYPE string VALUE '__DELETED_BRANCH_' ##NO_TEXT.
|
||||
|
||||
METHODS constructor
|
||||
|
@ -23,14 +22,14 @@ CLASS zcl_abapgit_branch_overview DEFINITION
|
|||
tyt_commit_sha1_range TYPE RANGE OF zif_abapgit_definitions=>ty_sha1 .
|
||||
|
||||
DATA mt_branches TYPE zif_abapgit_definitions=>ty_git_branch_list_tt .
|
||||
DATA mt_commits TYPE ty_commits .
|
||||
DATA mt_commits TYPE zif_abapgit_definitions=>ty_commit_tt .
|
||||
DATA mt_tags TYPE zif_abapgit_definitions=>ty_git_tag_list_tt .
|
||||
|
||||
CLASS-METHODS parse_commits
|
||||
IMPORTING
|
||||
!it_objects TYPE zif_abapgit_definitions=>ty_objects_tt
|
||||
RETURNING
|
||||
VALUE(rt_commits) TYPE ty_commits
|
||||
VALUE(rt_commits) TYPE zif_abapgit_definitions=>ty_commit_tt
|
||||
RAISING
|
||||
zcx_abapgit_exception .
|
||||
METHODS parse_annotated_tags
|
||||
|
@ -59,7 +58,7 @@ CLASS zcl_abapgit_branch_overview DEFINITION
|
|||
zcx_abapgit_exception .
|
||||
METHODS _sort_commits
|
||||
CHANGING
|
||||
!ct_commits TYPE ty_commits .
|
||||
!ct_commits TYPE zif_abapgit_definitions=>ty_commit_tt .
|
||||
METHODS _get_1st_child_commit
|
||||
IMPORTING
|
||||
!it_commit_sha1s TYPE tyt_commit_sha1_range
|
||||
|
@ -67,10 +66,10 @@ CLASS zcl_abapgit_branch_overview DEFINITION
|
|||
!et_commit_sha1s TYPE tyt_commit_sha1_range
|
||||
!es_1st_commit TYPE zif_abapgit_definitions=>ty_commit
|
||||
CHANGING
|
||||
!ct_commits TYPE ty_commits .
|
||||
!ct_commits TYPE zif_abapgit_definitions=>ty_commit_tt .
|
||||
METHODS _reverse_sort_order
|
||||
CHANGING
|
||||
!ct_commits TYPE ty_commits .
|
||||
!ct_commits TYPE zif_abapgit_definitions=>ty_commit_tt .
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
@ -405,15 +404,14 @@ CLASS zcl_abapgit_branch_overview IMPLEMENTATION.
|
|||
INSERT <lv_body> INTO TABLE ls_commit-body.
|
||||
ENDLOOP.
|
||||
|
||||
* unix time stamps are in same time zone, so ignore the zone,
|
||||
FIND REGEX zif_abapgit_definitions=>c_author_regex IN ls_raw-author
|
||||
SUBMATCHES
|
||||
ls_commit-author
|
||||
ls_commit-email
|
||||
ls_commit-time ##NO_TEXT.
|
||||
IF sy-subrc <> 0.
|
||||
zcx_abapgit_exception=>raise( 'Error author regex' ).
|
||||
ENDIF.
|
||||
zcl_abapgit_utils=>extract_author_data(
|
||||
EXPORTING
|
||||
iv_author = ls_raw-author
|
||||
IMPORTING
|
||||
ev_author = ls_commit-author
|
||||
ev_email = ls_commit-email
|
||||
ev_time = ls_commit-time ).
|
||||
|
||||
APPEND ls_commit TO rt_commits.
|
||||
|
||||
ENDLOOP.
|
||||
|
@ -506,7 +504,7 @@ CLASS zcl_abapgit_branch_overview IMPLEMENTATION.
|
|||
|
||||
METHOD _get_1st_child_commit.
|
||||
|
||||
DATA: lt_1stchild_commits TYPE ty_commits,
|
||||
DATA: lt_1stchild_commits TYPE zif_abapgit_definitions=>ty_commit_tt,
|
||||
ls_parent LIKE LINE OF it_commit_sha1s,
|
||||
lt_commit_sha1s LIKE it_commit_sha1s.
|
||||
|
||||
|
@ -544,7 +542,7 @@ CLASS zcl_abapgit_branch_overview IMPLEMENTATION.
|
|||
|
||||
|
||||
METHOD _reverse_sort_order.
|
||||
DATA: lt_commits TYPE ty_commits.
|
||||
DATA: lt_commits TYPE zif_abapgit_definitions=>ty_commit_tt.
|
||||
FIELD-SYMBOLS: <ls_commit> TYPE zif_abapgit_definitions=>ty_commit.
|
||||
|
||||
LOOP AT ct_commits ASSIGNING <ls_commit>.
|
||||
|
@ -558,7 +556,7 @@ CLASS zcl_abapgit_branch_overview IMPLEMENTATION.
|
|||
|
||||
METHOD _sort_commits.
|
||||
|
||||
DATA: lt_sorted_commits TYPE ty_commits,
|
||||
DATA: lt_sorted_commits TYPE zif_abapgit_definitions=>ty_commit_tt,
|
||||
ls_next_commit TYPE zif_abapgit_definitions=>ty_commit,
|
||||
lt_parents TYPE tyt_commit_sha1_range,
|
||||
ls_parent LIKE LINE OF lt_parents.
|
||||
|
|
|
@ -21,7 +21,7 @@ CLASS ltcl_test IMPLEMENTATION.
|
|||
METHOD parse_commits.
|
||||
|
||||
DATA: lt_objects TYPE zif_abapgit_definitions=>ty_objects_tt,
|
||||
lt_commits TYPE zcl_abapgit_branch_overview=>ty_commits,
|
||||
lt_commits TYPE zif_abapgit_definitions=>ty_commit_tt,
|
||||
ls_commit LIKE LINE OF lt_commits,
|
||||
ls_object LIKE LINE OF lt_objects.
|
||||
|
||||
|
@ -58,7 +58,7 @@ CLASS ltcl_test IMPLEMENTATION.
|
|||
METHOD check_author_regex.
|
||||
|
||||
DATA: lt_objects TYPE zif_abapgit_definitions=>ty_objects_tt,
|
||||
lt_commits TYPE zcl_abapgit_branch_overview=>ty_commits,
|
||||
lt_commits TYPE zif_abapgit_definitions=>ty_commit_tt,
|
||||
ls_object LIKE LINE OF lt_objects,
|
||||
ls_git_pack_commit TYPE zcl_abapgit_git_pack=>ty_commit.
|
||||
|
||||
|
|
|
@ -405,8 +405,7 @@ INTERFACE zif_abapgit_definitions
|
|||
CONSTANTS c_english TYPE spras VALUE 'E' ##NO_TEXT.
|
||||
CONSTANTS c_root_dir TYPE string VALUE '/' ##NO_TEXT.
|
||||
CONSTANTS c_dot_abapgit TYPE string VALUE '.abapgit.xml' ##NO_TEXT.
|
||||
CONSTANTS:
|
||||
c_author_regex TYPE string VALUE '^([\\\w\s\.\*\,\#@%\-_1-9\(\)\[\] ]+) <(.*)> (\d{10})\s?.\d{4}$' ##NO_TEXT.
|
||||
CONSTANTS c_author_regex TYPE string VALUE '^(.+) <(.*)> (\d{10})\s?.\d{4}$' ##NO_TEXT.
|
||||
CONSTANTS:
|
||||
BEGIN OF c_action,
|
||||
repo_refresh TYPE string VALUE 'repo_refresh',
|
||||
|
|
Loading…
Reference in New Issue
Block a user