abapgit-agent 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,138 @@
1
+ *"*"use source
2
+ *"*"Local Interface:
3
+ *"**********************************************************************
4
+ CLASS zcl_abgagt_command_import DEFINITION PUBLIC FINAL CREATE PUBLIC.
5
+
6
+ PUBLIC SECTION.
7
+ INTERFACES zif_abgagt_command.
8
+
9
+ TYPES: BEGIN OF ty_import_params,
10
+ url TYPE string,
11
+ message TYPE string,
12
+ username TYPE string,
13
+ password TYPE string,
14
+ END OF ty_import_params.
15
+
16
+ ENDCLASS.
17
+
18
+ CLASS zcl_abgagt_command_import IMPLEMENTATION.
19
+
20
+ METHOD zif_abgagt_command~get_name.
21
+ rv_name = 'IMPORT'.
22
+ ENDMETHOD.
23
+
24
+ METHOD zif_abgagt_command~execute.
25
+ DATA: ls_params TYPE ty_import_params,
26
+ li_repo TYPE REF TO zif_abapgit_repo,
27
+ li_repo_online TYPE REF TO zif_abapgit_repo_online,
28
+ lo_stage TYPE REF TO zcl_abapgit_stage,
29
+ lt_files TYPE zif_abapgit_definitions=>ty_files_item_tt,
30
+ lv_package TYPE devclass,
31
+ lv_message TYPE string,
32
+ lv_files_staged TYPE i.
33
+
34
+ " Use separate variables to avoid inline DATA issues
35
+ DATA: li_user TYPE REF TO zif_abapgit_persist_user,
36
+ lv_committer_name TYPE string,
37
+ lv_committer_email TYPE string.
38
+
39
+ TRY.
40
+ IF is_param IS SUPPLIED.
41
+ ls_params = CORRESPONDING #( is_param ).
42
+ ENDIF.
43
+
44
+ " Validate URL
45
+ IF ls_params-url IS INITIAL.
46
+ rv_result = '{"success":"","error":"URL is required"}'.
47
+ RETURN.
48
+ ENDIF.
49
+
50
+ " Configure credentials if provided
51
+ IF ls_params-username IS NOT INITIAL AND ls_params-password IS NOT INITIAL.
52
+ zcl_abapgit_persist_factory=>get_user( )->set_repo_git_user_name(
53
+ iv_url = ls_params-url iv_username = ls_params-username ).
54
+ zcl_abapgit_persist_factory=>get_user( )->set_repo_login(
55
+ iv_url = ls_params-url iv_login = ls_params-username ).
56
+ zcl_abapgit_login_manager=>set_basic(
57
+ iv_uri = ls_params-url
58
+ iv_username = ls_params-username
59
+ iv_password = ls_params-password ).
60
+ ENDIF.
61
+
62
+ " Find repository by URL
63
+ zcl_abapgit_repo_srv=>get_instance( )->get_repo_from_url(
64
+ EXPORTING iv_url = ls_params-url
65
+ IMPORTING ei_repo = li_repo ).
66
+
67
+ IF li_repo IS NOT BOUND.
68
+ rv_result = '{"success":"","error":"Repository not found"}'.
69
+ RETURN.
70
+ ENDIF.
71
+
72
+ " Cast to online repo for push operations
73
+ li_repo_online ?= li_repo.
74
+
75
+ " Get package from repository
76
+ lv_package = li_repo->get_package( ).
77
+
78
+ " Build commit message if not provided
79
+ IF ls_params-message IS INITIAL.
80
+ lv_message = |feat: initial import from ABAP package { lv_package }|.
81
+ ELSE.
82
+ lv_message = ls_params-message.
83
+ ENDIF.
84
+
85
+ " Refresh repository
86
+ li_repo->refresh( ).
87
+
88
+ " Get local files
89
+ lt_files = li_repo->get_files_local( ).
90
+
91
+ " Count files
92
+ lv_files_staged = lines( lt_files ).
93
+
94
+ " Check if there are files to import
95
+ IF lv_files_staged = 0.
96
+ rv_result = '{"success":"","error":"No objects found in package"}'.
97
+ RETURN.
98
+ ENDIF.
99
+
100
+ " Create stage
101
+ CREATE OBJECT lo_stage.
102
+
103
+ " Add all files to stage
104
+ LOOP AT lt_files ASSIGNING FIELD-SYMBOL(<ls_file>).
105
+ lo_stage->add(
106
+ iv_path = <ls_file>-file-path
107
+ iv_filename = <ls_file>-file-filename
108
+ iv_data = <ls_file>-file-data ).
109
+ ENDLOOP.
110
+
111
+ " Get user details for committer
112
+ li_user = zcl_abapgit_persist_factory=>get_user( ).
113
+ lv_committer_name = li_user->get_default_git_user_name( ).
114
+ lv_committer_email = li_user->get_default_git_user_email( ).
115
+
116
+ " Prepare commit
117
+ DATA: ls_comment TYPE zif_abapgit_git_definitions=>ty_comment.
118
+ ls_comment-committer-name = lv_committer_name.
119
+ ls_comment-committer-email = lv_committer_email.
120
+ ls_comment-comment = lv_message.
121
+
122
+ " Commit and push
123
+ li_repo_online->push(
124
+ is_comment = ls_comment
125
+ io_stage = lo_stage ).
126
+
127
+ COMMIT WORK.
128
+
129
+ rv_result = '{"success":"X","files_staged":"' && lv_files_staged && '","commit_message":"' && lv_message && '"}'.
130
+
131
+ CATCH zcx_abapgit_exception INTO DATA(lx_error).
132
+ rv_result = '{"success":"","error":"' && lx_error->get_text( ) && '"}'.
133
+ CATCH cx_root INTO DATA(lx_other).
134
+ rv_result = '{"success":"","error":"' && lx_other->get_text( ) && '"}'.
135
+ ENDTRY.
136
+ ENDMETHOD.
137
+
138
+ ENDCLASS.
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
3
+ <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
4
+ <asx:values>
5
+ <VSEOCLASS>
6
+ <CLSNAME>ZCL_ABGAGT_COMMAND_IMPORT</CLSNAME>
7
+ <LANGU>E</LANGU>
8
+ <DESCRIPT>Import command for ABAP Git Agent</DESCRIPT>
9
+ <EXPOSURE>2</EXPOSURE>
10
+ <STATE>1</STATE>
11
+ <UNICODE>X</UNICODE>
12
+ </VSEOCLASS>
13
+ </asx:values>
14
+ </asx:abap>
15
+ </abapGit>
@@ -0,0 +1,71 @@
1
+ *"*"use source
2
+ *"*"Local Interface:
3
+ *"**********************************************************************
4
+ CLASS zcl_abgagt_resource_create DEFINITION PUBLIC FINAL
5
+ INHERITING FROM cl_rest_resource
6
+ CREATE PUBLIC.
7
+
8
+ PUBLIC SECTION.
9
+ METHODS if_rest_resource~post REDEFINITION.
10
+
11
+ ENDCLASS.
12
+
13
+ CLASS zcl_abgagt_resource_create IMPLEMENTATION.
14
+
15
+ METHOD if_rest_resource~post.
16
+ DATA lv_json TYPE string.
17
+ lv_json = mo_request->get_entity( )->get_string_data( ).
18
+
19
+ " Parse JSON using /ui2/cl_json
20
+ DATA: BEGIN OF ls_request,
21
+ url TYPE string,
22
+ branch TYPE string,
23
+ package TYPE string,
24
+ display_name TYPE string,
25
+ name TYPE string,
26
+ folder_logic TYPE string,
27
+ folder TYPE string,
28
+ username TYPE string,
29
+ password TYPE string,
30
+ END OF ls_request.
31
+
32
+ /ui2/cl_json=>deserialize(
33
+ EXPORTING
34
+ json = lv_json
35
+ CHANGING
36
+ data = ls_request ).
37
+
38
+ " Validate required fields
39
+ IF ls_request-url IS INITIAL OR ls_request-package IS INITIAL.
40
+ DATA lv_json_resp TYPE string.
41
+ lv_json_resp = '{"success":"","error":"URL and package are required"}'.
42
+ DATA(lo_entity) = mo_response->create_entity( ).
43
+ lo_entity->set_content_type( iv_media_type = if_rest_media_type=>gc_appl_json ).
44
+ lo_entity->set_string_data( lv_json_resp ).
45
+ mo_response->set_status( cl_rest_status_code=>gc_client_error_bad_request ).
46
+ RETURN.
47
+ ENDIF.
48
+
49
+ " Get command from factory
50
+ DATA(lo_factory) = zcl_abgagt_cmd_factory=>get_instance( ).
51
+ DATA(lo_command) = lo_factory->get_command( zif_abgagt_command=>gc_create ).
52
+
53
+ IF lo_command IS NOT BOUND.
54
+ lv_json_resp = '{"success":"","error":"CREATE command not found"}'.
55
+ lo_entity = mo_response->create_entity( ).
56
+ lo_entity->set_content_type( iv_media_type = if_rest_media_type=>gc_appl_json ).
57
+ lo_entity->set_string_data( lv_json_resp ).
58
+ mo_response->set_status( cl_rest_status_code=>gc_client_error_bad_request ).
59
+ RETURN.
60
+ ENDIF.
61
+
62
+ " Execute command with is_param
63
+ DATA(lv_result) = lo_command->execute( is_param = ls_request ).
64
+
65
+ lo_entity = mo_response->create_entity( ).
66
+ lo_entity->set_content_type( iv_media_type = if_rest_media_type=>gc_appl_json ).
67
+ lo_entity->set_string_data( lv_result ).
68
+ mo_response->set_status( cl_rest_status_code=>gc_success_ok ).
69
+ ENDMETHOD.
70
+
71
+ ENDCLASS.
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
3
+ <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
4
+ <asx:values>
5
+ <VSEOCLASS>
6
+ <CLSNAME>ZCL_ABGAGT_RESOURCE_CREATE</CLSNAME>
7
+ <LANGU>E</LANGU>
8
+ <DESCRIPT>ABAP Git Agent - Create Resource</DESCRIPT>
9
+ <EXPOSURE>2</EXPOSURE>
10
+ <STATE>1</STATE>
11
+ <UNICODE>X</UNICODE>
12
+ </VSEOCLASS>
13
+ </asx:values>
14
+ </asx:abap>
15
+ </abapGit>
@@ -0,0 +1,66 @@
1
+ *"*"use source
2
+ *"*"Local Interface:
3
+ *"**********************************************************************
4
+ CLASS zcl_abgagt_resource_import DEFINITION PUBLIC FINAL
5
+ INHERITING FROM cl_rest_resource
6
+ CREATE PUBLIC.
7
+
8
+ PUBLIC SECTION.
9
+ METHODS if_rest_resource~post REDEFINITION.
10
+
11
+ ENDCLASS.
12
+
13
+ CLASS zcl_abgagt_resource_import IMPLEMENTATION.
14
+
15
+ METHOD if_rest_resource~post.
16
+ DATA lv_json TYPE string.
17
+ lv_json = mo_request->get_entity( )->get_string_data( ).
18
+
19
+ " Parse JSON using /ui2/cl_json
20
+ DATA: BEGIN OF ls_request,
21
+ url TYPE string,
22
+ message TYPE string,
23
+ username TYPE string,
24
+ password TYPE string,
25
+ END OF ls_request.
26
+
27
+ /ui2/cl_json=>deserialize(
28
+ EXPORTING
29
+ json = lv_json
30
+ CHANGING
31
+ data = ls_request ).
32
+
33
+ " Validate required fields
34
+ IF ls_request-url IS INITIAL.
35
+ DATA lv_json_resp TYPE string.
36
+ lv_json_resp = '{"success":"","error":"URL is required"}'.
37
+ DATA(lo_entity) = mo_response->create_entity( ).
38
+ lo_entity->set_content_type( iv_media_type = if_rest_media_type=>gc_appl_json ).
39
+ lo_entity->set_string_data( lv_json_resp ).
40
+ mo_response->set_status( cl_rest_status_code=>gc_client_error_bad_request ).
41
+ RETURN.
42
+ ENDIF.
43
+
44
+ " Get command from factory
45
+ DATA(lo_factory) = zcl_abgagt_cmd_factory=>get_instance( ).
46
+ DATA(lo_command) = lo_factory->get_command( zif_abgagt_command=>gc_import ).
47
+
48
+ IF lo_command IS NOT BOUND.
49
+ lv_json_resp = '{"success":"","error":"IMPORT command not found"}'.
50
+ lo_entity = mo_response->create_entity( ).
51
+ lo_entity->set_content_type( iv_media_type = if_rest_media_type=>gc_appl_json ).
52
+ lo_entity->set_string_data( lv_json_resp ).
53
+ mo_response->set_status( cl_rest_status_code=>gc_client_error_bad_request ).
54
+ RETURN.
55
+ ENDIF.
56
+
57
+ " Execute command with is_param
58
+ DATA(lv_result) = lo_command->execute( is_param = ls_request ).
59
+
60
+ lo_entity = mo_response->create_entity( ).
61
+ lo_entity->set_content_type( iv_media_type = if_rest_media_type=>gc_appl_json ).
62
+ lo_entity->set_string_data( lv_result ).
63
+ mo_response->set_status( cl_rest_status_code=>gc_success_ok ).
64
+ ENDMETHOD.
65
+
66
+ ENDCLASS.
@@ -0,0 +1,15 @@
1
+ <?xml version="1.0" encoding="utf-8"?>
2
+ <abapGit version="v1.0.0" serializer="LCL_OBJECT_CLAS" serializer_version="v1.0.0">
3
+ <asx:abap xmlns:asx="http://www.sap.com/abapxml" version="1.0">
4
+ <asx:values>
5
+ <VSEOCLASS>
6
+ <CLSNAME>ZCL_ABGAGT_RESOURCE_IMPORT</CLSNAME>
7
+ <LANGU>E</LANGU>
8
+ <DESCRIPT>REST resource handler for /import endpoint</DESCRIPT>
9
+ <EXPOSURE>2</EXPOSURE>
10
+ <STATE>1</STATE>
11
+ <UNICODE>X</UNICODE>
12
+ </VSEOCLASS>
13
+ </asx:values>
14
+ </asx:abap>
15
+ </abapGit>
@@ -20,6 +20,8 @@ CLASS zcl_abgagt_rest_handler IMPLEMENTATION.
20
20
  lo_router->attach( iv_template = '/health' iv_handler_class = 'ZCL_ABGAGT_RESOURCE_HEALTH' ).
21
21
  lo_router->attach( iv_template = '/inspect' iv_handler_class = 'ZCL_ABGAGT_RESOURCE_INSPECT' ).
22
22
  lo_router->attach( iv_template = '/unit' iv_handler_class = 'ZCL_ABGAGT_RESOURCE_UNIT' ).
23
+ lo_router->attach( iv_template = '/create' iv_handler_class = 'ZCL_ABGAGT_RESOURCE_CREATE' ).
24
+ lo_router->attach( iv_template = '/import' iv_handler_class = 'ZCL_ABGAGT_RESOURCE_IMPORT' ).
23
25
 
24
26
  ro_root_handler = lo_router.
25
27
  ENDMETHOD.
@@ -1,9 +1,6 @@
1
- " TODO: Implement detailed syntax error parsing
2
- " When a syntax error occurs, the log shows the affected object name
3
- " but not the specific line/column. For better error reporting:
4
- " - Parse the error message to extract object info
5
- " - For syntax errors, query SEPSA or TRINT_OBJECT_LOG for details
6
- " - Return structured error with line numbers and fix suggestions
1
+ " Interface for abapGit Agent - handles pull operations only.
2
+ " Note: inspect and run_tests are implemented in separate command classes
3
+ " (zcl_abgagt_command_inspect, zcl_abgagt_command_unit) using ABAP standard classes.
7
4
 
8
5
  INTERFACE zif_abgagt_agent PUBLIC.
9
6
 
@@ -34,71 +31,6 @@ INTERFACE zif_abgagt_agent PUBLIC.
34
31
  finished_at TYPE timestampl,
35
32
  END OF ty_result.
36
33
 
37
- TYPES: BEGIN OF ty_pull_params,
38
- url TYPE string,
39
- branch TYPE string,
40
- username TYPE string,
41
- password TYPE string,
42
- package TYPE devclass,
43
- folder_logic TYPE string,
44
- create_new TYPE abap_bool,
45
- END OF ty_pull_params.
46
-
47
- " Types for inspect (syntax check)
48
- TYPES: BEGIN OF ty_error,
49
- line TYPE string,
50
- column TYPE string,
51
- text TYPE string,
52
- word TYPE string,
53
- END OF ty_error.
54
-
55
- TYPES ty_errors TYPE STANDARD TABLE OF ty_error WITH NON-UNIQUE DEFAULT KEY.
56
-
57
- TYPES: BEGIN OF ty_inspect_result,
58
- success TYPE abap_bool,
59
- object_type TYPE string,
60
- object_name TYPE string,
61
- error_count TYPE i,
62
- errors TYPE ty_errors,
63
- END OF ty_inspect_result.
64
-
65
- " Types for unit tests
66
- TYPES: BEGIN OF ty_test_result,
67
- object_type TYPE string,
68
- object_name TYPE string,
69
- test_method TYPE string,
70
- status TYPE string,
71
- message TYPE string,
72
- line TYPE string,
73
- END OF ty_test_result.
74
-
75
- TYPES ty_test_results TYPE STANDARD TABLE OF ty_test_result WITH NON-UNIQUE DEFAULT KEY.
76
-
77
- TYPES: BEGIN OF ty_unit_result,
78
- success TYPE abap_bool,
79
- message TYPE string,
80
- test_count TYPE i,
81
- passed_count TYPE i,
82
- failed_count TYPE i,
83
- results TYPE ty_test_results,
84
- END OF ty_unit_result.
85
-
86
- TYPES: BEGIN OF ty_object_key,
87
- object_type TYPE string,
88
- object_name TYPE string,
89
- END OF ty_object_key.
90
-
91
- TYPES ty_object_keys TYPE STANDARD TABLE OF ty_object_key WITH NON-UNIQUE DEFAULT KEY.
92
-
93
- TYPES: ty_log_table TYPE TABLE OF string.
94
- TYPES: ty_job_status TYPE string.
95
-
96
- CONSTANTS:
97
- gc_status_pending TYPE ty_job_status VALUE 'PENDING',
98
- gc_status_running TYPE ty_job_status VALUE 'RUNNING',
99
- gc_status_completed TYPE ty_job_status VALUE 'COMPLETED',
100
- gc_status_failed TYPE ty_job_status VALUE 'FAILED'.
101
-
102
34
  METHODS pull
103
35
  IMPORTING
104
36
  iv_url TYPE string
@@ -118,17 +50,4 @@ INTERFACE zif_abgagt_agent PUBLIC.
118
50
  RETURNING
119
51
  VALUE(rv_status) TYPE string.
120
52
 
121
- METHODS inspect
122
- IMPORTING
123
- iv_file TYPE string
124
- RETURNING
125
- VALUE(rs_result) TYPE ty_inspect_result.
126
-
127
- METHODS run_tests
128
- IMPORTING
129
- iv_package TYPE devclass OPTIONAL
130
- it_objects TYPE ty_object_keys OPTIONAL
131
- RETURNING
132
- VALUE(rs_result) TYPE ty_unit_result.
133
-
134
53
  ENDINTERFACE.
@@ -5,7 +5,9 @@ INTERFACE zif_abgagt_command PUBLIC.
5
5
  CONSTANTS:
6
6
  gc_pull TYPE string VALUE 'PULL',
7
7
  gc_inspect TYPE string VALUE 'INSPECT',
8
- gc_unit TYPE string VALUE 'UNIT'.
8
+ gc_unit TYPE string VALUE 'UNIT',
9
+ gc_create TYPE string VALUE 'CREATE',
10
+ gc_import TYPE string VALUE 'IMPORT'.
9
11
 
10
12
  " Get command name
11
13
  METHODS get_name