来源资料待手动核验
项目简介
CommitLinter for abapGit
CommitLinter for abapGit
License: MIT Code Statistics
This repo allows abapGit to check if commit message complies with the commit rules defined per each repo.
Use abapgit for installing this repo and then implement described userExits.
This repo uses following abapgit UserExits:
METHOD zif_abapgit_exit~validate_before_push.
TRY.
DATA(lo_commit_linter) = zcl_abapgit_commitlint=>get_linter( io_repo ).
IF lo_commit_linter IS BOUND.
DATA(lo_commitlint_engine) = NEW zcl_abapgit_commitlint( is_comment = is_comment
io_repo = io_repo
io_linter = lo_commit_linter ).
lo_commitlint_engine->validate( ).
IF lo_commitlint_engine->has_errors( ) = abap_true.
zcl_abapgit_commitlint_ui=>display_log( lo_commitlint_engine->get_log( ) ).
IF zcl_abapgit_commitlint=>is_push_allowed_with_errors( io_repo ) = abap_false.
"Abort commit
zcx_abapgit_exception=>raise(
EXPORTING
iv_text = 'Commit message does not stick to the rules.' ).
ENDIF.
ENDIF.
ENDIF.
CATCH zcx_abapgit_commitlint INTO DATA(lo_exception).
zcx_abapgit_exception=>raise(
EXPORTING
iv_text = lo_exception->get_text( )
ix_previous = lo_exception ).
ENDTRY.
ENDMETHOD.Example of wrong commit message
METHOD zif_abapgit_exit~enhance_repo_toolbar.
io_menu->add( iv_txt = 'CommitLint'
iv_act = |{ zcl_abapgit_commitlint_page=>mc_id }?key={ iv_key }|
iv_cur = boolc( iv_act = zcl_abapgit_commitlint_page=>mc_id ) ).
ENDMETHOD.METHOD zif_abapgit_exit~on_event.
CASE ii_event->mv_action.
WHEN 'commitlint'.
TRY.
DATA(lv_key) = ii_event->query( )->get( 'KEY' ).
IF lv_key IS NOT INITIAL.
DATA(lo_repo) = CAST zcl_abapgit_repo( zcl_abapgit_repo_srv=>get_instance( )->get( CONV #( lv_key ) ) ).
ENDIF.
rs_handled-page = zcl_abapgit_commitlint_page=>create( lo_repo ).
rs_handled-state = zcl_abapgit_gui=>c_event_state-new_page.
CATCH zcx_abapgit_commitlint INTO DATA(lo_exception).
zcx_abapgit_exception=>raise( iv_text = lo_exception->get_text( )
ix_previous = lo_exception ).
ENDTRY.
ENDCASE.
ENDMETHOD.Example of wrong commit message
By default, this repo uses an implementation of conventional commit so ZCLABAPGITCOMMITLINT instantiates ZCLABAPGITCOMMITLINTSRV which executes a NodeJS application (see abap-srv-commitlint) where the rule validations are executed.
Ensuring that your commit messages stick to a predefined rule, you could even automate your CHANGELOGs by having the corresponding pipeline in place :wink: There are quite few libraries out there but to provide an example have a look at commitizen.