All files / src/ui/popups zcl_abapgit_popup_branch_list.clas.abap

100% Statements 123/123
100% Branches 0/0
100% Functions 0/0
100% Lines 123/123

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 1241x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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_popup_branch_list DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .
 
  PUBLIC SECTION.
 
    INTERFACES zif_abapgit_gui_render_item.
    INTERFACES zif_abapgit_html_popup.
 
    CLASS-METHODS create
      IMPORTING
        !iv_url             TYPE string
        !iv_default_branch  TYPE string OPTIONAL
        !iv_show_new_option TYPE abap_bool DEFAULT abap_false
      RETURNING
        VALUE(ri_popup)     TYPE REF TO zif_abapgit_html_popup.
 
    METHODS constructor
      IMPORTING
        !iv_url             TYPE string
        !iv_default_branch  TYPE string OPTIONAL
        !iv_show_new_option TYPE abap_bool DEFAULT abap_false.
 
  PRIVATE SECTION.
 
    DATA mv_repo_url TYPE string.
    DATA mv_default_branch TYPE string.
    DATA mv_show_new_option TYPE abap_bool.
 
    METHODS fetch_branch_list
      RETURNING
        VALUE(rt_branches) TYPE zif_abapgit_git_definitions=>ty_git_branch_list_tt
      RAISING
        zcx_abapgit_exception.
 
ENDCLASS.
 
 
 
CLASS zcl_abapgit_popup_branch_list IMPLEMENTATION.
 
 
  METHOD create.
    CREATE OBJECT ri_popup TYPE zcl_abapgit_popup_branch_list
      EXPORTING
        iv_url             = iv_url
        iv_default_branch  = iv_default_branch
        iv_show_new_option = iv_show_new_option.
  ENDMETHOD.
 
 
  METHOD constructor.
    mv_repo_url        = iv_url.
    mv_default_branch  = zif_abapgit_git_definitions=>c_git_branch-heads_prefix && iv_default_branch.
    mv_show_new_option = iv_show_new_option.
  ENDMETHOD.
 
 
  METHOD zif_abapgit_html_popup~create_picklist.
 
    CREATE OBJECT ro_picklist
      EXPORTING
        iv_title         = 'Choose Branch'
        it_list          = fetch_branch_list( )
        ii_item_renderer = me.
 
  ENDMETHOD.
 
 
  METHOD fetch_branch_list.
 
    DATA lo_branches    TYPE REF TO zcl_abapgit_git_branch_list.
    DATA lv_head_symref TYPE string.
 
    FIELD-SYMBOLS <ls_branch> LIKE LINE OF rt_branches.
 
    lo_branches    = zcl_abapgit_git_factory=>get_git_transport( )->branches( mv_repo_url ).
    rt_branches    = lo_branches->get_branches_only( ).
    lv_head_symref = lo_branches->get_head_symref( ).
 
    IF rt_branches IS INITIAL.
      zcx_abapgit_exception=>raise( 'No branches are available to select' ).
    ENDIF.
 
    " Clean up branches: HEAD duplicates, empty names
    LOOP AT rt_branches ASSIGNING <ls_branch>.
      IF <ls_branch>-name IS INITIAL.
        DELETE rt_branches INDEX sy-tabix.
      ELSEIF <ls_branch>-is_head = abap_true AND lv_head_symref IS NOT INITIAL AND <ls_branch>-name <> lv_head_symref.
        DELETE rt_branches INDEX sy-tabix.
      ENDIF.
    ENDLOOP.
 
    SORT rt_branches BY is_head DESCENDING display_name ASCENDING.
 
    IF mv_show_new_option = abap_true.
      APPEND INITIAL LINE TO rt_branches ASSIGNING <ls_branch>.
      <ls_branch>-name = zif_abapgit_popups=>c_new_branch_label.
      <ls_branch>-display_name = zif_abapgit_popups=>c_new_branch_label.
    ENDIF.
 
  ENDMETHOD.
 
 
  METHOD zif_abapgit_gui_render_item~render.
 
    DATA lv_head_marker TYPE string.
    FIELD-SYMBOLS <ls_b> TYPE zif_abapgit_git_definitions=>ty_git_branch.
 
    ASSIGN iv_item TO <ls_b>.
    ASSERT sy-subrc = 0.
 
    " TODO render mv_default_branch properly, needs respecting support from the picklist components
 
    IF <ls_b>-is_head = abap_true.
      lv_head_marker = | (<b>{ zif_abapgit_git_definitions=>c_head_name }</b>)|.
    ENDIF.
 
    ri_html = zcl_abapgit_html=>create( |{ <ls_b>-display_name }{ lv_head_marker }| ).
 
  ENDMETHOD.
ENDCLASS.