
class zcl_im_cl_cts_git_forward definition
public
final
create public .
public section.
types ty_tadir type standard table of tadir with default key.
types ty_objects_to_push type table of if_cts_abap_vcs_transport_req=>ty_objects with default key.
interfaces if_ex_cts_request_check .
constants co_superpackage type string value 'MY_TADIR_DEVC_PACKAGE' ##NO_TEXT.
protected section.
private section.
methods is_my_package_package
importing
!iv_package type devclass
returning
value(rv_found) type boolean .
methods get_objects_to_push
importing
!iv_repository type if_cts_abap_vcs_repository=>ty_repository_json
!it_object_list type ty_tadir
returning
value(rt_objects_to_push) type ty_objects_to_push .
endclass.
class zcl_im_cl_cts_git_forward implementation.
method if_ex_cts_request_check~check_before_add_objects.
" Not needed
endmethod.
method if_ex_cts_request_check~check_before_changing_owner.
" Not needed
endmethod.
method if_ex_cts_request_check~check_before_creation.
" Not needed
endmethod.
method if_ex_cts_request_check~check_before_release.
data: ls_tadir type tadir,
ls_e071 type e071,
lt_e071 type table of e071 with default key,
lt_object_list type ty_tadir,
ls_address type bapiaddr3,
lv_objname type sobj_name,
lv_check type flag.
" Execute just for a specific user (optional)
if sy-uname = 'MY_USER'.
" Execute just for certain TR type (e.g. task)
" R - repair, S - development/correction, Q -customizing task
if type = 'R' or type = 'S' or type = 'Q'.
" loop over provided objects from the BAdI signature parameter
loop at objects into data(ls_object).
data(lv_pgmid) = ls_object-pgmid.
data(lv_obj_type) = ls_object-object.
lv_objname = ls_object-obj_name.
" Find the super object for part objects which have not pgmid = R3TR
" This is needed if that object will be committed for the very first time
" Otherwise the repository will just contain, e.g. a single method, which cannot be deployed to a target system
if ls_object-pgmid = 'LIMU'.
call function 'TR_CHECK_TYPE'
exporting
wi_e071 = ls_object
importing
we_tadir = ls_tadir
exceptions
others = 1.
" There was a TADIR entry for that object
if sy-subrc = 0.
lv_pgmid = ls_tadir-pgmid.
lv_obj_type = ls_tadir-object.
lv_objname = ls_tadir-obj_name.
clear ls_tadir.
else.
continue.
endif.
endif.
" Also keep sure that this is a 'real' object and not a generated one
call function 'DEV_CHECK_OBJECT_EXISTS'
exporting
i_pgmid = lv_pgmid
i_objtype = lv_obj_type
i_objname = lv_objname
importing
e_exists = lv_check.
if sy-subrc = 0.
if lv_check = abap_true.
" Double check that the related object could be transported by SE01/SE09
call function 'TR_TADIR_INTERFACE'
exporting
wi_tadir_pgmid = lv_pgmid
wi_tadir_object = lv_obj_type
wi_tadir_obj_name = lv_objname
wi_read_only = 'X'
importing
new_tadir_entry = ls_tadir
exceptions
others = 1.
" Evaluate that the current object is related to my DEVC package (optional)
" Why do we need that?
" It could be the case that we have a lot of different TR which will be transported trought our STMS landscape
" In the case that gCTS will be used in parallel with common CTS we have to distinguish between the various object package relation
" because of the fact that we probably just want to push objects which are related to our repository
" For S/4HANA 2020: There is method which can be used in order to determine repository relation:
" CL_CTS_ABAP_VCS_ORGANIZER_FAC=>check_objects
if is_my_package_package( ls_tadir-devclass ) = abap_true and ls_tadir-genflag = abap_false.
if not line_exists( lt_object_list[ obj_name = ls_tadir-obj_name ] ).
append ls_tadir to lt_object_list.
clear ls_tadir.
endif.
endif.
else.
continue.
endif.
else.
" Handle Exception Here
raise cancel.
endif.
endloop.
" Get all exisiting repositories for current system
data(lt_repositories) = cl_cts_abap_vcs_api_facade=>get_repositories( value #( ) ).
" Was everything okay?
if lt_repositories-exception is initial.
loop at lt_repositories-result into data(ls_repository).
" Compare provided object list with objects list of repository ...
data(lt_objects_to_push) = get_objects_to_push( iv_repository = ls_repository it_object_list = lt_object_list ).
if lt_objects_to_push is not initial.
" Consume simplified facade method in order to commit&push objects to remote repository
data(lv_response) = cl_cts_abap_vcs_trans_facade=>push_objects( value #(
" Define Commit message
desc = text
" Define repository id for related objects
repository = ls_repository-rid
" Define repository related objects
objects = lt_objects_to_push
) ).
endif.
endloop.
endif.
endif.
endif.
endmethod.
method if_ex_cts_request_check~check_before_release_slin.
endmethod.
method is_my_package_package.
" Is this our wanted package?
if iv_package = co_superpackage.
rv_found = abap_true.
else.
" Load package method information
call method cl_package=>load_package
exporting
i_package_name = iv_package
importing
e_package = data(lo_package)
exceptions
others = 1.
if lo_package is not initial.
" is there a superpackage?
" If not the process is over and this isn't our wanted package
if lo_package->super_package_name is initial.
rv_found = abap_false.
elseif lo_package->super_package_name = co_superpackage .
rv_found = abap_true.
else.
" Recursive call if there is a superpackage which also have to be evaluated
rv_found = is_my_package_package( lo_package->super_package_name ).
endif.
else.
"this isn't our wanted package
rv_found = abap_false.
endif.
endif.
endmethod.
method get_objects_to_push.
data: ls_single_object type if_cts_abap_vcs_repository=>ty_object.
" Get all available objects for repository (Warning: this will just work with GitHub API repositories!)
data(ls_objects_response) = cl_cts_abap_vcs_repo_facade=>get_objects( iv_repository-rid ).
if ls_objects_response-objects is not initial and ls_objects_response-exception is initial.
loop at it_object_list into data(ls_object).
if line_exists( ls_objects_response-objects[ object = ls_object-devclass type = 'DEVC' ] ) or
line_exists( ls_objects_response-objects[ object = co_superpackage type = 'DEVC' ] ).
if line_exists( ls_objects_response-objects[ object = ls_object-obj_name type = ls_object-object ] ).
ls_single_object = ls_objects_response-objects[ object = ls_object-obj_name type = ls_object-object ].
append value #( object = ls_single_object-object type = ls_single_object-type ) to rt_objects_to_push.
else.
append value #( object = ls_object-obj_name type = ls_object-object ) to rt_objects_to_push.
endif.
elseif line_exists( ls_objects_response-objects[ object = ls_object-obj_name type = ls_object-object ] ).
ls_single_object = ls_objects_response-objects[ object = ls_object-obj_name type = ls_object-object ].
append value #( object = ls_single_object-object type = ls_single_object-type ) to rt_objects_to_push.
endif.
clear ls_single_object.
endloop.
endif.
endmethod.
endclass.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
18 | |
11 | |
8 | |
7 | |
6 | |
6 | |
6 | |
5 | |
5 | |
5 |