All files / test/src zcl_abapgit_gitea.clas.abap

100% Statements 69/69
100% Branches 0/0
100% Functions 0/0
100% Lines 69/69

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 701x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 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_gitea DEFINITION PUBLIC.
  PUBLIC SECTION.
    CLASS-METHODS create_repo
      IMPORTING
        iv_name       TYPE string
      RETURNING
        VALUE(rv_url) TYPE string
      RAISING
        zcx_abapgit_exception.
 
  PRIVATE SECTION.
    CONSTANTS c_base TYPE string VALUE 'http://localhost:3050'.
    CONSTANTS c_username TYPE string VALUE 'abapgit'.
    CONSTANTS c_password TYPE string VALUE 'abapgit'.
ENDCLASS.
 
CLASS zcl_abapgit_gitea IMPLEMENTATION.
  METHOD create_repo.
 
    DATA li_agent    TYPE REF TO zif_abapgit_http_agent.
    DATA li_response TYPE REF TO zif_abapgit_http_response.
    DATA lv_json     TYPE string.
    DATA lv_url      TYPE string.
 
 
    li_agent = zcl_abapgit_http_agent=>create( ).
 
    li_agent->global_headers( )->set(
      iv_key = 'Accept'
      iv_val = 'application/json' ).
 
    li_agent->global_headers( )->set(
      iv_key = 'Content-Type'
      iv_val = 'application/json' ).
 
    lv_url = c_base && '/api/v1/user/repos'.
 
    zcl_abapgit_login_manager=>set(
      iv_uri      = lv_url
      iv_username = c_username
      iv_password = c_password ).
 
    li_agent->global_headers( )->set(
      iv_key = 'Authorization'
      iv_val = zcl_abapgit_login_manager=>get( lv_url ) ).
 
    lv_json = `{` && |\n| &&
      `  "auto_init": true,` && |\n| &&
      `  "default_branch": "main",` && |\n| &&
      `  "description": "description",` && |\n| &&
      `  "license": "MIT",` && |\n| &&
      `  "name": "` && iv_name && `",` && |\n| &&
      `  "private": false,` && |\n| &&
      `  "trust_model": "default"` && |\n| &&
      `}`.
 
    li_response = li_agent->request(
      iv_url     = lv_url
      iv_method  = 'POST'
      iv_payload = lv_json ).
 
    IF li_response->code( ) <> 201.
      zcx_abapgit_exception=>raise( |Error creating repository| ).
    ENDIF.
 
    rv_url = |{ c_base }/abapgit/{ iv_name }|.
 
  ENDMETHOD.
ENDCLASS.