@@ -87,13 +87,16 @@ public Project createEngagement(Engagement engagement, String author, String aut
87
87
Project project = createProjectStucture (engagement );
88
88
engagement .setProjectId (project .getId ());
89
89
90
+ // get commit message before creating file
91
+ Optional <String > commitMessageOptional = Optional .ofNullable (engagement .getCommitMessage ());
92
+
90
93
// get all template files
91
94
List <File > repoFiles = new ArrayList <>();
92
95
repoFiles .add (createEngagmentFile (engagement ));
93
96
94
97
// create actions for multiple commit
95
98
CommitMultiple commit = createCommitMultiple (repoFiles , project .getId (), DEFAULT_BRANCH , author ,
96
- authorEmail , project .isFirst ());
99
+ authorEmail , project .isFirst (), commitMessageOptional );
97
100
98
101
if (LOGGER .isDebugEnabled ()) {
99
102
commit .getActions ().stream ().forEach (file -> LOGGER .debug ("Action File path :: {}" , file .getFilePath ()));
@@ -242,6 +245,7 @@ private File createEngagmentFile(Engagement engagement) {
242
245
//Git api is read only here.
243
246
engagement .setCommits (null );
244
247
engagement .setStatus (null );
248
+ engagement .setCommitMessage (null );
245
249
246
250
String fileContent = json .toJson (engagement );
247
251
return File .builder ().content (fileContent ).filePath (ENGAGEMENT_FILE ).build ();
@@ -312,15 +316,17 @@ private Project getOrCreateProject(Integer namespaceId, String projectName, Proj
312
316
}
313
317
314
318
private CommitMultiple createCommitMultiple (List <File > filesToCommit , Integer projectId , String branch ,
315
- String authorName , String authorEmail , boolean isNew ) {
319
+ String authorName , String authorEmail , boolean isNew , Optional < String > commitMessageOptional ) {
316
320
317
321
List <Action > actions = new ArrayList <>();
318
322
319
323
// convert each file to action - parallelStream was bringing inconsistent
320
324
// results
321
325
filesToCommit .stream ().forEach (file -> actions .add (createAction (file , isNew )));
322
-
323
- String commitMessage = isNew ? commitMessage ("Engagement created" ) : commitMessage ("Engagement updated" );
326
+
327
+ // use message if provided. otherwise, defaults
328
+ String commitMessage = commitMessageOptional
329
+ .orElse (isNew ? commitMessage ("Engagement created" ) : commitMessage ("Engagement updated" ));
324
330
325
331
return CommitMultiple .builder ().id (projectId ).branch (branch ).commitMessage (commitMessage ).actions (actions )
326
332
.authorName (authorName ).authorEmail (authorEmail ).build ();
0 commit comments