mirror of
https://github.com/abapGit/abapGit.git
synced 2025-04-30 20:03:20 +08:00
add user exit for commit display URL (#4073)
* add user exit for commit display URL METHODS adjust_display_commit_url IMPORTING iv_repo_url TYPE zif_abapgit_persistence=>ty_repo-url iv_commit_hash TYPE zif_abapgit_definitions=>ty_sha1 CHANGING cv_display_url TYPE zif_abapgit_persistence=>ty_repo-url * adjust UT * provide also repo name and key in the exit * Update ref-exits.md * Update ref-exits.md Co-authored-by: Lars Hvam <larshp@hotmail.com>
This commit is contained in:
parent
ba0c1257c8
commit
15dcf41984
|
@ -50,3 +50,11 @@ This [example implementation](https://gist.github.com/flaiker/999c8165b89131608b
|
|||
|
||||
### DESERIALIZE_POSTPROCESS
|
||||
Can be used for any postprocessing operation for deserialized objects. Since it is a postprocessing step, only logs can be added to II_LOG and one should not terminate the process by raising exception, which may lead to inconsistencies.
|
||||
|
||||
### ADJUST_DISPLAY_COMMIT_URL
|
||||
Can be used to set the URL to display a commit. There is a default implementation for some provider:
|
||||
| | Repo URL | Show Commit URL|
|
||||
|-- | -- | -- |
|
||||
|github | http(s):\/\/github.com/<user\>/\<repo\>.git | http(s): //github.com/<user\>/\<repo\>/commit/17b6411cdb59cfb4478a8e6b3de1da3241fedd41 |
|
||||
|bitbucket | http(s):\/\/bitbucket.org/<user\>/\<repo\>.git | http(s):\/\/bitbucket.org/<user\>/\<repo\>/commits/17b6411cdb59cfb4478a8e6b3de1da3241fedd41 |
|
||||
|gitlab | http(s):\/\/gitlab.com/<user\>/\<repo\>.git | http(s):\/\/gitlab.com/\<user\>/\<repo\>/-/commit/17b6411cdb59cfb4478a8e6b3de1da3241fedd41 |
|
||||
|
|
|
@ -15,7 +15,7 @@ ENDCLASS.
|
|||
|
||||
|
||||
|
||||
CLASS ZCL_ABAPGIT_EXIT IMPLEMENTATION.
|
||||
CLASS zcl_abapgit_exit IMPLEMENTATION.
|
||||
|
||||
|
||||
METHOD get_instance.
|
||||
|
@ -176,4 +176,22 @@ CLASS ZCL_ABAPGIT_EXIT IMPLEMENTATION.
|
|||
ENDTRY.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD zif_abapgit_exit~adjust_display_commit_url.
|
||||
|
||||
TRY.
|
||||
gi_exit->adjust_display_commit_url(
|
||||
EXPORTING
|
||||
iv_repo_url = iv_repo_url
|
||||
iv_repo_name = iv_repo_name
|
||||
iv_repo_key = iv_repo_key
|
||||
iv_commit_hash = iv_commit_hash
|
||||
CHANGING
|
||||
cv_display_url = cv_display_url ).
|
||||
CATCH cx_sy_ref_is_initial cx_sy_dyn_call_illegal_method ##NO_HANDLER.
|
||||
ENDTRY.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
|
|
|
@ -56,6 +56,13 @@ CLASS zcl_abapgit_repo_online DEFINITION
|
|||
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 .
|
||||
|
@ -67,13 +74,13 @@ CLASS zcl_abapgit_repo_online DEFINITION
|
|||
zcx_abapgit_exception .
|
||||
|
||||
METHODS get_files_remote
|
||||
REDEFINITION .
|
||||
REDEFINITION .
|
||||
METHODS get_name
|
||||
REDEFINITION .
|
||||
REDEFINITION .
|
||||
METHODS has_remote_source
|
||||
REDEFINITION .
|
||||
REDEFINITION .
|
||||
METHODS rebuild_local_checksums
|
||||
REDEFINITION .
|
||||
REDEFINITION .
|
||||
PROTECTED SECTION.
|
||||
PRIVATE SECTION.
|
||||
|
||||
|
@ -132,27 +139,46 @@ CLASS zcl_abapgit_repo_online IMPLEMENTATION.
|
|||
|
||||
METHOD get_commit_display_url.
|
||||
|
||||
rv_url = me->get_default_commit_display_url( iv_hash ).
|
||||
|
||||
zcl_abapgit_exit=>get_instance( )->adjust_display_commit_url(
|
||||
EXPORTING
|
||||
iv_repo_url = me->get_url( )
|
||||
iv_repo_name = me->get_name( )
|
||||
iv_repo_key = me->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_default_commit_display_url.
|
||||
|
||||
DATA ls_result TYPE match_result.
|
||||
FIELD-SYMBOLS <ls_provider_match> TYPE submatch_result.
|
||||
|
||||
rv_url = me->get_url( ).
|
||||
|
||||
FIND REGEX '^https:\/\/(?:www\.)?(github\.com|bitbucket\.org|gitlab\.com)\/' IN rv_url RESULTS ls_result.
|
||||
IF sy-subrc <> 0.
|
||||
zcx_abapgit_exception=>raise( |provider not yet supported| ).
|
||||
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.
|
||||
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.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
|
|
@ -29,6 +29,9 @@ CLASS ltcl_repo_online IMPLEMENTATION.
|
|||
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.
|
||||
ls_provider_urls-repo_url = |http://github.com/abapGit/abapGit.git|.
|
||||
ls_provider_urls-show_url = |http://github.com/abapGit/abapGit/commit/{ lv_testhash }|.
|
||||
APPEND ls_provider_urls TO lt_test_urls.
|
||||
ls_provider_urls-repo_url = |https://bitbucket.org/abapGit/abapGit.git|.
|
||||
ls_provider_urls-show_url = |https://bitbucket.org/abapGit/abapGit/commits/{ lv_testhash }|.
|
||||
APPEND ls_provider_urls TO lt_test_urls.
|
||||
|
@ -46,7 +49,7 @@ CLASS ltcl_repo_online IMPLEMENTATION.
|
|||
EXPORTING
|
||||
is_data = ls_online_repo.
|
||||
|
||||
lv_show_url = lr_test_repo->get_commit_display_url( iv_hash = lv_testhash ).
|
||||
lv_show_url = lr_test_repo->get_default_commit_display_url( iv_hash = lv_testhash ).
|
||||
|
||||
cl_aunit_assert=>assert_equals( exp = <ls_provider_urls>-show_url
|
||||
act = lv_show_url
|
||||
|
|
|
@ -69,4 +69,11 @@ INTERFACE zif_abapgit_exit
|
|||
!iv_object TYPE tadir-object
|
||||
CHANGING
|
||||
!ct_ci_repos TYPE ty_ci_repos .
|
||||
METHODS adjust_display_commit_url
|
||||
IMPORTING !iv_repo_url TYPE zif_abapgit_persistence=>ty_repo-url
|
||||
!iv_repo_name TYPE string
|
||||
!iv_repo_key TYPE zif_abapgit_persistence=>ty_value
|
||||
!iv_commit_hash TYPE zif_abapgit_definitions=>ty_sha1
|
||||
CHANGING !cv_display_url TYPE zif_abapgit_persistence=>ty_repo-url
|
||||
RAISING zcx_abapgit_exception .
|
||||
ENDINTERFACE.
|
||||
|
|
Loading…
Reference in New Issue
Block a user