From 15dcf4198437702d7508ad33d81df0a4212bbbd2 Mon Sep 17 00:00:00 2001 From: Domi Bigl Date: Wed, 28 Oct 2020 07:00:37 +0100 Subject: [PATCH] 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 --- docs/ref-exits.md | 8 +++ src/zcl_abapgit_exit.clas.abap | 20 +++++- src/zcl_abapgit_repo_online.clas.abap | 64 +++++++++++++------ ..._abapgit_repo_online.clas.testclasses.abap | 5 +- src/zif_abapgit_exit.intf.abap | 7 ++ 5 files changed, 83 insertions(+), 21 deletions(-) diff --git a/docs/ref-exits.md b/docs/ref-exits.md index 5cf310a2f..1b5d50d23 100644 --- a/docs/ref-exits.md +++ b/docs/ref-exits.md @@ -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//\.git | http(s): //github.com//\/commit/17b6411cdb59cfb4478a8e6b3de1da3241fedd41 | +|bitbucket | http(s):\/\/bitbucket.org//\.git | http(s):\/\/bitbucket.org//\/commits/17b6411cdb59cfb4478a8e6b3de1da3241fedd41 | +|gitlab | http(s):\/\/gitlab.com//\.git | http(s):\/\/gitlab.com/\/\/-/commit/17b6411cdb59cfb4478a8e6b3de1da3241fedd41 | diff --git a/src/zcl_abapgit_exit.clas.abap b/src/zcl_abapgit_exit.clas.abap index e586f9c61..431711ef4 100644 --- a/src/zcl_abapgit_exit.clas.abap +++ b/src/zcl_abapgit_exit.clas.abap @@ -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. diff --git a/src/zcl_abapgit_repo_online.clas.abap b/src/zcl_abapgit_repo_online.clas.abap index e5586b4ab..486fd66a8 100644 --- a/src/zcl_abapgit_repo_online.clas.abap +++ b/src/zcl_abapgit_repo_online.clas.abap @@ -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 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 . + CASE rv_url+-offset(-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 . - CASE rv_url+-offset(-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. diff --git a/src/zcl_abapgit_repo_online.clas.testclasses.abap b/src/zcl_abapgit_repo_online.clas.testclasses.abap index 21bbe38d6..835a76471 100644 --- a/src/zcl_abapgit_repo_online.clas.testclasses.abap +++ b/src/zcl_abapgit_repo_online.clas.testclasses.abap @@ -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 = -show_url act = lv_show_url diff --git a/src/zif_abapgit_exit.intf.abap b/src/zif_abapgit_exit.intf.abap index 5d44438ca..af1fabe55 100644 --- a/src/zif_abapgit_exit.intf.abap +++ b/src/zif_abapgit_exit.intf.abap @@ -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.