1 files changed, 7 insertions(+), 24 deletions(-)

M googlechat.groovy
M googlechat.groovy +7 -24
@@ 68,32 68,16 @@ def String getWebhookUrl(Issue issue, Lo
 	// Returns null if anything fails.
 }
 
-def debugMessages(IssueEvent event) {
-	log "--------------------------------------";
-	log "event: ${event?.getClass()}";
-	log "event.issue: ${event.issue.getClass()}";
-	log "event.comment: ${event.comment?.body}";
-	log "event.changeLog: is ${event?.changeLog?.getClass()}";
-	log "event.comment: is ${event.comment?.getClass()}";
-	log "Event methods:";
-	log(event.metaClass.methods*.name.sort().unique()  );
-	if (event?.changeLog) {
-		log "changeitems: ${event.changeLog.getRelated('ChildChangeItem').getClass()}";
-		event.changeLog.getRelated("ChildChangeItem").each {
-			def ci = it as GenericValue;
-			log "Change: ${ci.getString('oldstring')} → ${ci.getString('newstring')}";
-		}
-	}
-}
-
 def String getBaseUrl() {
 	// https://community.atlassian.com/t5/Answers-Developer-Questions/How-do-I-programatically-find-JIRA-s-base-URL/qaq-p/519640
 	return ComponentAccessor.getApplicationProperties().getString("jira.baseurl");
 }
 
+/** Sends a message to a webhook. */
 def messageWebhook(String webhookUrl, ChatMessage message) {
-	log "JSON: ${message.toJSON()}";
+	//log "JSON: ${message.toJSON()}";
 
+	// Give each issue its own gchat 'thread', for grouping
 	def threadKey = baseUrl.replaceAll("https://", '') + "-" + event.issue.key;
 	URIBuilder uriBuilder = new URIBuilder(webhookUrl).addQueryParam("threadKey", threadKey);
 	log.debug "Built URL ${uriBuilder}";

          
@@ 109,8 93,6 @@ def messageWebhook(String webhookUrl, Ch
 		request.getParams().setParameter("http.connection.timeout", 5000);
 		requestContentType = ContentType.JSON;
 		request.addHeader("Content-Type", "application/json; charset=UTF-8");
-		//body = new JsonBuilder( ['text': messageText] ).toString()
-		// https://developers.google.com/hangouts/chat/reference/message-formats/cards
 
 		body = message.toJSON();
 

          
@@ 125,7 107,7 @@ def messageWebhook(String webhookUrl, Ch
 	}
 }
 
-/** Classes implementing a toJSON() method, generating Hangout Chat message format (https://developers.google.com/hangouts/chat/reference/message-formats/).
+/** Represents an abstract GChat message. Concrete implementations should pick a representation (https://developers.google.com/hangouts/chat/reference/message-formats/).
  */
 abstract class ChatMessage {
 	abstract String toJSON();

          
@@ 210,7 192,6 @@ class SimpleChatMessage extends ChatMess
 		return ComponentAccessor.eventTypeManager.getEventType(event.getEventTypeId()).getName();
 	}
 
-
 	String keyValue(key, value)
 	{
 		if (value != null) {

          
@@ 218,6 199,7 @@ class SimpleChatMessage extends ChatMess
 		} else { null }
 	}
 
+	/** Convert from Jira wiki format to GChat format. */
 	public String reformat(String text) {
 		text?.
 			replaceAll(~"\\{quote\\}\\r?", '```')?.

          
@@ 264,8 246,9 @@ class SimpleChatMessage extends ChatMess
 			def formattedComment = reformat(event.comment?.body);
 			if (event?.changeLog) { 
 				return '`Comment` ' + formattedComment;
-			} else 
+			} else {
 				return formattedComment;
+			}
 		}
 	}