Skip to content

Commit e8add01

Browse files
committed
use commit message if specified
1 parent 8fc7f03 commit e8add01

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

src/main/java/com/redhat/labs/lodestar/models/Engagement.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,5 +54,6 @@ public class Engagement {
5454
private List<Category> categories;
5555

5656
private List<Artifact> artifacts;
57+
private String commitMessage;
5758

5859
}

src/main/java/com/redhat/labs/lodestar/service/EngagementService.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,16 @@ public Project createEngagement(Engagement engagement, String author, String aut
8787
Project project = createProjectStucture(engagement);
8888
engagement.setProjectId(project.getId());
8989

90+
// get commit message before creating file
91+
Optional<String> commitMessageOptional = Optional.ofNullable(engagement.getCommitMessage());
92+
9093
// get all template files
9194
List<File> repoFiles = new ArrayList<>();
9295
repoFiles.add(createEngagmentFile(engagement));
9396

9497
// create actions for multiple commit
9598
CommitMultiple commit = createCommitMultiple(repoFiles, project.getId(), DEFAULT_BRANCH, author,
96-
authorEmail, project.isFirst());
99+
authorEmail, project.isFirst(), commitMessageOptional);
97100

98101
if (LOGGER.isDebugEnabled()) {
99102
commit.getActions().stream().forEach(file -> LOGGER.debug("Action File path :: {}", file.getFilePath()));
@@ -312,15 +315,17 @@ private Project getOrCreateProject(Integer namespaceId, String projectName, Proj
312315
}
313316

314317
private CommitMultiple createCommitMultiple(List<File> filesToCommit, Integer projectId, String branch,
315-
String authorName, String authorEmail, boolean isNew) {
318+
String authorName, String authorEmail, boolean isNew, Optional<String> commitMessageOptional) {
316319

317320
List<Action> actions = new ArrayList<>();
318321

319322
// convert each file to action - parallelStream was bringing inconsistent
320323
// results
321324
filesToCommit.stream().forEach(file -> actions.add(createAction(file, isNew)));
322-
323-
String commitMessage = isNew ? commitMessage("Engagement created") : commitMessage("Engagement updated");
325+
326+
// use message if provided. otherwise, defaults
327+
String commitMessage = commitMessageOptional
328+
.orElse(isNew ? commitMessage("Engagement created") : commitMessage("Engagement updated"));
324329

325330
return CommitMultiple.builder().id(projectId).branch(branch).commitMessage(commitMessage).actions(actions)
326331
.authorName(authorName).authorEmail(authorEmail).build();

0 commit comments

Comments
 (0)