public int commit ( ) throws GitSubsystemException { int committed = lockAnd ( me -> { final int size = changelogEntries . size ( ) ; if ( ! changelogEntries . isEmpty ( ) ) { try { CommitCommand commit = git . commit ( ) ; StringBuilder sb = new StringBuilder ( ) . append ( COMMIT_CHANGELOG_ENTRIES + "\n\n" ) ; for ( ChangelogEntry et : changelogEntries ) { sb . append ( et . getUsername ( ) + " " + et . getTimestamp ( ) + " " + et . getMessage ( ) ) ; sb . append ( "\n\n" ) ; } String message = sb . toString ( ) ; logger . info ( message ) ; commit . setMessage ( message ) . setAuthor ( SYSTEM_USER , email ) . call ( ) ; changelogEntries . clear ( ) ; } catch ( final JGitInternalException | GitAPIException e ) { throw new GitSubsystemException ( "Cannot commit to git: " + e . getMessage ( ) , e ) ; } } return size ; } ) ; return committed ; }
Commit the changelog entries