/*
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.groboclown.idea.p4ic.v2.server.util;

import com.intellij.openapi.vcs.changes.ChangeList;
import org.jetbrains.annotations.NotNull;

public class ChangelistDescriptionGenerator {
    public static String getDescription(@NotNull ChangeList ideaChange) {
        StringBuilder sb = new StringBuilder();
        if (ideaChange.getName().length() > 0) {
            sb.append(ideaChange.getName());
            if (ideaChange.getComment() != null && ideaChange.getComment().length() > 0) {
                sb.append("\n\n");
            }
        }
        if (ideaChange.getComment() != null && ideaChange.getComment().length() > 0) {
            sb.append(ideaChange.getComment());
        }
        return sb.toString();
    }
}

@@ -832,24 +832,276 @@
 aChange) %7B%0D%0A
+        // Bug #91: if both %22name%22 and %22comment%22 are specified, then the changelist will use both%0D%0A        // the name and the description for the comment.  Instead, this should match the %22submit%22%0D%0A        // functionality and only use the comment.%0D%0A%0D%0A
         Stri
@@ -1229,32 +1229,39 @@
 etName());%0D%0A    
+    %7D%0D%0A
         if (idea
@@ -1348,66 +1348,150 @@
     
-    sb.append(%22%5Cn%5Cn%22);%0D%0A            %7D%0D%0A        %7D%0D%0A
+String comment = ideaChange.getComment();%0D%0A            if (sb.length() %3E 0) %7B%0D%0A%0D%0A%0D%0A                String head = sb.toString();%0D%0A     
         
 if (
@@ -1490,86 +1490,393 @@
     
+   
 if (
-ideaChange.getC
+head.endsWith(%22...%22)) %7B%0D%0A                    head = head.substring(0, head.length() - 3);%0D%0A                %7D%0D%0A                if (head.trim().equalsIgnoreCase(c
 omment
-() != null && ideaChange.getComment().length() %3E 0) %7B
+)) %7B%0D%0A                    // Just use the comment, not the name + comment.%0D%0A                    sb.setLength(0);%0D%0A                %7D else %7B%0D%0A                    sb.append(%22%5Cn%5Cn%22);%0D%0A                %7D%0D%0A            %7D
 %0D%0A  

Fix the changelist name/comment concatenation issue (#91)