mirror of
https://github.com/abapGit/abapGit.git
synced 2025-05-01 12:20:51 +08:00
Transport to branch
This commit is contained in:
parent
48aadc67e8
commit
e47110f2af
|
@ -141,11 +141,10 @@ TYPES: BEGIN OF ty_sotr,
|
|||
TYPES: ty_sotr_tt TYPE STANDARD TABLE OF ty_sotr WITH DEFAULT KEY.
|
||||
|
||||
TYPES:
|
||||
BEGIN OF ty_branch_pull_request,
|
||||
BEGIN OF ty_transport_to_branch,
|
||||
branch_name TYPE string,
|
||||
commit_text TYPE string,
|
||||
pull_request_title TYPE string,
|
||||
END OF ty_branch_pull_request.
|
||||
END OF ty_transport_to_branch.
|
||||
|
||||
CONSTANTS: BEGIN OF gc_state, " https://git-scm.com/docs/git-status
|
||||
unchanged TYPE char1 VALUE '',
|
||||
|
@ -205,7 +204,7 @@ CONSTANTS: BEGIN OF gc_action,
|
|||
repo_remote_change TYPE string VALUE 'repo_remote_change',
|
||||
repo_refresh_checksums TYPE string VALUE 'repo_refresh_checksums',
|
||||
repo_toggle_fav TYPE string VALUE 'repo_toggle_fav',
|
||||
repo_transport_to_pull_reqst TYPE string VALUE 'go_transport_to_pull_request',
|
||||
repo_transport_to_branch TYPE string VALUE 'go_transport_to_branch',
|
||||
|
||||
abapgit_home TYPE string VALUE 'abapgit_home',
|
||||
abapgit_wiki TYPE string VALUE 'abapgit_wiki',
|
||||
|
|
|
@ -70,7 +70,7 @@ CLASS lcl_gui_router IMPLEMENTATION.
|
|||
ls_item TYPE ty_item,
|
||||
lt_transport_headers TYPE trwbo_request_headers,
|
||||
lt_tadir TYPE scts_tadir,
|
||||
ls_branch_pull_request TYPE ty_branch_pull_request.
|
||||
ls_transport_to_branch TYPE ty_transport_to_branch.
|
||||
|
||||
lv_key = iv_getdata. " TODO refactor
|
||||
lv_url = iv_getdata. " TODO refactor
|
||||
|
@ -174,19 +174,24 @@ CLASS lcl_gui_router IMPLEMENTATION.
|
|||
WHEN gc_action-repo_toggle_fav. " Toggle repo as favorite
|
||||
lcl_services_repo=>toggle_favorite( lv_key ).
|
||||
ev_state = gc_event_state-re_render.
|
||||
WHEN gc_action-repo_transport_to_pull_reqst.
|
||||
WHEN gc_action-repo_transport_to_branch.
|
||||
ev_state = gc_event_state-re_render.
|
||||
|
||||
lt_transport_headers = lcl_transport_popup=>show( ).
|
||||
lt_tadir = lcl_transport=>to_tadir( lt_transport_headers ).
|
||||
ls_branch_pull_request = lcl_popups=>popup_to_create_pull_request(
|
||||
IF lt_tadir IS INITIAL.
|
||||
lcx_exception=>raise( 'Canceled or List of objects is empty ' ).
|
||||
ENDIF.
|
||||
ls_transport_to_branch = lcl_popups=>popup_to_create_transp_branch(
|
||||
it_transport_headers = lt_transport_headers
|
||||
it_transport_objects = lt_tadir
|
||||
).
|
||||
lcl_services_repo=>transport_to_pull_request(
|
||||
lcl_services_repo=>transport_to_branch(
|
||||
iv_repository_key = lv_key
|
||||
is_branch_pull_request = ls_branch_pull_request
|
||||
is_transport_to_branch = ls_transport_to_branch
|
||||
it_transport_objects = lt_tadir
|
||||
).
|
||||
ev_state = gc_event_state-re_render.
|
||||
|
||||
|
||||
" ZIP services actions
|
||||
WHEN gc_action-zip_import. " Import repo from ZIP
|
||||
|
|
|
@ -69,10 +69,10 @@ CLASS lcl_popups DEFINITION FINAL.
|
|||
EXPORTING es_package_data TYPE scompkdtln
|
||||
ev_create TYPE boolean
|
||||
RAISING lcx_exception,
|
||||
popup_to_create_pull_request
|
||||
popup_to_create_transp_branch
|
||||
IMPORTING it_transport_headers TYPE trwbo_request_headers
|
||||
it_transport_objects TYPE scts_tadir
|
||||
RETURNING VALUE(rs_branch_pull_request) TYPE ty_branch_pull_request
|
||||
RETURNING VALUE(rs_transport_branch) TYPE ty_transport_to_branch
|
||||
RAISING lcx_exception
|
||||
lcx_cancel.
|
||||
ENDCLASS.
|
||||
|
@ -550,12 +550,12 @@ CLASS lcl_popups IMPLEMENTATION.
|
|||
ENDIF.
|
||||
ENDMETHOD. " popup_to_create_package
|
||||
|
||||
METHOD popup_to_create_pull_request.
|
||||
METHOD popup_to_create_transp_branch.
|
||||
DATA: lv_returncode TYPE c,
|
||||
lt_fields TYPE TABLE OF sval,
|
||||
lv_icon_ok TYPE icon-name,
|
||||
lv_button_pull_request TYPE svalbutton-buttontext,
|
||||
lv_icon_pull_request TYPE icon-name,
|
||||
lv_button_transport TYPE svalbutton-buttontext,
|
||||
lv_icon_transport TYPE icon-name,
|
||||
lv_transports_as_text TYPE string,
|
||||
ls_transport_header LIKE LINE OF it_transport_headers.
|
||||
|
||||
|
@ -569,22 +569,21 @@ CLASS lcl_popups IMPLEMENTATION.
|
|||
" TAB FLD LABEL DEF ATTR
|
||||
_add_dialog_fld 'TEXTL' 'LINE' 'Branch name' lv_transports_as_text ''.
|
||||
_add_dialog_fld 'ABAPTXT255' 'LINE' 'Commit text' lv_transports_as_text ''.
|
||||
_add_dialog_fld 'SAPPARAM' 'SNAME' 'Pull request' lv_transports_as_text ''.
|
||||
"_add_dialog_fld 'ABAPTXT255' 'LINE' 'TODO: Tadir Items?' '' ''.
|
||||
|
||||
lv_icon_ok = icon_okay.
|
||||
lv_button_pull_request = 'Create pull request' ##NO_TEXT.
|
||||
lv_icon_pull_request = icon_import_all_requests.
|
||||
lv_button_transport = 'Transport(s)->Branch' ##NO_TEXT.
|
||||
lv_icon_transport = icon_import_all_requests.
|
||||
|
||||
CALL FUNCTION 'POPUP_GET_VALUES_USER_BUTTONS'
|
||||
call FUNCTION 'POPUP_GET_VALUES_USER_BUTTONS'
|
||||
EXPORTING
|
||||
popup_title = 'Transport to Pull Request'
|
||||
popup_title = 'Transport to new Branch'
|
||||
programname = sy-repid
|
||||
formname = 'PULL_REQUEST_POPUP'
|
||||
ok_pushbuttontext = ''
|
||||
icon_ok_push = ''
|
||||
first_pushbutton = lv_button_pull_request
|
||||
icon_button_1 = lv_icon_pull_request
|
||||
first_pushbutton = lv_button_transport
|
||||
icon_button_1 = lv_icon_transport
|
||||
second_pushbutton = ''
|
||||
icon_button_2 = ''
|
||||
IMPORTING
|
||||
|
@ -599,23 +598,16 @@ CLASS lcl_popups IMPLEMENTATION.
|
|||
ENDIF.
|
||||
|
||||
IF lv_returncode = 'A'.
|
||||
RAISE exception type lcx_cancel.
|
||||
RAISE EXCEPTION TYPE lcx_cancel.
|
||||
ENDIF.
|
||||
|
||||
|
||||
READ TABLE lt_fields INDEX 1 ASSIGNING <ls_field>.
|
||||
ASSERT sy-subrc = 0.
|
||||
rs_branch_pull_request-branch_name = <ls_field>-value.
|
||||
rs_transport_branch-branch_name = <ls_field>-value.
|
||||
|
||||
READ TABLE lt_fields INDEX 2 ASSIGNING <ls_field>.
|
||||
ASSERT sy-subrc = 0.
|
||||
rs_branch_pull_request-commit_text = <ls_field>-value.
|
||||
|
||||
READ TABLE lt_fields INDEX 3 ASSIGNING <ls_field>.
|
||||
ASSERT sy-subrc = 0.
|
||||
rs_branch_pull_request-pull_request_title = <ls_field>-value.
|
||||
|
||||
|
||||
rs_transport_branch-commit_text = <ls_field>-value.
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
*& Include ZABAPGIT_SERVICES
|
||||
*&---------------------------------------------------------------------*
|
||||
|
||||
INCLUDE zabapgit_services_trans_branch.
|
||||
INCLUDE zabapgit_services_repo.
|
||||
INCLUDE zabapgit_services_abapgit.
|
||||
INCLUDE zabapgit_services_git.
|
||||
|
|
|
@ -47,11 +47,11 @@ CLASS lcl_services_repo DEFINITION FINAL.
|
|||
IMPORTING iv_package TYPE devclass
|
||||
RAISING lcx_exception.
|
||||
|
||||
CLASS-METHODS transport_to_pull_request
|
||||
IMPORTING
|
||||
iv_repository_key TYPE lcl_persistence_db=>ty_value
|
||||
is_branch_pull_request TYPE ty_branch_pull_request
|
||||
it_transport_objects TYPE scts_tadir.
|
||||
CLASS-METHODS transport_to_branch
|
||||
IMPORTING iv_repository_key TYPE lcl_persistence_db=>ty_value
|
||||
is_transport_to_branch TYPE ty_transport_to_branch
|
||||
it_transport_objects TYPE scts_tadir
|
||||
RAISING lcx_exception.
|
||||
|
||||
ENDCLASS. "lcl_services_repo
|
||||
|
||||
|
@ -321,77 +321,17 @@ CLASS lcl_services_repo IMPLEMENTATION.
|
|||
ENDMETHOD. " open_se80.
|
||||
|
||||
|
||||
METHOD transport_to_pull_request.
|
||||
METHOD transport_to_branch.
|
||||
DATA:
|
||||
lo_repo TYPE REF TO lcl_repo_online,
|
||||
ls_transport_object LIKE LINE OF it_transport_objects,
|
||||
lt_items TYPE ty_files_item_tt,
|
||||
ls_file LIKE LINE OF lt_items,
|
||||
ls_item TYPE string,
|
||||
lv_branch_name TYPE string,
|
||||
ls_comment TYPE ty_comment.
|
||||
lo_repository TYPE REF TO lcl_repo_online,
|
||||
lo_transport_to_branch TYPE REF TO lcl_transport_to_branch.
|
||||
|
||||
BREAK copat.
|
||||
lo_repo ?= lcl_app=>repo_srv( )->get( iv_repository_key ).
|
||||
|
||||
lv_branch_name = lcl_git_branch_list=>complete_heads_branch_name(
|
||||
lcl_git_branch_list=>normalize_branch_name( is_branch_pull_request-branch_name ) ).
|
||||
|
||||
ASSERT lv_branch_name CP 'refs/heads/+*'.
|
||||
|
||||
lcl_git_porcelain=>create_branch(
|
||||
io_repo = lo_repo
|
||||
iv_name = lv_branch_name
|
||||
iv_from = lo_repo->get_sha1_local( ) ).
|
||||
|
||||
lo_repo->set_branch_name( lv_branch_name ).
|
||||
|
||||
DATA lo_stage TYPE REF TO lcl_stage.
|
||||
CREATE OBJECT lo_stage
|
||||
EXPORTING
|
||||
iv_branch_name = lv_branch_name
|
||||
iv_branch_sha1 = lo_repo->get_sha1_remote( ).
|
||||
|
||||
DATA: ls_stage_files TYPE ty_stage_files.
|
||||
|
||||
|
||||
ls_stage_files = lcl_stage_logic=>get( lo_repo ).
|
||||
|
||||
LOOP AT ls_stage_files-local INTO ls_file.
|
||||
lo_stage->add(
|
||||
iv_path = ls_file-file-path
|
||||
iv_filename = ls_file-file-filename
|
||||
iv_data = ls_file-file-data
|
||||
).
|
||||
ENDLOOP.
|
||||
|
||||
DATA ls_remote_file LIKE line of ls_stage_files-remote.
|
||||
|
||||
LOOP AT ls_stage_files-remote INTO ls_remote_file.
|
||||
lo_stage->rm(
|
||||
iv_path = ls_remote_file-path
|
||||
iv_filename = ls_remote_file-filename
|
||||
).
|
||||
endloop.
|
||||
* CATCH lcx_exception. "
|
||||
|
||||
FIELD-SYMBOLS: <ls_local> LIKE LINE OF ls_stage_files-local.
|
||||
|
||||
READ TABLE ls_stage_files-local INDEX 1 ASSIGNING <ls_local>.
|
||||
IF sy-subrc <> 0.
|
||||
EXIT.
|
||||
ENDIF.
|
||||
|
||||
CLEAR ls_comment.
|
||||
ls_comment-committer-name = lcl_objects=>changed_by( <ls_local>-item ).
|
||||
ls_comment-committer-email = |{ ls_comment-committer-name }@localhost|.
|
||||
ls_comment-comment = is_branch_pull_request-commit_text.
|
||||
|
||||
lo_repo->push( is_comment = ls_comment
|
||||
io_stage = lo_stage ).
|
||||
|
||||
|
||||
"lo_repo->push
|
||||
lo_repository ?= lcl_app=>repo_srv( )->get( iv_repository_key ).
|
||||
CREATE OBJECT lo_transport_to_branch.
|
||||
lo_transport_to_branch->create(
|
||||
io_repository = lo_repository
|
||||
is_transport_to_branch = is_transport_to_branch
|
||||
it_transport_objects = it_transport_objects ).
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS. "lcl_services_repo
|
||||
|
|
124
src/zabapgit_services_trans_branch.prog.abap
Normal file
124
src/zabapgit_services_trans_branch.prog.abap
Normal file
|
@ -0,0 +1,124 @@
|
|||
*&---------------------------------------------------------------------*
|
||||
*& Include zabapgit_services_trans_branch
|
||||
*&---------------------------------------------------------------------*
|
||||
CLASS lcl_transport_to_branch DEFINITION.
|
||||
PUBLIC SECTION.
|
||||
METHODS:
|
||||
create
|
||||
IMPORTING io_repository TYPE REF TO lcl_repo_online
|
||||
is_transport_to_branch TYPE ty_transport_to_branch
|
||||
it_transport_objects TYPE scts_tadir
|
||||
RAISING lcx_exception.
|
||||
PRIVATE SECTION.
|
||||
|
||||
METHODS craete_new_branch
|
||||
IMPORTING
|
||||
io_repository TYPE REF TO lcl_repo_online
|
||||
iv_branch_name TYPE string
|
||||
RAISING
|
||||
lcx_exception.
|
||||
METHODS add_new_and_changes_to_stage
|
||||
IMPORTING
|
||||
it_transport_objects TYPE scts_tadir
|
||||
io_stage TYPE REF TO lcl_stage
|
||||
is_stage_objects TYPE ty_stage_files
|
||||
RAISING
|
||||
lcx_exception.
|
||||
METHODS generate_commit_message
|
||||
IMPORTING
|
||||
is_transport_to_branch TYPE ty_transport_to_branch
|
||||
RETURNING
|
||||
VALUE(rs_comment) TYPE ty_comment.
|
||||
ENDCLASS.
|
||||
|
||||
CLASS lcl_transport_to_branch IMPLEMENTATION.
|
||||
|
||||
METHOD create.
|
||||
DATA:
|
||||
ls_transport_object TYPE LINE OF scts_tadir,
|
||||
lt_items TYPE ty_files_item_tt,
|
||||
ls_local_file TYPE LINE OF ty_files_item_tt,
|
||||
ls_remote_file TYPE LINE OF ty_files_tt,
|
||||
ls_item TYPE string,
|
||||
lv_branch_name TYPE string,
|
||||
ls_comment TYPE ty_comment,
|
||||
lo_stage TYPE REF TO lcl_stage,
|
||||
ls_stage_objects TYPE ty_stage_files.
|
||||
|
||||
lv_branch_name = lcl_git_branch_list=>complete_heads_branch_name(
|
||||
lcl_git_branch_list=>normalize_branch_name( is_transport_to_branch-branch_name ) ).
|
||||
|
||||
craete_new_branch(
|
||||
io_repository = io_repository
|
||||
iv_branch_name = lv_branch_name ).
|
||||
|
||||
CREATE OBJECT lo_stage
|
||||
EXPORTING
|
||||
iv_branch_name = lv_branch_name
|
||||
iv_branch_sha1 = io_repository->get_sha1_remote( ).
|
||||
|
||||
ls_stage_objects = lcl_stage_logic=>get( io_repository ).
|
||||
|
||||
add_new_and_changes_to_stage(
|
||||
it_transport_objects = it_transport_objects
|
||||
io_stage = lo_stage
|
||||
is_stage_objects = ls_stage_objects ).
|
||||
|
||||
"Stage remote files as removal, for they could be deleted
|
||||
LOOP AT ls_stage_objects-remote INTO ls_remote_file.
|
||||
lo_stage->rm(
|
||||
iv_path = ls_remote_file-path
|
||||
iv_filename = ls_remote_file-filename ).
|
||||
ENDLOOP.
|
||||
|
||||
ls_comment = generate_commit_message( is_transport_to_branch ).
|
||||
|
||||
io_repository->push( is_comment = ls_comment
|
||||
io_stage = lo_stage ).
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD craete_new_branch.
|
||||
|
||||
ASSERT iv_branch_name CP 'refs/heads/+*'.
|
||||
TRY.
|
||||
lcl_git_porcelain=>create_branch(
|
||||
io_repo = io_repository
|
||||
iv_name = iv_branch_name
|
||||
iv_from = io_repository->get_sha1_local( ) ).
|
||||
|
||||
io_repository->set_branch_name( iv_branch_name ).
|
||||
CATCH lcx_exception.
|
||||
lcx_exception=>raise( 'Error when creating new branch').
|
||||
ENDTRY.
|
||||
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD add_new_and_changes_to_stage.
|
||||
DATA ls_transport_object TYPE tadir.
|
||||
DATA ls_local_file TYPE ty_file_item.
|
||||
|
||||
LOOP AT it_transport_objects INTO ls_transport_object.
|
||||
IF ls_transport_object-delflag = abap_false.
|
||||
LOOP AT is_stage_objects-local
|
||||
INTO ls_local_file
|
||||
WHERE item-obj_name = ls_transport_object-obj_name.
|
||||
"Looping is needed to also add XMLs, other includes (e.g. local class implementation)
|
||||
io_stage->add(
|
||||
iv_path = ls_local_file-file-path
|
||||
iv_filename = ls_local_file-file-filename
|
||||
iv_data = ls_local_file-file-data ).
|
||||
ENDLOOP.
|
||||
ENDIF.
|
||||
ENDLOOP.
|
||||
ENDMETHOD.
|
||||
|
||||
|
||||
METHOD generate_commit_message.
|
||||
rs_comment-committer-name = sy-uname.
|
||||
rs_comment-committer-email = |{ rs_comment-committer-name }@localhost|.
|
||||
rs_comment-comment = is_transport_to_branch-commit_text.
|
||||
ENDMETHOD.
|
||||
|
||||
ENDCLASS.
|
25
src/zabapgit_services_trans_branch.prog.xml
Normal file
25
src/zabapgit_services_trans_branch.prog.xml
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<abapGit version="v1.0.0" serializer="LCL_OBJECT_PROG" serializer_version="v1.0.0">
|
||||
<asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
|
||||
<asx:values>
|
||||
<PROGDIR>
|
||||
<NAME>ZABAPGIT_SERVICES_TRANS_BRANCH</NAME>
|
||||
<STATE>A</STATE>
|
||||
<VARCL>X</VARCL>
|
||||
<DBAPL>S</DBAPL>
|
||||
<DBNA>D$</DBNA>
|
||||
<SUBC>I</SUBC>
|
||||
<FIXPT>X</FIXPT>
|
||||
<LDBNAME>D$S</LDBNAME>
|
||||
<UCCHECK>X</UCCHECK>
|
||||
</PROGDIR>
|
||||
<TPOOL>
|
||||
<item>
|
||||
<ID>R</ID>
|
||||
<ENTRY>Include ZABAPGIT_SERVICSE_TRANS_BRANCH</ENTRY>
|
||||
<LENGTH>38</LENGTH>
|
||||
</item>
|
||||
</TPOOL>
|
||||
</asx:values>
|
||||
</asx:abap>
|
||||
</abapGit>
|
|
@ -225,9 +225,5 @@ CLASS lcl_transport_popup IMPLEMENTATION.
|
|||
IF sy-subrc <> 0.
|
||||
RETURN.
|
||||
ENDIF.
|
||||
|
||||
break copat.
|
||||
"LEAVE TO SCREEN 1001.
|
||||
|
||||
ENDMETHOD.
|
||||
ENDCLASS.
|
||||
|
|
|
@ -309,8 +309,8 @@ CLASS lcl_gui_view_repo_content IMPLEMENTATION.
|
|||
iv_act = |{ gc_action-repo_remote_detach }?{ lv_key }| ).
|
||||
lo_tb_advanced->add( iv_txt = 'Force stage'
|
||||
iv_act = |{ gc_action-go_stage }?{ lv_key }| ).
|
||||
lo_tb_advanced->add( iv_txt = 'Transport to Pull Request'
|
||||
iv_act = |{ gc_action-repo_transport_to_pull_reqst }?{ lv_key }| ).
|
||||
lo_tb_advanced->add( iv_txt = 'Transport to Branch'
|
||||
iv_act = |{ gc_action-repo_transport_to_branch }?{ lv_key }| ).
|
||||
ELSE.
|
||||
lo_tb_advanced->add( iv_txt = 'Make on-line'
|
||||
iv_act = |{ gc_action-repo_remote_attach }?{ lv_key }| ).
|
||||
|
|
Loading…
Reference in New Issue
Block a user