Refactor: Decouple staging logic from factory

The factory class is too god-like. This will allow using the stage logic independently.
This commit is contained in:
Marc Bernard 2025-02-26 10:43:22 +00:00
parent 91dd6873ab
commit 2e93418ac0
7 changed files with 38 additions and 35 deletions

View File

@ -110,7 +110,7 @@ CLASS zcl_abapgit_background_push_au IMPLEMENTATION.
<ls_local> LIKE LINE OF ls_files-local.
ls_files = zcl_abapgit_factory=>get_stage_logic( )->get( io_repo ).
ls_files = zcl_abapgit_stage_logic=>get_stage_logic( )->get( io_repo ).
LOOP AT ls_files-local ASSIGNING <ls_local>.
lv_changed_by = zcl_abapgit_objects=>changed_by(
@ -237,7 +237,7 @@ CLASS zcl_abapgit_background_push_au IMPLEMENTATION.
DATA: ls_files TYPE zif_abapgit_definitions=>ty_stage_files.
mi_log = ii_log.
ls_files = zcl_abapgit_factory=>get_stage_logic( )->get( io_repo ).
ls_files = zcl_abapgit_stage_logic=>get_stage_logic( )->get( io_repo ).
IF lines( ls_files-local ) = 0 AND lines( ls_files-remote ) = 0.
ii_log->add_info( 'Nothing to stage' ).

View File

@ -73,7 +73,7 @@ CLASS zcl_abapgit_background_push_fi IMPLEMENTATION.
<ls_remote> LIKE LINE OF ls_files-remote.
ls_files = zcl_abapgit_factory=>get_stage_logic( )->get( io_repo ).
ls_files = zcl_abapgit_stage_logic=>get_stage_logic( )->get( io_repo ).
ASSERT lines( ls_files-local ) > 0
OR lines( ls_files-remote ) > 0.
@ -142,7 +142,7 @@ CLASS zcl_abapgit_background_push_fi IMPLEMENTATION.
lv_email TYPE string.
mi_log = ii_log.
ls_files = zcl_abapgit_factory=>get_stage_logic( )->get( io_repo ).
ls_files = zcl_abapgit_stage_logic=>get_stage_logic( )->get( io_repo ).
IF lines( ls_files-local ) = 0 AND lines( ls_files-remote ) = 0.
ii_log->add_info( 'Nothing to stage' ).

View File

@ -50,7 +50,7 @@ CLASS zcl_abapgit_transport_2_branch IMPLEMENTATION.
CREATE OBJECT lo_stage.
ls_stage_objects = zcl_abapgit_factory=>get_stage_logic( )->get( io_repository ).
ls_stage_objects = zcl_abapgit_stage_logic=>get_stage_logic( )->get( io_repository ).
lt_object_statuses = zcl_abapgit_repo_status=>calculate( io_repository ).

View File

@ -1,13 +1,24 @@
CLASS zcl_abapgit_stage_logic DEFINITION
PUBLIC
CREATE PRIVATE
GLOBAL FRIENDS zcl_abapgit_factory .
CREATE PRIVATE.
PUBLIC SECTION.
INTERFACES zif_abapgit_stage_logic .
INTERFACES zif_abapgit_stage_logic.
CLASS-METHODS get_stage_logic
RETURNING
VALUE(ri_logic) TYPE REF TO zif_abapgit_stage_logic.
CLASS-METHODS set_stage_logic
IMPORTING
ii_logic TYPE REF TO zif_abapgit_stage_logic.
PROTECTED SECTION.
PRIVATE SECTION.
CLASS-DATA gi_stage_logic TYPE REF TO zif_abapgit_stage_logic.
CLASS-METHODS:
remove_ignored
IMPORTING io_repo TYPE REF TO zcl_abapgit_repo_online
@ -22,6 +33,17 @@ ENDCLASS.
CLASS zcl_abapgit_stage_logic IMPLEMENTATION.
METHOD get_stage_logic.
IF gi_stage_logic IS INITIAL.
CREATE OBJECT gi_stage_logic TYPE zcl_abapgit_stage_logic.
ENDIF.
ri_logic = gi_stage_logic.
ENDMETHOD.
METHOD remove_identical.
DATA: lv_index TYPE i,
@ -85,6 +107,11 @@ CLASS zcl_abapgit_stage_logic IMPLEMENTATION.
ENDMETHOD.
METHOD set_stage_logic.
gi_stage_logic = ii_logic.
ENDMETHOD.
METHOD zif_abapgit_stage_logic~get.
" Getting REMOTE before LOCAL is critical to ensure that DATA config is loaded first

View File

@ -373,7 +373,7 @@ CLASS zcl_abapgit_gui_page_stage IMPLEMENTATION.
METHOD init_files.
ms_files = zcl_abapgit_factory=>get_stage_logic( )->get( io_repo = mo_repo
ms_files = zcl_abapgit_stage_logic=>get_stage_logic( )->get( io_repo = mo_repo
ii_obj_filter = mi_obj_filter ).
IF lines( ms_files-local ) = 0 AND lines( ms_files-remote ) = 0.

View File

@ -20,9 +20,6 @@ CLASS zcl_abapgit_factory DEFINITION
VALUE(ri_code_inspector) TYPE REF TO zif_abapgit_code_inspector
RAISING
zcx_abapgit_exception .
CLASS-METHODS get_stage_logic
RETURNING
VALUE(ri_logic) TYPE REF TO zif_abapgit_stage_logic .
CLASS-METHODS get_cts_api
RETURNING
VALUE(ri_cts_api) TYPE REF TO zif_abapgit_cts_api .
@ -89,7 +86,7 @@ ENDCLASS.
CLASS ZCL_ABAPGIT_FACTORY IMPLEMENTATION.
CLASS zcl_abapgit_factory IMPLEMENTATION.
METHOD get_code_inspector.
@ -234,17 +231,6 @@ CLASS ZCL_ABAPGIT_FACTORY IMPLEMENTATION.
ENDMETHOD.
METHOD get_stage_logic.
IF gi_stage_logic IS INITIAL.
CREATE OBJECT gi_stage_logic TYPE zcl_abapgit_stage_logic.
ENDIF.
ri_logic = gi_stage_logic.
ENDMETHOD.
METHOD get_tadir.
IF gi_tadir IS INITIAL.

View File

@ -16,9 +16,6 @@ CLASS zcl_abapgit_injector DEFINITION
IMPORTING
!iv_package TYPE devclass
!ii_code_inspector TYPE REF TO zif_abapgit_code_inspector .
CLASS-METHODS set_stage_logic
IMPORTING
!ii_logic TYPE REF TO zif_abapgit_stage_logic .
CLASS-METHODS set_cts_api
IMPORTING
!ii_cts_api TYPE REF TO zif_abapgit_cts_api .
@ -146,13 +143,6 @@ CLASS zcl_abapgit_injector IMPLEMENTATION.
ENDMETHOD.
METHOD set_stage_logic.
zcl_abapgit_factory=>gi_stage_logic = ii_logic.
ENDMETHOD.
METHOD set_tadir.
zcl_abapgit_factory=>gi_tadir = ii_tadir.
ENDMETHOD.