All files / src/ui/routing zcl_abapgit_services_git.clas.abap

100% Statements 339/339
100% Branches 1/1
100% Functions 1/1
100% Lines 339/339

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 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 3401x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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_services_git DEFINITION
  PUBLIC
  FINAL
  CREATE PUBLIC .
 
  PUBLIC SECTION.
    CLASS-METHODS pull
      IMPORTING
        !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
      RAISING
        zcx_abapgit_exception.
    CLASS-METHODS create_branch
      IMPORTING
        !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
      RAISING
        zcx_abapgit_exception.
    CLASS-METHODS create_branch_from
      IMPORTING
        !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
      RAISING
        zcx_abapgit_exception.
    CLASS-METHODS switch_branch
      IMPORTING
        !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
      RAISING
        zcx_abapgit_exception.
    CLASS-METHODS delete_branch
      IMPORTING
        !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
      RAISING
        zcx_abapgit_exception.
    CLASS-METHODS delete_tag
      IMPORTING
        !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
      RAISING
        zcx_abapgit_exception.
    CLASS-METHODS switch_tag
      IMPORTING
        !iv_key TYPE zif_abapgit_persistence=>ty_repo-key
      RAISING
        zcx_abapgit_exception.
    CLASS-METHODS commit
      IMPORTING
        !ii_repo_online TYPE REF TO zif_abapgit_repo_online
        !is_commit      TYPE zif_abapgit_services_git=>ty_commit_fields
        !io_stage       TYPE REF TO zcl_abapgit_stage
      RAISING
        zcx_abapgit_exception.
 
  PROTECTED SECTION.
  PRIVATE SECTION.
 
    CLASS-METHODS create_branch_common
      IMPORTING
        !iv_key                TYPE zif_abapgit_persistence=>ty_repo-key
        !iv_source_branch_name TYPE string
        !iv_source_commit      TYPE zif_abapgit_git_definitions=>ty_sha1
      RAISING
        zcx_abapgit_exception.
 
ENDCLASS.
 
 
 
CLASS ZCL_ABAPGIT_SERVICES_GIT IMPLEMENTATION.
 
 
  METHOD commit.
 
    DATA: ls_comment TYPE zif_abapgit_git_definitions=>ty_comment,
          li_user    TYPE REF TO zif_abapgit_persist_user.
 
    li_user = zcl_abapgit_persist_factory=>get_user( ).
    li_user->set_repo_git_user_name( iv_url      = ii_repo_online->get_url( )
                                     iv_username = is_commit-committer_name ).
    li_user->set_repo_git_user_email( iv_url   = ii_repo_online->get_url( )
                                      iv_email = is_commit-committer_email ).
 
    IF is_commit-committer_name IS INITIAL.
      zcx_abapgit_exception=>raise( 'Commit: Committer name empty' ).
    ELSEIF is_commit-committer_email IS INITIAL.
      zcx_abapgit_exception=>raise( 'Commit: Committer email empty' ).
    ELSEIF is_commit-author_email IS NOT INITIAL AND is_commit-author_name IS INITIAL.
      zcx_abapgit_exception=>raise( 'Commit: Author name empty' ). " Opposite should be OK ?
    ELSEIF is_commit-comment IS INITIAL.
      zcx_abapgit_exception=>raise( 'Commit: empty comment' ).
    ENDIF.
 
    ls_comment-committer-name  = is_commit-committer_name.
    ls_comment-committer-email = is_commit-committer_email.
    ls_comment-author-name     = is_commit-author_name.
    ls_comment-author-email    = is_commit-author_email.
    ls_comment-comment         = is_commit-comment.
 
    IF NOT is_commit-body IS INITIAL.
      CONCATENATE ls_comment-comment '' is_commit-body
        INTO ls_comment-comment SEPARATED BY cl_abap_char_utilities=>newline.
    ENDIF.
 
    zcl_abapgit_exit=>get_instance( )->validate_before_push(
      is_comment     = ls_comment
      io_stage       = io_stage
      ii_repo_online = ii_repo_online ).
 
    ii_repo_online->push( is_comment = ls_comment
                          io_stage   = io_stage ).
 
    COMMIT WORK.
 
    zcl_abapgit_exit=>get_instance( )->validate_after_push( ii_repo_online ).
 
  ENDMETHOD.
 
 
  METHOD create_branch.
 
    DATA: lv_name               TYPE string,
          lv_cancel             TYPE abap_bool,
          li_repo_online        TYPE REF TO zif_abapgit_repo_online,
          lv_msg                TYPE string,
          li_popups             TYPE REF TO zif_abapgit_popups,
          lv_source_branch_name TYPE string.
 
 
    li_repo_online ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
    lv_source_branch_name = li_repo_online->get_selected_branch( ).
 
    li_popups = zcl_abapgit_ui_factory=>get_popups( ).
    li_popups->create_branch_popup(
      EXPORTING
        iv_source_branch_name = lv_source_branch_name
      IMPORTING
        ev_name               = lv_name
        ev_cancel             = lv_cancel ).
 
    IF lv_cancel = abap_true.
      RAISE EXCEPTION TYPE zcx_abapgit_cancel.
    ENDIF.
 
    li_repo_online->create_branch( lv_name ).
 
    lv_msg = |Branch switched from { zcl_abapgit_git_branch_utils=>get_display_name( lv_source_branch_name )
      } to new branch { zcl_abapgit_git_branch_utils=>get_display_name( lv_name ) }|.
    MESSAGE lv_msg TYPE 'S'.
 
  ENDMETHOD.
 
 
  METHOD create_branch_from.
 
    DATA: li_repo_online   TYPE REF TO zif_abapgit_repo_online,
          li_popups        TYPE REF TO zif_abapgit_popups,
          ls_source_branch TYPE zif_abapgit_git_definitions=>ty_git_branch.
 
 
    li_repo_online ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
 
    " Choose the source branch that the new branch will be created from
    li_popups = zcl_abapgit_ui_factory=>get_popups( ).
    ls_source_branch = li_popups->branch_list_popup(
      iv_url                 = li_repo_online->get_url( )
      iv_default_branch      = li_repo_online->get_selected_branch( )
      iv_title               = 'Create Branch From'
      iv_text                = 'Select the source branch for the new branch'
      iv_show_switch_message = abap_false ).
    IF ls_source_branch-name IS INITIAL.
      RAISE EXCEPTION TYPE zcx_abapgit_cancel.
    ENDIF.
 
    create_branch_common(
      iv_key                = iv_key
      iv_source_branch_name = ls_source_branch-name
      iv_source_commit      = ls_source_branch-sha1 ).
 
  ENDMETHOD.
 
 
  METHOD create_branch_common.
 
    DATA: lv_name        TYPE string,
          lv_cancel      TYPE abap_bool,
          li_repo_online TYPE REF TO zif_abapgit_repo_online,
          lv_msg         TYPE string,
          li_popups      TYPE REF TO zif_abapgit_popups.
 
 
    li_repo_online ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
 
    li_popups = zcl_abapgit_ui_factory=>get_popups( ).
    li_popups->create_branch_popup(
      EXPORTING
        iv_source_branch_name = iv_source_branch_name
      IMPORTING
        ev_name               = lv_name
        ev_cancel             = lv_cancel ).
 
    IF lv_cancel = abap_true.
      RAISE EXCEPTION TYPE zcx_abapgit_cancel.
    ENDIF.
 
    li_repo_online->create_branch(
      iv_name = lv_name
      iv_from = iv_source_commit ).
 
    lv_msg = |Branch created from { zcl_abapgit_git_branch_utils=>get_display_name( iv_source_branch_name )
      } as new branch { zcl_abapgit_git_branch_utils=>get_display_name( lv_name ) }|.
    MESSAGE lv_msg TYPE 'S'.
 
  ENDMETHOD.
 
 
  METHOD delete_branch.
 
    DATA: li_repo_online TYPE REF TO zif_abapgit_repo_online,
          ls_branch      TYPE zif_abapgit_git_definitions=>ty_git_branch,
          lv_msg         TYPE string,
          li_popups      TYPE REF TO zif_abapgit_popups.
 
 
    li_repo_online ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
 
    li_popups = zcl_abapgit_ui_factory=>get_popups( ).
    ls_branch = li_popups->branch_list_popup( iv_url         = li_repo_online->get_url( )
                                              iv_hide_branch = li_repo_online->get_selected_branch( )
                                              iv_hide_head   = abap_true ).
    IF ls_branch IS INITIAL.
      RAISE EXCEPTION TYPE zcx_abapgit_cancel.
    ENDIF.
 
    zcl_abapgit_git_porcelain=>delete_branch(
      iv_url    = li_repo_online->get_url( )
      is_branch = ls_branch ).
 
    lv_msg = |Branch { ls_branch-display_name } deleted|.
    MESSAGE lv_msg TYPE 'S'.
 
  ENDMETHOD.
 
 
  METHOD delete_tag.
 
    DATA: li_repo_online TYPE REF TO zif_abapgit_repo_online,
          ls_tag         TYPE zif_abapgit_git_definitions=>ty_git_tag,
          lv_text        TYPE string.
 
    li_repo_online ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
 
    ls_tag = zcl_abapgit_ui_factory=>get_popups( )->tag_list_popup( li_repo_online->get_url( ) ).
    IF ls_tag IS INITIAL.
      RAISE EXCEPTION TYPE zcx_abapgit_cancel.
    ENDIF.
 
    zcl_abapgit_git_porcelain=>delete_tag(
      iv_url = li_repo_online->get_url( )
      is_tag = ls_tag ).
 
    lv_text = |Tag { ls_tag-display_name } deleted|.
 
    MESSAGE lv_text TYPE 'S'.
 
  ENDMETHOD.
 
 
  METHOD pull.
 
    DATA: li_repo TYPE REF TO zif_abapgit_repo.
 
    li_repo = zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
 
    li_repo->refresh( ).
 
    zcl_abapgit_services_repo=>gui_deserialize( li_repo ).
 
  ENDMETHOD.
 
 
  METHOD switch_branch.
 
    DATA: li_repo_online TYPE REF TO zif_abapgit_repo_online,
          ls_branch      TYPE zif_abapgit_git_definitions=>ty_git_branch.
 
 
    li_repo_online ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
 
    ls_branch = zcl_abapgit_ui_factory=>get_popups( )->branch_list_popup(
      iv_url             = li_repo_online->get_url( )
      iv_default_branch  = li_repo_online->get_selected_branch( )
      iv_show_new_option = abap_true ).
    IF ls_branch IS INITIAL.
      RAISE EXCEPTION TYPE zcx_abapgit_cancel.
    ENDIF.
 
    IF ls_branch-name = zif_abapgit_popups=>c_new_branch_label.
      create_branch( iv_key ).
      RETURN.
    ENDIF.
 
    IF ls_branch-name = zif_abapgit_popups=>c_new_branch_from_label.
      create_branch_from( iv_key ).
      RETURN.
    ENDIF.
 
    " Reset commit and pull request
    li_repo_online->select_commit( '' ).
    li_repo_online->switch_origin( '' ).
 
    li_repo_online->select_branch( ls_branch-name ).
    COMMIT WORK AND WAIT.
 
  ENDMETHOD.
 
 
  METHOD switch_tag.
 
    DATA: li_repo_online TYPE REF TO zif_abapgit_repo_online,
          ls_tag         TYPE zif_abapgit_git_definitions=>ty_git_tag,
          lv_text        TYPE string.
 
    li_repo_online ?= zcl_abapgit_repo_srv=>get_instance( )->get( iv_key ).
 
    ls_tag = zcl_abapgit_ui_factory=>get_popups( )->tag_list_popup( li_repo_online->get_url( ) ).
    IF ls_tag IS INITIAL.
      RAISE EXCEPTION TYPE zcx_abapgit_cancel.
    ENDIF.
 
    " Reset commit and pull request
    li_repo_online->select_commit( '' ).
    li_repo_online->switch_origin( '' ).
 
    li_repo_online->select_branch( zcl_abapgit_git_tag=>remove_peel( ls_tag-name ) ).
 
    COMMIT WORK AND WAIT.
 
    lv_text = |Tag switched to { ls_tag-display_name } |.
 
    MESSAGE lv_text TYPE 'S'.
 
  ENDMETHOD.
ENDCLASS.