Skip to content

Commit

Permalink
Merge pull request #8 from muziyoshiz/add-original-message
Browse files Browse the repository at this point in the history
 Add description parameter for typetalkSend step
  • Loading branch information
ikikko committed Dec 6, 2018
2 parents 8090c24 + fc46cb7 commit 4b665d9
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 8 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Expand Up @@ -8,3 +8,5 @@ work/
classes/
src/test/resources/config.properties
target
.idea
*.iml
Expand Up @@ -25,12 +25,14 @@ public class TypetalkNotifier extends Notifier {
public final String name;
public final String topicNumber;
public final String talkId;
public final String description;

@DataBoundConstructor
public TypetalkNotifier(String name, String topicNumber, String talkId) {
public TypetalkNotifier(String name, String topicNumber, String talkId, String description) {
this.name = name;
this.topicNumber = topicNumber;
this.talkId = talkId;
this.description = description;
}

@Override
Expand All @@ -45,7 +47,7 @@ public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListen
if (StringUtils.isNotEmpty(talkId)) {
talkIdLong = Long.parseLong(talkId);
}
new NotifyDelegate(name, Long.valueOf(topicNumber), talkIdLong , listener, build).notifyResult();
new NotifyDelegate(name, Long.valueOf(topicNumber), talkIdLong, description, listener, build).notifyResult();
return true;
}

Expand Down
Expand Up @@ -16,14 +16,17 @@ public class NotifyDelegate {

private final Long talkId;

private final String description;

private final TaskListener listener;

private final Run run;

public NotifyDelegate(String name, Long topicId, Long talkId, TaskListener listener, Run run) {
public NotifyDelegate(String name, Long topicId, Long talkId, String description, TaskListener listener, Run run) {
this.name = name;
this.topicId = topicId;
this.talkId = talkId;
this.description = description;
this.listener = listener;
this.run = run;
}
Expand All @@ -37,7 +40,7 @@ public void notifyResult() throws IOException {
listener.getLogger().println("Notifying build result to Typetalk...");

TypetalkMessage typetalkMessage = resultSupport.convertBuildToMessage(run);
String message = typetalkMessage.buildMessageWithBuild(run);
String message = typetalkMessage.buildMessageWithBuild(run, description);

Typetalk.createFromName(name).postMessage(topicId, message, talkId);
}
Expand Down
Expand Up @@ -18,6 +18,7 @@ public class TypetalkSendStep extends AbstractStepImpl {
private final @Nonnull String name;
private final @Nonnull Long topicId;
private final @Nonnull Long talkId;
private final @Nonnull String description;

@Nonnull
public String getName() {
Expand All @@ -34,11 +35,17 @@ public Long getTalkId() {
return talkId;
}

@Nonnull
public String getDescription() {
return description;
}

@DataBoundConstructor
public TypetalkSendStep(@Nonnull String name, @Nonnull Long topicId, @Nonnull Long talkId) {
public TypetalkSendStep(@Nonnull String name, @Nonnull Long topicId, @Nonnull Long talkId, @Nonnull String description) {
this.name = name;
this.topicId = topicId;
this.talkId = talkId;
this.description = description;
}

@Extension
Expand Down Expand Up @@ -74,7 +81,7 @@ public static class TypetalkSendStepExecution extends AbstractSynchronousNonBloc

@Override
protected Void run() throws Exception {
new NotifyDelegate(step.name, step.topicId, step.talkId, listener, run).notifyResult();
new NotifyDelegate(step.name, step.topicId, step.talkId, step.description, listener, run).notifyResult();
return null;
}

Expand Down
Expand Up @@ -29,7 +29,11 @@ public TypetalkMessage(Emoji emoji, String message) {
this.message = message;
}

public String buildMessageWithBuild(Run build) {
public String buildMessageWithBuild(Run build) {
return buildMessageWithBuild(build, null);
}

public String buildMessageWithBuild(Run build, String description) {
final String rootUrl = Jenkins.getInstance().getRootUrl();
if (StringUtils.isEmpty(rootUrl)) {
throw new IllegalStateException("Root URL isn't configured yet. Cannot compute absolute URL.");
Expand All @@ -56,6 +60,11 @@ public String buildMessageWithBuild(Run build) {
}
}

if (StringUtils.isNotEmpty(description)) {
builder.append("\n\n");
builder.append(description);
}

return builder.toString();
}

Expand Down
Expand Up @@ -20,4 +20,8 @@
<f:textbox />
</f:entry>

<f:entry title="${%Description}" field="description">
<f:textbox />
</f:entry>

</j:jelly>
Expand Up @@ -14,4 +14,12 @@
<f:textbox />
</f:entry>

<f:entry title="${%Talk Number}" field="talkId">
<f:textbox />
</f:entry>

<f:entry title="${%Description}" field="description">
<f:textbox />
</f:entry>

</j:jelly>
Expand Up @@ -8,6 +8,6 @@
sh 'package'
sh 'deploy'
}
typetalkSend name: 'demo', topicId: 1
typetalkSend name: 'demo', topicId: 1, talkId: 1, description: "Awesome description"
</pre>
</div>

0 comments on commit 4b665d9

Please sign in to comment.