Skip to content

Commit

Permalink
feat: add the ability to disable text wrap
Browse files Browse the repository at this point in the history
Closes #14
  • Loading branch information
darrachequesne committed Nov 2, 2020
1 parent 73627cf commit 42530f4
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 15 deletions.
9 changes: 6 additions & 3 deletions src/com/leroymerlin/commit/CommitMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,22 @@ class CommitMessage {

private ChangeType changeType;
private String changeScope, shortDescription, longDescription, breakingChanges, closedIssues;
private boolean wrapText = true;

private CommitMessage() {
this.longDescription = "";
this.breakingChanges = "";
this.closedIssues = "";
}

public CommitMessage(ChangeType changeType, String changeScope, String shortDescription, String longDescription, String breakingChanges, String closedIssues) {
public CommitMessage(ChangeType changeType, String changeScope, String shortDescription, String longDescription, String breakingChanges, String closedIssues, boolean wrapText) {
this.changeType = changeType;
this.changeScope = changeScope;
this.shortDescription = shortDescription;
this.longDescription = longDescription;
this.breakingChanges = breakingChanges;
this.closedIssues = closedIssues;
this.wrapText = wrapText;
}

@Override
Expand All @@ -53,14 +55,15 @@ public String toString() {
builder
.append(System.lineSeparator())
.append(System.lineSeparator())
.append(WordUtils.wrap(longDescription, MAX_LINE_LENGTH));
.append(wrapText ? WordUtils.wrap(longDescription, MAX_LINE_LENGTH) : longDescription);
}

if (isNotBlank(breakingChanges)) {
String content = "BREAKING CHANGE: " + breakingChanges;
builder
.append(System.lineSeparator())
.append(System.lineSeparator())
.append(WordUtils.wrap("BREAKING CHANGE: " + breakingChanges, MAX_LINE_LENGTH));
.append(wrapText ? WordUtils.wrap(content, MAX_LINE_LENGTH) : content);
}

if (isNotBlank(closedIssues)) {
Expand Down
23 changes: 17 additions & 6 deletions src/com/leroymerlin/commit/CommitPanel.form
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.leroymerlin.commit.CommitPanel">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="7" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="27dc6" binding="mainPanel" layout-manager="GridLayoutManager" row-count="8" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<xy x="20" y="20" width="954" height="629"/>
Expand All @@ -10,7 +10,7 @@
<children>
<vspacer id="80732">
<constraints>
<grid row="6" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="8bb2e" class="javax.swing.JLabel">
Expand Down Expand Up @@ -76,7 +76,7 @@
</component>
<component id="83b17" class="javax.swing.JLabel">
<constraints>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Closed issues"/>
Expand All @@ -93,30 +93,41 @@
</component>
<component id="73448" class="javax.swing.JTextField" binding="closedIssues">
<constraints>
<grid row="5" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="6" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="c313a" class="javax.swing.JLabel">
<constraints>
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="5" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Breaking changes"/>
</properties>
</component>
<component id="15a33" class="javax.swing.JTextArea" binding="breakingChanges">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="5" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties>
<lineWrap value="true"/>
</properties>
</component>
<component id="fa59e" class="javax.swing.JCheckBox" binding="wrapTextCheckBox">
<constraints>
<grid row="4" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<actionCommand value="Wrap text at 72 characters?"/>
<autoscrolls value="false"/>
<selected value="true"/>
<text value="Wrap at 72 characters?"/>
</properties>
</component>
</children>
</grid>
</form>
4 changes: 3 additions & 1 deletion src/com/leroymerlin/commit/CommitPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class CommitPanel {
private JTextArea longDescription;
private JTextArea breakingChanges;
private JTextField closedIssues;
private JCheckBox wrapTextCheckBox;

CommitPanel(Project project, CommitMessage commitMessage) {
for (ChangeType type : ChangeType.values()) {
Expand Down Expand Up @@ -45,7 +46,8 @@ CommitMessage getCommitMessage() {
shortDescription.getText().trim(),
longDescription.getText().trim(),
breakingChanges.getText().trim(),
closedIssues.getText().trim()
closedIssues.getText().trim(),
wrapTextCheckBox.isSelected()
);
}

Expand Down
20 changes: 15 additions & 5 deletions tests/com/leroymerlin/commit/CommitMessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public void testFormatCommit() {
CommitMessage commitMessage = new CommitMessage(ChangeType.FIX, "ngStyle",
"skip setting empty value when new style has the property",
"Previously, all the properties in oldStyles are set to empty value once. Using AngularJS with jQuery 3.3.1, this disables the CSS transition as reported in jquery/jquery#4185.",
null, "#16709");
null, "#16709", true);
String expected = "fix(ngStyle): skip setting empty value when new style has the property\n" +
"\n" +
"Previously, all the properties in oldStyles are set to empty value once.\n" +
Expand All @@ -25,7 +25,7 @@ public void testFormatCommit() {
@Test
public void testFormatCommit_withoutScope() {
CommitMessage commitMessage = new CommitMessage(ChangeType.STYLE, null,
"fix eslint error", null, null, "");
"fix eslint error", null, null, "", true);
String expected = "style: fix eslint error";
check(commitMessage, expected);
}
Expand All @@ -35,7 +35,7 @@ public void testFormatCommit_withMultipleClosedIssues() {
CommitMessage commitMessage = new CommitMessage(ChangeType.FEAT, "$route",
"add support for the `reloadOnUrl` configuration option",
"Enables users to specify that a particular route should not be reloaded after a URL change.",
"", "#7925,#15002");
"", "#7925,#15002", true);
String expected = "feat($route): add support for the `reloadOnUrl` configuration option\n" +
"\n" +
"Enables users to specify that a particular route should not be reloaded\n" +
Expand All @@ -49,7 +49,7 @@ public void testFormatCommit_withMultipleClosedIssues() {
@Test
public void testFormatCommit_withLongBreakingChange() {
CommitMessage commitMessage = new CommitMessage(ChangeType.FEAT, null, "break everything", null,
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "");
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "", true);
String expected = "feat: break everything\n" +
"\n" +
"BREAKING CHANGE: Lorem ipsum dolor sit amet, consectetur adipiscing\n" +
Expand All @@ -73,7 +73,7 @@ public void testFormatCommit_addNumberSignIfMissing() {
CommitMessage commitMessage = new CommitMessage(ChangeType.FEAT, "$route",
"add support for the `reloadOnUrl` configuration option",
"",
"", "7925, #15002 , https://github.com/o/r/issues/15003 ");
"", "7925, #15002 , https://github.com/o/r/issues/15003 ", true);
String expected = "feat($route): add support for the `reloadOnUrl` configuration option\n" +
"\n" +
"Closes #7925\n" +
Expand All @@ -82,6 +82,16 @@ public void testFormatCommit_addNumberSignIfMissing() {
assertEquals(expected, commitMessage.toString());
}

@Test
public void testFormatCommit_noWrap() {
CommitMessage commitMessage = new CommitMessage(ChangeType.FEAT, null, "break everything", null,
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.", "", false);
String expected = "feat: break everything\n" +
"\n" +
"BREAKING CHANGE: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
check(commitMessage, expected);
}

private void check(CommitMessage commitMessage, String output) {
checkFormat(commitMessage, output);
checkParse(commitMessage, output);
Expand Down

0 comments on commit 42530f4

Please sign in to comment.