Skip to content

Instantly share code, notes, and snippets.

@mbtools
Created August 10, 2023 15:38
Show Gist options
  • Save mbtools/eb88883dc0e1618195117fc60974d06a to your computer and use it in GitHub Desktop.
Save mbtools/eb88883dc0e1618195117fc60974d06a to your computer and use it in GitHub Desktop.
Run background logic for selected abapGit repositories
REPORT zabapgit_background_mode.
DATA lv_repo TYPE c LENGTH 60.
SELECT-OPTIONS so_repo FOR lv_repo OBLIGATORY.
INITIALIZATION.
%_so_repo_%_app_%-text = 'abapGit Repositories'.
FORM run.
CONSTANTS lc_enq_type TYPE c LENGTH 12 VALUE 'BACKGROUND'.
DATA: lo_per TYPE REF TO zcl_abapgit_persist_background,
lo_repo TYPE REF TO zcl_abapgit_repo_online,
lt_list TYPE zcl_abapgit_persist_background=>ty_background_keys,
li_background TYPE REF TO zif_abapgit_background,
li_log TYPE REF TO zif_abapgit_log,
lx_error TYPE REF TO zcx_abapgit_exception,
lv_repo_name TYPE string.
FIELD-SYMBOLS <ls_list> LIKE LINE OF lt_list.
CALL FUNCTION 'ENQUEUE_EZABAPGIT'
EXPORTING
mode_zabapgit = 'E'
type = lc_enq_type
_scope = '3'
EXCEPTIONS
foreign_lock = 1
system_failure = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: / 'Another intance of the program is already running'.
RETURN.
ENDIF.
TRY.
CREATE OBJECT lo_per.
lt_list = lo_per->list( ).
CATCH zcx_abapgit_exception INTO lx_error.
WRITE / lx_error->get_text( ).
ENDTRY.
WRITE / 'Background mode'.
LOOP AT lt_list ASSIGNING <ls_list>.
TRY.
lo_repo ?= zcl_abapgit_repo_srv=>get_instance( )->get( <ls_list>-key ).
lv_repo_name = lo_repo->get_name( ).
CHECK lv_repo_name IN so_repo.
WRITE: / <ls_list>-method, lv_repo_name.
zcl_abapgit_login_manager=>set(
iv_uri = lo_repo->get_url( )
iv_username = <ls_list>-username
iv_password = <ls_list>-password ).
CREATE OBJECT li_log TYPE zcl_abapgit_log.
CREATE OBJECT li_background TYPE (<ls_list>-method).
li_background->run(
io_repo = lo_repo
ii_log = li_log
it_settings = <ls_list>-settings ).
li_log->add_success( |Repo { lv_repo_name } processed successfully| ).
" Clear auth buffer to allow different user/password per repository in background mode
zcl_abapgit_login_manager=>clear( ).
CATCH zcx_abapgit_exception INTO lx_error.
li_log->add_exception( lx_error ).
ENDTRY.
zcl_abapgit_log_viewer=>write_log( li_log ).
ENDLOOP.
IF lines( lt_list ) = 0.
WRITE / 'Nothing configured'.
ENDIF.
CALL FUNCTION 'DEQUEUE_EZABAPGIT'
EXPORTING
type = lc_enq_type.
ENDFORM.
START-OF-SELECTION.
PERFORM run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment