All files / src/ui/pages/codi zcl_abapgit_gui_page_code_insp.clas.abap

91.97% Statements 298/324
100% Branches 0/0
0% Functions 0/2
91.97% Lines 298/324

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 3251x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                         1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x                             1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
CLASS zcl_abapgit_gui_page_code_insp DEFINITION
  PUBLIC
  INHERITING FROM zcl_abapgit_gui_page_codi_base
  FINAL
  CREATE PRIVATE.
 
  PUBLIC SECTION.
 
    INTERFACES:
      zif_abapgit_gui_page_title,
      zif_abapgit_gui_event_handler,
      zif_abapgit_gui_hotkeys,
      zif_abapgit_gui_menu_provider,
      zif_abapgit_gui_renderable.
 
    CLASS-METHODS create
      IMPORTING
        io_repo                  TYPE REF TO zcl_abapgit_repo
        io_stage                 TYPE REF TO zcl_abapgit_stage OPTIONAL
        iv_check_variant         TYPE sci_chkv OPTIONAL
        iv_raise_when_no_results TYPE abap_bool DEFAULT abap_false
      RETURNING
        VALUE(ri_page)           TYPE REF TO zif_abapgit_gui_renderable
      RAISING
        zcx_abapgit_exception.
 
    METHODS constructor
      IMPORTING
        io_repo                  TYPE REF TO zcl_abapgit_repo
        io_stage                 TYPE REF TO zcl_abapgit_stage OPTIONAL
        iv_check_variant         TYPE sci_chkv OPTIONAL
        iv_raise_when_no_results TYPE abap_bool DEFAULT abap_false
      RAISING
        zcx_abapgit_exception.
 
  PROTECTED SECTION.
  PRIVATE SECTION.
 
    DATA mo_stage         TYPE REF TO zcl_abapgit_stage.
    DATA mv_check_variant TYPE sci_chkv.
 
    METHODS:
      run_code_inspector
        RAISING
          zcx_abapgit_exception,
 
      has_inspection_errors
        RETURNING
          VALUE(rv_has_inspection_errors) TYPE abap_bool,
 
      is_stage_allowed
        RETURNING
          VALUE(rv_is_stage_allowed) TYPE abap_bool,
 
      ask_user_for_check_variant
        RETURNING
          VALUE(rv_check_variant) TYPE sci_chkv
        RAISING
          zcx_abapgit_exception,
 
      determine_check_variant
        RAISING
          zcx_abapgit_exception.
 
    METHODS status
      RETURNING
        VALUE(rv_status) TYPE zif_abapgit_definitions=>ty_sci_result.
 
ENDCLASS.
 
 
 
CLASS ZCL_ABAPGIT_GUI_PAGE_CODE_INSP IMPLEMENTATION.
 
 
  METHOD ask_user_for_check_variant.
 
    rv_check_variant = zcl_abapgit_ui_factory=>get_popups( )->choose_code_insp_check_variant( ).
 
    IF rv_check_variant IS INITIAL.
      zcx_abapgit_exception=>raise( |Please select a check variant.| ).
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD constructor.
 
    super->constructor( ).
    mo_repo = io_repo.
    mo_stage = io_stage.
    mv_check_variant = iv_check_variant.
    determine_check_variant( ).
    run_code_inspector( ).
 
    IF mt_result IS INITIAL AND iv_raise_when_no_results = abap_true.
      zcx_abapgit_exception=>raise( 'No results' ).
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD create.
 
    DATA lo_component TYPE REF TO zcl_abapgit_gui_page_code_insp.
 
    CREATE OBJECT lo_component
      EXPORTING
        io_repo                  = io_repo
        io_stage                 = io_stage
        iv_check_variant         = iv_check_variant
        iv_raise_when_no_results = iv_raise_when_no_results.
 
    ri_page = zcl_abapgit_gui_page_hoc=>create( lo_component ).
 
  ENDMETHOD.
 
 
  METHOD determine_check_variant.

    IF mv_check_variant IS NOT INITIAL.
      RETURN.
    ENDIF.

    mv_check_variant = mo_repo->get_local_settings( )-code_inspector_check_variant.

    IF mv_check_variant IS INITIAL.
      mv_check_variant = ask_user_for_check_variant( ).
    ENDIF.

  ENDMETHOD.
 
 
  METHOD has_inspection_errors.
 
    READ TABLE mt_result TRANSPORTING NO FIELDS WITH KEY kind = 'E'.
    rv_has_inspection_errors = boolc( sy-subrc = 0 ).
 
  ENDMETHOD.
 
 
  METHOD is_stage_allowed.
 
    rv_is_stage_allowed = boolc( NOT (
      mo_repo->get_local_settings( )-block_commit = abap_true AND has_inspection_errors( ) = abap_true ) ).
 
  ENDMETHOD.
 
 
  METHOD run_code_inspector.

    DATA li_code_inspector TYPE REF TO zif_abapgit_code_inspector.

    li_code_inspector = zcl_abapgit_factory=>get_code_inspector( mo_repo->get_package( ) ).

    mt_result = li_code_inspector->run(
      iv_variant = |{ mv_check_variant }|
      iv_save    = abap_true ).

    mv_summary = li_code_inspector->get_summary( ).

    DELETE mt_result WHERE kind = 'N'.

  ENDMETHOD.
 
 
  METHOD status.
 
    READ TABLE mt_result TRANSPORTING NO FIELDS WITH KEY kind = 'E'.
    IF sy-subrc = 0.
      rv_status = zif_abapgit_definitions=>c_sci_result-failed.
    ELSE.
      READ TABLE mt_result TRANSPORTING NO FIELDS WITH KEY kind = 'W'.
      IF sy-subrc = 0.
        rv_status = zif_abapgit_definitions=>c_sci_result-warning.
      ELSE.
        rv_status = zif_abapgit_definitions=>c_sci_result-passed.
      ENDIF.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_event_handler~on_event.
 
    DATA lo_repo_online TYPE REF TO zcl_abapgit_repo_online.
 
    CASE ii_event->mv_action.
      WHEN c_actions-stage.
 
        lo_repo_online ?= mo_repo.
 
        IF is_stage_allowed( ) = abap_true.
 
          rs_handled-page   = zcl_abapgit_gui_page_stage=>create(
            io_repo       = lo_repo_online
            iv_sci_result = status( ) ).
 
          rs_handled-state = zcl_abapgit_gui=>c_event_state-new_page.
 
        ELSE.
 
          rs_handled-state = zcl_abapgit_gui=>c_event_state-no_more_act.
 
        ENDIF.
 
      WHEN c_actions-commit.
 
        lo_repo_online ?= mo_repo.
 
        IF is_stage_allowed( ) = abap_true.
 
          rs_handled-page = zcl_abapgit_gui_page_commit=>create(
            io_repo  = lo_repo_online
            io_stage = mo_stage ).
 
          rs_handled-state = zcl_abapgit_gui=>c_event_state-new_page.
 
        ELSE.
 
          rs_handled-state = zcl_abapgit_gui=>c_event_state-no_more_act.
 
        ENDIF.
 
      WHEN c_actions-rerun.
 
        run_code_inspector( ).
        rs_handled-state = zcl_abapgit_gui=>c_event_state-re_render.
 
      WHEN OTHERS.
        rs_handled = on_event( ii_event ).
    ENDCASE.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_hotkeys~get_hotkey_actions.
 
    DATA: ls_hotkey_action LIKE LINE OF rt_hotkey_actions.
 
    ls_hotkey_action-ui_component = 'Code Inspector'.
 
    ls_hotkey_action-description = |Stage|.
    ls_hotkey_action-action = c_actions-stage.
    ls_hotkey_action-hotkey = |s|.
    INSERT ls_hotkey_action INTO TABLE rt_hotkey_actions.
 
    ls_hotkey_action-description = |Re-Run|.
    ls_hotkey_action-action = c_actions-rerun.
    ls_hotkey_action-hotkey = |r|.
    INSERT ls_hotkey_action INTO TABLE rt_hotkey_actions.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_menu_provider~get_menu.
 
    DATA: lv_opt TYPE c LENGTH 1.
 
    ro_toolbar = build_base_menu( ).
 
    IF is_stage_allowed( ) = abap_false.
      lv_opt = zif_abapgit_html=>c_html_opt-crossout.
    ENDIF.
 
    IF mo_repo->is_offline( ) = abap_true.
      RETURN.
    ENDIF.
 
    IF mo_stage IS BOUND.
 
      " Staging info already available, we can directly
      " offer to commit
 
      ro_toolbar->add(
        iv_txt = 'Commit'
        iv_act = c_actions-commit
        iv_opt = lv_opt ).
 
    ELSE.
 
      ro_toolbar->add(
        iv_txt = 'Stage'
        iv_act = c_actions-stage
        iv_opt = lv_opt ).
 
    ENDIF.
 
    ro_toolbar->add(
      iv_txt = 'Back'
      iv_act = zif_abapgit_definitions=>c_action-go_back ).
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_page_title~get_page_title.
    rv_title = 'Code Inspector'.
  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_renderable~render.
 
    register_handlers( ).
 
    CREATE OBJECT ri_html TYPE zcl_abapgit_html.
 
    ri_html->div(
      iv_class = 'repo'
      ii_content = zcl_abapgit_gui_chunk_lib=>render_repo_top(
        io_repo        = mo_repo
        iv_show_commit = abap_false ) ).
 
    IF mv_check_variant IS INITIAL.
      ri_html->add( zcl_abapgit_gui_chunk_lib=>render_error( iv_error = 'No check variant supplied.' ) ).
      RETURN.
    ENDIF.
 
    render_ci_report(
      ii_html    = ri_html
      iv_variant = mv_check_variant
      iv_success_msg = 'No code inspector findings' ).
 
  ENDMETHOD.
ENDCLASS.