mirror of
https://github.com/abapGit/abapGit.git
synced 2025-04-30 11:46:38 +08:00
Move git url repo methods (#4147)
* Move git url repo methods This moves methods GET_COMMIT_DISPLAY_URL and GET_DEFAULT_COMMIT_DISPLAY_URL from the repo class to new class in new package GIT_PLATFORM. we want to keep the repo class small, as its quite complex and central #4085 * fix line length
This commit is contained in:
parent
443850751a
commit
3162b23c39
10
src/git_platform/package.devc.xml
Normal file
10
src/git_platform/package.devc.xml
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_DEVC" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<DEVC>
|
||||
<CTEXT>abapGit - Git Platform Functionality</CTEXT>
|
||||
</DEVC>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
84
src/git_platform/zcl_abapgit_git_url.clas.abap
Normal file
84
src/git_platform/zcl_abapgit_git_url.clas.abap
Normal file
|
@ -0,0 +1,84 @@
|
|||
CLASS zcl_abapgit_git_url DEFINITION
|
||||
PUBLIC
|
||||
FINAL
|
||||
CREATE PUBLIC .
|
||||
|
||||
PUBLIC SECTION.
|
||||
|
||||
METHODS get_commit_display_url
|
||||
IMPORTING
|
||||
!io_repo TYPE REF TO zcl_abapgit_repo_online
|
||||
RETURNING
|
||||
VALUE(rv_url) TYPE string
|
||||
RAISING
|
||||
zcx_abapgit_exception .
|
||||
PROTECTED SECTION.
|
||||
|
||||
METHODS get_default_commit_display_url
|
||||
IMPORTING
|
||||
!iv_repo_url TYPE string
|
||||
!iv_hash TYPE zif_abapgit_definitions=>ty_sha1
|
||||
RETURNING
|
||||
VALUE(rv_commit_url) TYPE string
|
||||
RAISING
|
||||
zcx_abapgit_exception .
|
||||
PRIVATE SECTION.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
||||
CLASS ZCL_ABAPGIT_GIT_URL IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD get_commit_display_url.
|
||||
|
||||
DATA li_exit TYPE REF TO zif_abapgit_exit.
|
||||
|
||||
rv_url = get_default_commit_display_url(
|
||||
iv_repo_url = io_repo->get_url( )
|
||||
iv_hash = io_repo->get_current_remote( ) ).
|
||||
|
||||
li_exit = zcl_abapgit_exit=>get_instance( ).
|
||||
li_exit->adjust_display_commit_url(
|
||||
EXPORTING
|
||||
iv_repo_url = io_repo->get_url( )
|
||||
iv_repo_name = io_repo->get_name( )
|
||||
iv_repo_key = io_repo->get_key( )
|
||||
iv_commit_hash = io_repo->get_current_remote( )
|
||||
CHANGING
|
||||
cv_display_url = rv_url ).
|
||||
|
||||
IF rv_url IS INITIAL.
|
||||
zcx_abapgit_exception=>raise( |provider not yet supported| ).
|
||||
ENDIF.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD get_default_commit_display_url.
|
||||
|
||||
DATA ls_result TYPE match_result.
|
||||
FIELD-SYMBOLS <ls_provider_match> TYPE submatch_result.
|
||||
|
||||
rv_commit_url = iv_repo_url.
|
||||
|
||||
FIND REGEX '^http(?:s)?:\/\/(?:www\.)?(github\.com|bitbucket\.org|gitlab\.com)\/'
|
||||
IN rv_commit_url
|
||||
RESULTS ls_result.
|
||||
IF sy-subrc = 0.
|
||||
READ TABLE ls_result-submatches INDEX 1 ASSIGNING <ls_provider_match>.
|
||||
CASE rv_commit_url+<ls_provider_match>-offset(<ls_provider_match>-length).
|
||||
WHEN 'github.com'.
|
||||
REPLACE REGEX '\.git$' IN rv_commit_url WITH space.
|
||||
rv_commit_url = rv_commit_url && |/commit/| && iv_hash.
|
||||
WHEN 'bitbucket.org'.
|
||||
REPLACE REGEX '\.git$' IN rv_commit_url WITH space.
|
||||
rv_commit_url = rv_commit_url && |/commits/| && iv_hash.
|
||||
WHEN 'gitlab.com'.
|
||||
REPLACE REGEX '\.git$' IN rv_commit_url WITH space.
|
||||
rv_commit_url = rv_commit_url && |/-/commit/| && iv_hash.
|
||||
ENDCASE.
|
||||
ENDIF.
|
||||
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
|
@ -1,6 +1,7 @@
|
|||
CLASS ltcl_repo_online DEFINITION FINAL FOR TESTING
|
||||
DURATION SHORT
|
||||
RISK LEVEL HARMLESS.
|
||||
CLASS ltcl_repo_online DEFINITION DEFERRED.
|
||||
CLASS zcl_abapgit_git_url DEFINITION LOCAL FRIENDS ltcl_repo_online.
|
||||
|
||||
CLASS ltcl_repo_online DEFINITION FINAL FOR TESTING DURATION SHORT RISK LEVEL HARMLESS.
|
||||
|
||||
PRIVATE SECTION.
|
||||
METHODS:
|
||||
|
@ -23,9 +24,13 @@ CLASS ltcl_repo_online IMPLEMENTATION.
|
|||
lv_testhash TYPE zif_abapgit_definitions=>ty_sha1 VALUE 'my-SHA1-hash',
|
||||
ls_online_repo TYPE zif_abapgit_persistence=>ty_repo,
|
||||
lr_test_repo TYPE REF TO zcl_abapgit_repo_online,
|
||||
lo_cut TYPE REF TO zcl_abapgit_git_url,
|
||||
lv_show_url TYPE zif_abapgit_persistence=>ty_repo-url.
|
||||
|
||||
FIELD-SYMBOLS <ls_provider_urls> TYPE ty_show_url_test.
|
||||
|
||||
CREATE OBJECT lo_cut.
|
||||
|
||||
ls_provider_urls-repo_url = |https://github.com/abapGit/abapGit.git|.
|
||||
ls_provider_urls-show_url = |https://github.com/abapGit/abapGit/commit/{ lv_testhash }|.
|
||||
APPEND ls_provider_urls TO lt_test_urls.
|
||||
|
@ -49,14 +54,15 @@ CLASS ltcl_repo_online IMPLEMENTATION.
|
|||
EXPORTING
|
||||
is_data = ls_online_repo.
|
||||
|
||||
lv_show_url = lr_test_repo->get_default_commit_display_url( iv_hash = lv_testhash ).
|
||||
lv_show_url = lo_cut->get_default_commit_display_url(
|
||||
iv_repo_url = lr_test_repo->get_url( )
|
||||
iv_hash = lv_testhash ).
|
||||
|
||||
cl_aunit_assert=>assert_equals( exp = <ls_provider_urls>-show_url
|
||||
act = lv_show_url
|
||||
quit = cl_aunit_assert=>no ).
|
||||
ENDLOOP.
|
||||
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
17
src/git_platform/zcl_abapgit_git_url.clas.xml
Normal file
17
src/git_platform/zcl_abapgit_git_url.clas.xml
Normal file
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<VSEOCLASS>
|
||||
<CLSNAME>ZCL_ABAPGIT_GIT_URL</CLSNAME>
|
||||
<LANGU>E</LANGU>
|
||||
<DESCRIPT>abapGit - Git URL</DESCRIPT>
|
||||
<STATE>1</STATE>
|
||||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
|
@ -167,7 +167,7 @@ ENDCLASS.
|
|||
|
||||
|
||||
|
||||
CLASS zcl_abapgit_gui_chunk_lib IMPLEMENTATION.
|
||||
CLASS ZCL_ABAPGIT_GUI_CHUNK_LIB IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD advanced_submenu.
|
||||
|
@ -852,6 +852,7 @@ CLASS zcl_abapgit_gui_chunk_lib IMPLEMENTATION.
|
|||
DATA: lv_commit_hash TYPE zif_abapgit_definitions=>ty_sha1,
|
||||
lv_commit_short_hash TYPE zif_abapgit_definitions=>ty_sha1,
|
||||
lv_display_url TYPE zif_abapgit_persistence=>ty_repo-url,
|
||||
lo_url TYPE REF TO zcl_abapgit_git_url,
|
||||
lv_icon_commit TYPE string.
|
||||
|
||||
lv_commit_hash = io_repo_online->get_current_remote( ).
|
||||
|
@ -861,8 +862,10 @@ CLASS zcl_abapgit_gui_chunk_lib IMPLEMENTATION.
|
|||
iv_class = 'pad-sides'
|
||||
iv_hint = 'Commit' ).
|
||||
|
||||
CREATE OBJECT lo_url.
|
||||
|
||||
TRY.
|
||||
lv_display_url = io_repo_online->get_commit_display_url( lv_commit_hash ).
|
||||
lv_display_url = lo_url->get_commit_display_url( io_repo_online ).
|
||||
|
||||
ii_html->add_a( iv_txt = |{ lv_icon_commit }{ lv_commit_short_hash }|
|
||||
iv_act = |{ zif_abapgit_definitions=>c_action-url }?url={ lv_display_url }|
|
||||
|
|
|
@ -41,7 +41,7 @@ CLASS zcl_abapgit_repo_online DEFINITION
|
|||
zcx_abapgit_exception .
|
||||
METHODS select_commit
|
||||
IMPORTING
|
||||
iv_selected_commit TYPE zif_abapgit_persistence=>ty_repo-selected_commit
|
||||
!iv_selected_commit TYPE zif_abapgit_persistence=>ty_repo-selected_commit
|
||||
RAISING
|
||||
zcx_abapgit_exception .
|
||||
METHODS get_objects
|
||||
|
@ -49,20 +49,6 @@ CLASS zcl_abapgit_repo_online DEFINITION
|
|||
VALUE(rt_objects) TYPE zif_abapgit_definitions=>ty_objects_tt
|
||||
RAISING
|
||||
zcx_abapgit_exception .
|
||||
METHODS get_commit_display_url
|
||||
IMPORTING
|
||||
!iv_hash TYPE zif_abapgit_definitions=>ty_sha1
|
||||
RETURNING
|
||||
VALUE(rv_url) TYPE zif_abapgit_persistence=>ty_repo-url
|
||||
RAISING
|
||||
zcx_abapgit_exception .
|
||||
METHODS get_default_commit_display_url
|
||||
IMPORTING
|
||||
!iv_hash TYPE zif_abapgit_definitions=>ty_sha1
|
||||
RETURNING
|
||||
VALUE(rv_url) TYPE zif_abapgit_persistence=>ty_repo-url
|
||||
RAISING
|
||||
zcx_abapgit_exception .
|
||||
METHODS get_switched_origin
|
||||
RETURNING
|
||||
VALUE(rv_url) TYPE zif_abapgit_persistence=>ty_repo-switched_origin .
|
||||
|
@ -104,7 +90,7 @@ ENDCLASS.
|
|||
|
||||
|
||||
|
||||
CLASS zcl_abapgit_repo_online IMPLEMENTATION.
|
||||
CLASS ZCL_ABAPGIT_REPO_ONLINE IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD fetch_remote.
|
||||
|
@ -136,61 +122,12 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION.
|
|||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD get_commit_display_url.
|
||||
|
||||
DATA li_exit TYPE REF TO zif_abapgit_exit.
|
||||
|
||||
rv_url = get_default_commit_display_url( iv_hash ).
|
||||
|
||||
li_exit = zcl_abapgit_exit=>get_instance( ).
|
||||
li_exit->adjust_display_commit_url(
|
||||
EXPORTING
|
||||
iv_repo_url = get_url( )
|
||||
iv_repo_name = get_name( )
|
||||
iv_repo_key = get_key( )
|
||||
iv_commit_hash = iv_hash
|
||||
CHANGING
|
||||
cv_display_url = rv_url ).
|
||||
|
||||
IF rv_url IS INITIAL.
|
||||
zcx_abapgit_exception=>raise( |provider not yet supported| ).
|
||||
ENDIF.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD get_current_remote.
|
||||
fetch_remote( ).
|
||||
rv_sha1 = mv_current_commit.
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD get_default_commit_display_url.
|
||||
|
||||
DATA ls_result TYPE match_result.
|
||||
FIELD-SYMBOLS <ls_provider_match> TYPE submatch_result.
|
||||
|
||||
rv_url = get_url( ).
|
||||
|
||||
FIND REGEX '^http(?:s)?:\/\/(?:www\.)?(github\.com|bitbucket\.org|gitlab\.com)\/' IN rv_url RESULTS ls_result.
|
||||
IF sy-subrc = 0.
|
||||
READ TABLE ls_result-submatches INDEX 1 ASSIGNING <ls_provider_match>.
|
||||
CASE rv_url+<ls_provider_match>-offset(<ls_provider_match>-length).
|
||||
WHEN 'github.com'.
|
||||
REPLACE REGEX '\.git$' IN rv_url WITH space.
|
||||
rv_url = rv_url && |/commit/| && iv_hash.
|
||||
WHEN 'bitbucket.org'.
|
||||
REPLACE REGEX '\.git$' IN rv_url WITH space.
|
||||
rv_url = rv_url && |/commits/| && iv_hash.
|
||||
WHEN 'gitlab.com'.
|
||||
REPLACE REGEX '\.git$' IN rv_url WITH space.
|
||||
rv_url = rv_url && |/-/commit/| && iv_hash.
|
||||
ENDCASE.
|
||||
ENDIF.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD get_files_remote.
|
||||
fetch_remote( ).
|
||||
rt_files = super->get_files_remote( ).
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
<CLSCCINCL>X</CLSCCINCL>
|
||||
<FIXPT>X</FIXPT>
|
||||
<UNICODE>X</UNICODE>
|
||||
<WITH_UNIT_TESTS>X</WITH_UNIT_TESTS>
|
||||
</VSEOCLASS>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
|
|
Loading…
Reference in New Issue
Block a user