Skip to content

Commit

Permalink
인터페이스 변경
Browse files Browse the repository at this point in the history
- Content#writeMessage(UserConfiguration) 추가
- UserConfiguration.notification -> simpleMessage 변경
  • Loading branch information
markruler committed Sep 8, 2022
1 parent 15e1fa1 commit fe6c68c
Show file tree
Hide file tree
Showing 13 changed files with 155 additions and 149 deletions.
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ stage('Notification') {
contentActionLabel: 'Go to Jenkins',
contentActionLink: env.BUILD_URL,
messages: issues,
notification: """${minute}분 뒤 'A'가 재시작됩니다.
|
|'A' will restart in ${minute} minutes.
|""".stripMargin()
simpleMessage: """${minute}분 뒤 'A'가 재시작됩니다.
|
|'A' will restart in ${minute} minutes.
|""".stripMargin()
)
}
```
Expand All @@ -85,10 +85,10 @@ naver(
channelId: env.NAVER_WORKS_CHANNEL_ID,
messageType: 'text',
// optional parameters
notification: """${minute}분 뒤 'A'가 재시작됩니다.
|
|'A' will restart in ${minute} minutes.
|""".stripMargin()
simpleMessage: """${minute}분 뒤 'A'가 재시작됩니다.
|
|'A' will restart in ${minute} minutes.
|""".stripMargin()
)
```

Expand All @@ -107,7 +107,7 @@ naver(
backgroundImageUrl: env.NAVER_WORKS_BG_URL,
contentActionLabel: 'Go to Jenkins',
contentActionLink: env.BUILD_URL,
notification: 'Changes have been deployed.'
simpleMessage: 'Changes have been deployed.'
)
```

Expand Down
14 changes: 7 additions & 7 deletions src/main/java/io/jenkins/plugins/naverworks/NaverWorks.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class NaverWorks
private final List<Map<String, String>> messages;
private final String contentActionLabel;
private final String contentActionLink;
private final String notification;
private final String simpleMessage;
private final String messageType;

@DataBoundConstructor
Expand All @@ -63,7 +63,7 @@ public NaverWorks(
List<Map<String, String>> messages,
String contentActionLabel,
String contentActionLink,
String notification,
String simpleMessage,
String messageType
) {
this.credentialId = credentialId;
Expand All @@ -72,7 +72,7 @@ public NaverWorks(
this.messages = messages;
this.contentActionLabel = contentActionLabel;
this.contentActionLink = contentActionLink;
this.notification = notification;
this.simpleMessage = simpleMessage;
this.messageType = messageType;
}

Expand Down Expand Up @@ -109,8 +109,8 @@ public String getContentActionLink() {
return contentActionLink;
}

public String getNotification() {
return notification;
public String getSimpleMessage() {
return simpleMessage;
}

public String getMessageType() {
Expand All @@ -124,7 +124,7 @@ public String toString() {
", messages=" + messages +
", contentActionLabel='" + contentActionLabel + "'" +
", contentActionLink='" + contentActionLink + "'" +
", notification='" + notification + "'" +
", simpleMessage='" + simpleMessage + "'" +
", messageType='" + messageType + "'" +
'}';
}
Expand Down Expand Up @@ -169,7 +169,7 @@ public void perform(
backgroundImageUrl,
contentActionLabel,
actionLink,
notification,
simpleMessage,
messageType);
final Message message = messageService.write(userConfiguration);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,25 @@ public class UserConfiguration {
private final String backgroundImageUrl;
private final String contentActionLabel;
private final String contentActionLink;
private final String notification;
private final String simpleMessage;
private final String messageType;

public UserConfiguration(
List<Map<String, String>> messages,
String backgroundImageUrl,
String contentActionLabel,
String contentActionLink,
String notification,
String simpleMessage,
String messageType
) {
this.messages = messages;
this.backgroundImageUrl = backgroundImageUrl;
this.contentActionLabel = contentActionLabel;
this.contentActionLink = contentActionLink;
this.notification = notification;
if (simpleMessage == null || simpleMessage.isEmpty()) {
simpleMessage = "Changes have been deployed.";
}
this.simpleMessage = simpleMessage;
this.messageType = messageType;
}

Expand All @@ -47,8 +50,8 @@ public String getContentActionLink() {
return contentActionLink;
}

public String getNotification() {
return notification;
public String getSimpleMessage() {
return simpleMessage;
}

public String getMessageType() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;

import static org.apache.commons.lang.StringUtils.isBlank;

Expand All @@ -49,40 +47,29 @@ public Message write(UserConfiguration userConfiguration) {
/**
* type별 메시지를 만든다.
*
* @param userConfiguration 사용자 설정
* @param configuration 사용자 설정
* @return 메시지
*/
private Message writeTemplateMessage(UserConfiguration userConfiguration) {

final List<Map<String, String>> messages = userConfiguration.getMessages();
final String backgroundImageUrl = userConfiguration.getBackgroundImageUrl();
final String contentActionLabel = userConfiguration.getContentActionLabel();
final String contentActionLink = userConfiguration.getContentActionLink();
String messageType = userConfiguration.getMessageType();
String notification = userConfiguration.getNotification();

if (isBlank(notification)) {
notification = "Changes have been deployed.";
}

switch (messageType) {

private Message writeTemplateMessage(UserConfiguration configuration) {
switch (configuration.getMessageType()) {
case TextContent.TYPE:
TextContent textContent = new TextContent(notification);
TextContent textContent = new TextContent();
textContent.writeMessage(configuration);
return new TextMessage(textContent);

case LinkContent.TYPE:
LinkContent linkContent = new LinkContent(notification, contentActionLabel, contentActionLink);
LinkContent linkContent = new LinkContent();
linkContent.writeMessage(configuration);
return new LinkMessage(linkContent);

case ListTemplateContent.TYPE:
ListTemplateContent listTemplateContent = new ListTemplateContent();
listTemplateContent.setMessages(messages, backgroundImageUrl, contentActionLabel, contentActionLink);
listTemplateContent.writeMessage(configuration);
return new ListTemplateMessage(listTemplateContent);

case CarouselContent.TYPE:
CarouselContent carouselContent = new CarouselContent();
carouselContent.setMessages(messages, backgroundImageUrl, contentActionLink);
carouselContent.writeMessage(configuration);
return new CarouselMessage(carouselContent);

default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.jenkins.plugins.naverworks.bot.message;

import io.jenkins.plugins.naverworks.UserConfiguration;

/**
* 메시지 내용
*/
Expand All @@ -12,4 +14,11 @@ public interface Content {
*/
String getType();

/**
* 메시지를 작성한다.
*
* @param configuration 사용자 설정
*/
void writeMessage(UserConfiguration configuration);

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.jenkins.plugins.naverworks.bot.message.carousel;

import io.jenkins.plugins.naverworks.UserConfiguration;
import io.jenkins.plugins.naverworks.bot.message.Action;
import io.jenkins.plugins.naverworks.bot.message.Content;
import org.apache.commons.collections.MapUtils;
Expand Down Expand Up @@ -38,39 +39,6 @@ public class CarouselContent implements Content {
*/
private List<Column> columns;

public void setMessages(
List<Map<String, String>> messages,
String backgroundImageUrl,
String contentActionLink
) {
List<Column> columnList = new ArrayList<>();
// EXCEEDED_LENGTH_LIMIT_OF_PARAM: Maximum content.columns length is 10
final int maxContentColumnsLength = 10;
int columnCount = 0;
for (Map<String, String> message : messages) {
if (columnCount == maxContentColumnsLength) {
break;
}
String link = MapUtils.getString(message, "link");
String title = MapUtils.getString(message, "title");
String subtitle = MapUtils.getString(message, "subtitle");

Column column = new Column(
backgroundImageUrl,
null,
title,
subtitle,
new Action(null, contentActionLink),
Collections.singletonList(new Action("more", link))
);

columnList.add(column);
columnCount++;
}

this.setColumns(columnList);
}

@Override
public String getType() {
return TYPE;
Expand Down Expand Up @@ -99,4 +67,38 @@ public List<Column> getColumns() {
public void setColumns(List<Column> columns) {
this.columns = columns;
}

@Override
public void writeMessage(UserConfiguration configuration) {
final List<Map<String, String>> messages = configuration.getMessages();
final String backgroundImageUrl = configuration.getBackgroundImageUrl();
final String contentActionLink = configuration.getContentActionLink();

List<Column> columnList = new ArrayList<>();
// EXCEEDED_LENGTH_LIMIT_OF_PARAM: Maximum content.columns length is 10
final int maxContentColumnsLength = 10;
int columnCount = 0;
for (Map<String, String> message : messages) {
if (columnCount == maxContentColumnsLength) {
break;
}
String link = MapUtils.getString(message, "link");
String title = MapUtils.getString(message, "title");
String subtitle = MapUtils.getString(message, "subtitle");

Column column = new Column(
backgroundImageUrl,
null,
title,
subtitle,
new Action(null, contentActionLink),
Collections.singletonList(new Action("more", link))
);

columnList.add(column);
columnCount++;
}

this.setColumns(columnList);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.jenkins.plugins.naverworks.bot.message.link;

import io.jenkins.plugins.naverworks.UserConfiguration;
import io.jenkins.plugins.naverworks.bot.message.Content;

/**
Expand All @@ -17,23 +18,17 @@ public class LinkContent implements Content {
/**
* 메시지 본문
*/
private final String contentText;
private String contentText;

/**
* 링크 레이블
*/
private final String linkText;
private String linkText;

/**
* linkText 영역을 누르면 이동할 페이지
*/
private final String link;

public LinkContent(String contentText, String linkText, String link) {
this.contentText = contentText;
this.linkText = linkText;
this.link = link;
}
private String link;

@Override
public String getType() {
Expand All @@ -51,4 +46,11 @@ public String getLinkText() {
public String getLink() {
return link;
}

@Override
public void writeMessage(UserConfiguration configuration) {
this.contentText = configuration.getSimpleMessage();
this.linkText = configuration.getContentActionLabel();
this.link = configuration.getContentActionLink();
}
}
Loading

0 comments on commit fe6c68c

Please sign in to comment.