Skip to content

Commit b4c53c9

Browse files
authored
Merge pull request #95 from dwasinge/commit-msg
Use Commit Message if Provided
2 parents 8fc7f03 + 13ba341 commit b4c53c9

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-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: 10 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()));
@@ -242,6 +245,7 @@ private File createEngagmentFile(Engagement engagement) {
242245
//Git api is read only here.
243246
engagement.setCommits(null);
244247
engagement.setStatus(null);
248+
engagement.setCommitMessage(null);
245249

246250
String fileContent = json.toJson(engagement);
247251
return File.builder().content(fileContent).filePath(ENGAGEMENT_FILE).build();
@@ -312,15 +316,17 @@ private Project getOrCreateProject(Integer namespaceId, String projectName, Proj
312316
}
313317

314318
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) {
316320

317321
List<Action> actions = new ArrayList<>();
318322

319323
// convert each file to action - parallelStream was bringing inconsistent
320324
// results
321325
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"));
324330

325331
return CommitMultiple.builder().id(projectId).branch(branch).commitMessage(commitMessage).actions(actions)
326332
.authorName(authorName).authorEmail(authorEmail).build();

0 commit comments

Comments
 (0)