mirror of
https://github.com/jlengrand/jreleaser.git
synced 2026-03-10 08:31:24 +00:00
[announce] Fix small issues in GoogleChat integration. Relates to #241
This commit is contained in:
@@ -33,6 +33,7 @@ public class Announce implements Domain, EnabledAware {
|
||||
private final Discord discord = new Discord();
|
||||
private final Discussions discussions = new Discussions();
|
||||
private final Gitter gitter = new Gitter();
|
||||
private final GoogleChat googleChat = new GoogleChat();
|
||||
private final Mail mail = new Mail();
|
||||
private final Mastodon mastodon = new Mastodon();
|
||||
private final Mattermost mattermost = new Mattermost();
|
||||
@@ -42,7 +43,6 @@ public class Announce implements Domain, EnabledAware {
|
||||
private final Twitter twitter = new Twitter();
|
||||
private final Webhooks webhooks = new Webhooks();
|
||||
private final Zulip zulip = new Zulip();
|
||||
private final GoogleChat googleChat = new GoogleChat();
|
||||
private Boolean enabled;
|
||||
|
||||
void setAll(Announce announce) {
|
||||
@@ -267,6 +267,7 @@ public class Announce implements Domain, EnabledAware {
|
||||
set.add(Discord.NAME);
|
||||
set.add(Discussions.NAME);
|
||||
set.add(Gitter.NAME);
|
||||
set.add(GoogleChat.NAME);
|
||||
set.add(Mail.NAME);
|
||||
set.add(Mastodon.NAME);
|
||||
set.add(Mattermost.NAME);
|
||||
|
||||
@@ -28,32 +28,24 @@ import static org.jreleaser.util.StringUtils.isBlank;
|
||||
import static org.jreleaser.util.StringUtils.isNotBlank;
|
||||
|
||||
/**
|
||||
* @author Andres Almiray
|
||||
* @since 0.1.0
|
||||
* @author Anyul Rivas
|
||||
* @since 0.5.0
|
||||
*/
|
||||
public abstract class GoogleChatValidator extends Validator {
|
||||
private static final String DEFAULT_GOOGLE_CHAT_TPL = "src/jreleaser/templates/google_chat.tpl";
|
||||
private static final String DEFAULT_GOOGLE_CHAT_TPL = "src/jreleaser/templates/googleChat.tpl";
|
||||
|
||||
public static void validateGoogleChat(JReleaserContext context, GoogleChat googleChat, Errors errors) {
|
||||
if (!googleChat.resolveEnabled(context.getModel().getProject())) return;
|
||||
context.getLogger().debug("announce.slack");
|
||||
context.getLogger().debug("announce.googleChat");
|
||||
|
||||
Errors ignored = new Errors();
|
||||
googleChat.setWebhook(
|
||||
checkProperty(context.getModel().getEnvironment(),
|
||||
GOOGLE_CHAT_WEBHOOK,
|
||||
"GoogleChat.webhook",
|
||||
"googleChat.webhook",
|
||||
googleChat.getWebhook(),
|
||||
ignored,
|
||||
errors,
|
||||
context.isDryrun()));
|
||||
|
||||
String webhook = googleChat.getResolvedWebhook();
|
||||
|
||||
if (!context.isDryrun() && isBlank(webhook)) {
|
||||
errors.configuration("GoogleChat.webhook must be provided");
|
||||
return;
|
||||
}
|
||||
|
||||
if (isBlank(googleChat.getMessage()) && isBlank(googleChat.getMessageTemplate())) {
|
||||
if (Files.exists(context.getBasedir().resolve(DEFAULT_GOOGLE_CHAT_TPL))) {
|
||||
googleChat.setMessageTemplate(DEFAULT_GOOGLE_CHAT_TPL);
|
||||
@@ -64,7 +56,7 @@ public abstract class GoogleChatValidator extends Validator {
|
||||
|
||||
if (isNotBlank(googleChat.getMessageTemplate()) &&
|
||||
!Files.exists(context.getBasedir().resolve(googleChat.getMessageTemplate().trim()))) {
|
||||
errors.configuration("GoogleChat.messageTemplate does not exist. " + googleChat.getMessageTemplate());
|
||||
errors.configuration("googleChat.messageTemplate does not exist. " + googleChat.getMessageTemplate());
|
||||
}
|
||||
|
||||
if (googleChat.getConnectTimeout() <= 0 || googleChat.getConnectTimeout() > 300) {
|
||||
|
||||
@@ -28,7 +28,6 @@ import org.gradle.api.provider.Property
|
||||
*/
|
||||
@CompileStatic
|
||||
interface GoogleChat extends Announcer {
|
||||
|
||||
Property<String> getWebhook()
|
||||
|
||||
Property<String> getMessage()
|
||||
|
||||
@@ -164,8 +164,9 @@ class AnnounceImpl implements Announce {
|
||||
ConfigureUtil.configure(action, gitter)
|
||||
}
|
||||
|
||||
@Override
|
||||
void googleChat(@DelegatesTo(strategy = Closure.DELEGATE_FIRST, value = GoogleChat) Closure<Void> action) {
|
||||
ConfigureUtil.configure(action, gitter)
|
||||
ConfigureUtil.configure(action, googleChat)
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -17,17 +17,15 @@
|
||||
*/
|
||||
package org.jreleaser.sdk.googlechat;
|
||||
|
||||
import org.jreleaser.model.JReleaserContext;
|
||||
import org.jreleaser.model.GoogleChat;
|
||||
import org.jreleaser.model.JReleaserContext;
|
||||
import org.jreleaser.model.announcer.spi.AnnounceException;
|
||||
import org.jreleaser.model.announcer.spi.Announcer;
|
||||
import org.jreleaser.sdk.commons.ClientUtils;
|
||||
import org.jreleaser.util.Constants;
|
||||
import org.jreleaser.util.MustacheUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.jreleaser.util.StringUtils.isNotBlank;
|
||||
@@ -69,16 +67,12 @@ public class GoogleChatAnnouncer implements Announcer {
|
||||
|
||||
context.getLogger().info("message: {}", message);
|
||||
|
||||
if (isNotBlank(googleChat.getResolvedWebhook()) && !context.isDryrun()) {
|
||||
try {
|
||||
ClientUtils.webhook(context.getLogger(),
|
||||
googleChat.getResolvedWebhook(),
|
||||
googleChat.getConnectTimeout(),
|
||||
googleChat.getReadTimeout(),
|
||||
Message.of(message));
|
||||
} catch (AnnounceException e) {
|
||||
context.getLogger().trace(e);
|
||||
}
|
||||
if (!context.isDryrun()) {
|
||||
ClientUtils.webhook(context.getLogger(),
|
||||
googleChat.getResolvedWebhook(),
|
||||
googleChat.getConnectTimeout(),
|
||||
googleChat.getReadTimeout(),
|
||||
Message.of(message));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user