mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-01 12:20:51 +08:00
Add Feature: Create New Branch for Commit (#5123)
* add feature: create new branch for commit * add clarifying comments * add check for empty branch name * remove check box, add condense to new branch name * add duplicate check for branch name Co-authored-by: Marc Bernard <59966492+mbtools@users.noreply.github.com>
This commit is contained in:
parent
51aeea2bc5
commit
289f22d79d
|
@ -40,6 +40,7 @@ CLASS zcl_abapgit_gui_page_commit DEFINITION
|
|||
author TYPE string VALUE 'author',
|
||||
author_name TYPE string VALUE 'author_name',
|
||||
author_email TYPE string VALUE 'author_email',
|
||||
new_branch_name TYPE string VALUE 'new_branch_name',
|
||||
END OF c_id.
|
||||
|
||||
CONSTANTS:
|
||||
|
@ -107,9 +108,14 @@ CLASS zcl_abapgit_gui_page_commit DEFINITION
|
|||
VALUE(rv_text) TYPE string.
|
||||
METHODS is_valid_email
|
||||
IMPORTING
|
||||
!iv_email TYPE string
|
||||
iv_email TYPE string
|
||||
RETURNING
|
||||
VALUE(rv_valid) TYPE abap_bool.
|
||||
METHODS branch_name_to_internal
|
||||
IMPORTING
|
||||
iv_branch_name TYPE string
|
||||
RETURNING
|
||||
VALUE(rv_new_branch_name) TYPE string.
|
||||
ENDCLASS.
|
||||
|
||||
|
||||
|
@ -322,7 +328,13 @@ CLASS zcl_abapgit_gui_page_commit IMPLEMENTATION.
|
|||
iv_placeholder = 'Optionally, specify an author (same as committer by default)'
|
||||
)->text(
|
||||
iv_name = c_id-author_email
|
||||
iv_label = 'Author Email' ).
|
||||
iv_label = 'Author Email'
|
||||
)->text(
|
||||
iv_name = c_id-new_branch_name
|
||||
iv_label = 'New Branch Name'
|
||||
iv_placeholder = 'Optionally, enter a new branch name for this commit'
|
||||
iv_condense = abap_true ).
|
||||
|
||||
|
||||
ro_form->command(
|
||||
iv_label = 'Commit'
|
||||
|
@ -435,6 +447,9 @@ CLASS zcl_abapgit_gui_page_commit IMPLEMENTATION.
|
|||
|
||||
METHOD validate_form.
|
||||
|
||||
DATA: lt_branches TYPE zif_abapgit_definitions=>ty_git_branch_list_tt,
|
||||
lv_new_branch_name TYPE string.
|
||||
|
||||
ro_validation_log = mo_form_util->validate( io_form_data ).
|
||||
|
||||
IF is_valid_email( io_form_data->get( c_id-committer_email ) ) = abap_false.
|
||||
|
@ -449,10 +464,24 @@ CLASS zcl_abapgit_gui_page_commit IMPLEMENTATION.
|
|||
iv_val = |Invalid email address| ).
|
||||
ENDIF.
|
||||
|
||||
lv_new_branch_name = io_form_data->get( c_id-new_branch_name ).
|
||||
IF lv_new_branch_name IS NOT INITIAL.
|
||||
" check if branch already exists
|
||||
lt_branches = zcl_abapgit_git_transport=>branches( mo_repo->get_url( ) )->get_branches_only( ).
|
||||
READ TABLE lt_branches TRANSPORTING NO FIELDS WITH TABLE KEY name_key
|
||||
COMPONENTS name = branch_name_to_internal( lv_new_branch_name ).
|
||||
IF sy-subrc = 0.
|
||||
ro_validation_log->set(
|
||||
iv_key = c_id-new_branch_name
|
||||
iv_val = |Branch already exists| ).
|
||||
ENDIF.
|
||||
ENDIF.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD zif_abapgit_gui_event_handler~on_event.
|
||||
DATA lv_new_branch_name TYPE string.
|
||||
|
||||
mo_form_data = mo_form_util->normalize( ii_event->form_data( ) ).
|
||||
|
||||
|
@ -465,6 +494,10 @@ CLASS zcl_abapgit_gui_page_commit IMPLEMENTATION.
|
|||
mo_validation_log = validate_form( mo_form_data ).
|
||||
|
||||
IF mo_validation_log->is_empty( ) = abap_true.
|
||||
|
||||
" new branch fields not needed in commit data
|
||||
mo_form_data->strict( abap_false ).
|
||||
|
||||
mo_form_data->to_abap( CHANGING cs_container = ms_commit ).
|
||||
|
||||
REPLACE ALL OCCURRENCES
|
||||
|
@ -472,11 +505,20 @@ CLASS zcl_abapgit_gui_page_commit IMPLEMENTATION.
|
|||
IN ms_commit-body
|
||||
WITH zif_abapgit_definitions=>c_newline.
|
||||
|
||||
lv_new_branch_name = mo_form_data->get( c_id-new_branch_name ).
|
||||
" create new branch and commit to it if branch name is not empty
|
||||
IF lv_new_branch_name IS NOT INITIAL.
|
||||
lv_new_branch_name = branch_name_to_internal( lv_new_branch_name ).
|
||||
" creates a new branch and automatically switches to it
|
||||
mo_repo->create_branch( lv_new_branch_name ).
|
||||
ENDIF.
|
||||
|
||||
zcl_abapgit_services_git=>commit(
|
||||
is_commit = ms_commit
|
||||
io_repo = mo_repo
|
||||
io_stage = mo_stage ).
|
||||
|
||||
|
||||
MESSAGE 'Commit was successful' TYPE 'S'.
|
||||
|
||||
rs_handled-state = zcl_abapgit_gui=>c_event_state-go_back_to_bookmark.
|
||||
|
@ -516,4 +558,10 @@ CLASS zcl_abapgit_gui_page_commit IMPLEMENTATION.
|
|||
ri_html->add( '</div>' ).
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
METHOD branch_name_to_internal.
|
||||
rv_new_branch_name = zcl_abapgit_git_branch_list=>complete_heads_branch_name(
|
||||
zcl_abapgit_git_branch_list=>normalize_branch_name( iv_branch_name ) ).
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
|
|
Loading…
Reference in New Issue
Block a user