Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<dependency>
<groupId>com.github.ArtemGet</groupId>
<artifactId>entrys</artifactId>
<version>0.4.0</version>
<version>0.4.1</version>
</dependency>
<dependency>
<groupId>com.github.ArtemGet</groupId>
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/io/github/artemget/tagrelease/Entrypoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,14 @@
import io.github.artemget.tagrelease.command.CmdListServices;
import io.github.artemget.tagrelease.command.CmdListServicesAll;
import io.github.artemget.tagrelease.command.CmdListStands;
import io.github.artemget.tagrelease.command.CmdListServicesAllTags;
import io.github.artemget.tagrelease.domain.Services;
import io.github.artemget.tagrelease.domain.ServicesAll;
import io.github.artemget.tagrelease.domain.Stands;
import io.github.artemget.tagrelease.domain.StandsGl;
import io.github.artemget.tagrelease.match.MatchAdmin;
import io.github.artemget.tagrelease.match.MatchReply;
import io.github.artemget.teleroute.match.MatchAny;
import io.github.artemget.teleroute.match.MatchRegex;
import io.github.artemget.teleroute.route.RouteDfs;
import io.github.artemget.teleroute.route.RouteFork;
Expand Down Expand Up @@ -76,7 +78,7 @@ public static void main(final String[] args) throws EntryException, TelegramApiE
new MatchAdmin(new ESplit(new EVal("bot.admins"))),
new RouteDfs<>(
new RouteFork<>(
new MatchRegex<>("[Э]эхо"),
new MatchRegex<>("[Ээ]хо"),
new RouteFork<>(
new MatchReply(),
new CmdEchoReply(),
Expand All @@ -96,7 +98,14 @@ public static void main(final String[] args) throws EntryException, TelegramApiE
new CmdListStands(stands)
),
new RouteFork<>(
new MatchRegex<>("[Сс]обери сервисы \\{([^{}]*)\\}\\s+префикс\\s+\\{([^{}]*)\\}$"),
new MatchRegex<>("[Пп]окажи тег \\{([^{}]*)\\}\\s+префикс\\s+\\{([^{}]*)\\}$"),
new CmdListServicesAllTags(host, project, token)
),
new RouteFork<>(
new MatchAny<>(
new MatchRegex<>("[Сс]обери тег \\{([^{}]*)\\}\\s+префикс\\s+\\{([^{}]*)\\}$"),
new MatchRegex<>("[Сс]обери тег \\{([^{}]*)\\}\\s+префикс\\s+\\{([^{}]*)\\}\\s+ветка\\s+\\{([^{}]*)\\}$")
),
new CmdBuildTags(host, project, token)
)
// new RouteFork<>(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@

import io.github.artemget.entrys.Entry;
import io.github.artemget.entrys.EntryException;
import io.github.artemget.entrys.fake.EFake;
import io.github.artemget.entrys.operation.ESplit;
import io.github.artemget.entrys.operation.EUnwrap;
import io.github.artemget.tagrelease.domain.Service;
import io.github.artemget.tagrelease.domain.Services;
import io.github.artemget.tagrelease.domain.ServicesAll;
import io.github.artemget.tagrelease.domain.Tag;
import io.github.artemget.tagrelease.domain.TagEa;
import io.github.artemget.tagrelease.domain.Tags;
import io.github.artemget.tagrelease.domain.TagsGl;
import io.github.artemget.tagrelease.exception.DomainException;
Expand Down Expand Up @@ -69,27 +70,18 @@ public CmdBuildTags(final Services services, final Tags tags) {
@Override
public Send<AbsSender> execute(Update update) throws CmdException {
final List<String> names;
final String branch;
final String prefix;
final String[] values = StringUtils.substringsBetween(update.getMessage().getText(), "{", "}");
try {
names = new ESplit(new EUnwrap(values[0]), ",").value();
} catch (final EntryException exception) {
throw new CmdException("Failed to parse service names for tag build", exception);
}
try {
prefix = new EUnwrap(values[1]).value();
names = new ESplit(new EFake<>(values[0]), ",").value();
} catch (final EntryException exception) {
throw new CmdException("Failed to parse prefix name for tag build", exception);
throw new CmdException("Failed to parse service names for tag fetch", exception);
}
try {
if (values.length >= 3) {
branch = new EUnwrap(values[2]).value();
} else {
branch = "develop";
}
} catch (final EntryException exception) {
throw new CmdException("Failed to parse branch name for tag build", exception);
final String prefix = values[1];
final String branch;
if (values.length >= 3) {
branch = values[2];
} else {
branch = "develop";
}
final List<Tag> succeed = new ArrayList<>();
final List<String> failed = new ArrayList<>();
Expand All @@ -110,18 +102,28 @@ public Send<AbsSender> execute(Update update) throws CmdException {
failed.add(name);
continue;
}
succeed.add(tag);
succeed.add(new TagEa(service.name(), tag.name(), tag.branch(), tag.fromCommit(), tag.message(), tag.created()));
}
final SendMessage message = new SendMessage(
update.getMessage().getChatId().toString(),
String.format(
"Собраны сервисы:\n%s\nОшибка сборки сервисов:\n%s",
new Tag.Printed(succeed).asString(),
String.join("\n", failed)
)
String.format("Собраны сервисы:\n%s", new Tag.Printed(succeed).asString())
.concat(CmdBuildTags.checked(failed))
);
message.setReplyToMessageId(update.getMessage().getMessageId());
message.enableMarkdownV2(true);
return new SendMessageWrap<>(message);
}

private static String checked(List<String> failed) {
final String message;
if (failed.isEmpty()) {
message = "";
} else {
message = String.format(
"\nОшибка поиска тегов по сервисам:\n%s",
String.format("```\n%s\n```", String.join("\n", failed))
);
}
return message;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package io.github.artemget.tagrelease.command;

import io.github.artemget.entrys.Entry;
import io.github.artemget.entrys.EntryException;
import io.github.artemget.entrys.fake.EFake;
import io.github.artemget.entrys.operation.ESplit;
import io.github.artemget.tagrelease.domain.Service;
import io.github.artemget.tagrelease.domain.Services;
import io.github.artemget.tagrelease.domain.ServicesAll;
import io.github.artemget.tagrelease.domain.Tag;
import io.github.artemget.tagrelease.domain.TagEa;
import io.github.artemget.tagrelease.domain.Tags;
import io.github.artemget.tagrelease.domain.TagsGl;
import io.github.artemget.tagrelease.exception.DomainException;
import io.github.artemget.teleroute.command.Cmd;
import io.github.artemget.teleroute.command.CmdException;
import io.github.artemget.teleroute.send.Send;
import io.github.artemget.teleroute.telegrambots.send.SendMessageWrap;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
import org.telegram.telegrambots.meta.api.objects.Update;
import org.telegram.telegrambots.meta.bots.AbsSender;

public class CmdListServicesAllTags implements Cmd<Update, AbsSender> {
private final Logger log = LoggerFactory.getLogger(CmdListServicesAllTags.class);
private final Services services;
private final Tags tags;

public CmdListServicesAllTags(
final Entry<String> host,
final Entry<String> project,
final Entry<String> token
) {
this(new ServicesAll(host, project, token), new TagsGl(host, token));
}

public CmdListServicesAllTags(final Services services, final Tags tags) {
this.services = services;
this.tags = tags;
}

@Override
public Send<AbsSender> execute(Update update) throws CmdException {
final List<String> names;
final String[] values = StringUtils.substringsBetween(update.getMessage().getText(), "{", "}");
try {
names = new ESplit(new EFake<>(values[0]), ",").value();
} catch (final EntryException exception) {
throw new CmdException("Failed to parse service names for tag fetch", exception);
}
final String prefix = values[1];
final String branch;
if (values.length >= 3) {
branch = values[2];
} else {
branch = "develop";
}
final List<Tag> succeed = new ArrayList<>();
final List<String> failed = new ArrayList<>();
for (final String name : names) {
Service service;
try {
service = this.services.service(name);
} catch (final DomainException exception) {
log.error("Failed to fetch service:'{}' for tag build", name, exception);
failed.add(name);
continue;
}
final Tag tag;
try {
tag = this.tags.current(service.id(), branch, prefix);
} catch (final DomainException exception) {
log.error("Failed to fetch current tag for service:'{}'", name, exception);
failed.add(name);
continue;
}
succeed.add(new TagEa(service.name(), tag.name(), tag.branch(), tag.fromCommit(), tag.message(), tag.created()));
}
final SendMessage message = new SendMessage(
update.getMessage().getChatId().toString(),
String.format("Найдены теги:\n```\n%s\n```", new Tag.Printed(succeed).asString())
.concat(CmdListServicesAllTags.checked(failed))
);
message.setReplyToMessageId(update.getMessage().getMessageId());
message.enableMarkdownV2(true);
return new SendMessageWrap<>(message);
}

private static String checked(List<String> failed) {
final String message;
if (failed.isEmpty()) {
message = "";
} else {
message = String.format(
"\nОшибка поиска тегов по сервисам:\n%s",
String.format("```\n%s\n```", String.join("\n", failed))
);
}
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public Printed(final List<Tag> tags) {
public String asString() {
final StringBuilder string = new StringBuilder();
for (final Tag tag : this.tags) {
string.append(String.format("```%s:%s```\n", tag.repo(), tag.name()));
string.append(String.format("%s:%s\n", tag.repo(), tag.name()));
}
return string.toString();
}
Expand Down
Loading