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 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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
!iv_hide_branch TYPE zif_abapgit_git_definitions=>ty_git_branch-name OPTIONAL
!iv_hide_head 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
!iv_hide_branch TYPE zif_abapgit_git_definitions=>ty_git_branch-name OPTIONAL
!iv_hide_head TYPE abap_bool DEFAULT abap_false.
PROTECTED SECTION.
PRIVATE SECTION.
DATA mv_repo_url TYPE string.
DATA mv_default_branch TYPE string.
DATA mv_show_new_option TYPE abap_bool.
DATA mv_hide_branch TYPE zif_abapgit_git_definitions=>ty_git_branch-name.
DATA mv_hide_head 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 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.
mv_hide_branch = iv_hide_branch.
mv_hide_head = iv_hide_head.
ENDMETHOD.
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
iv_hide_branch = iv_hide_branch
iv_hide_head = iv_hide_head.
ENDMETHOD.
METHOD fetch_branch_list.
DATA lo_branches TYPE REF TO zif_abapgit_git_branch_list.
DATA lv_head_symref TYPE string.
DATA lv_text 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 mv_hide_branch IS NOT INITIAL.
DELETE rt_branches WHERE name = mv_hide_branch.
ENDIF.
IF mv_hide_head = abap_true.
DELETE rt_branches WHERE name = zif_abapgit_git_definitions=>c_head_name
OR is_head = abap_true.
ENDIF.
IF rt_branches IS INITIAL.
IF mv_hide_head = abap_true.
lv_text = 'main'.
ENDIF.
IF mv_hide_branch IS NOT INITIAL AND mv_hide_branch <> zif_abapgit_git_definitions=>c_git_branch-main.
IF lv_text IS INITIAL.
lv_text = mv_hide_branch && ' is'.
ELSE.
CONCATENATE lv_text 'and' mv_hide_branch 'are' INTO lv_text SEPARATED BY space.
ENDIF.
ELSE.
lv_text = lv_text && ' is'.
ENDIF.
IF lv_text <> ' is'.
zcx_abapgit_exception=>raise( 'No branches available to select (' && lv_text && ' hidden)' ).
ELSE.
zcx_abapgit_exception=>raise( 'No branches are available to select' ).
ENDIF.
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.
APPEND INITIAL LINE TO rt_branches ASSIGNING <ls_branch>.
<ls_branch>-name = zif_abapgit_popups=>c_new_branch_from_label.
<ls_branch>-display_name = zif_abapgit_popups=>c_new_branch_from_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>.
" 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.
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.
ENDCLASS.
|