Skip to content

Commit b5e4499

Browse files
authored
Merge pull request #3 from ArtemGet/create_tag
Create tag fix
2 parents a278a42 + 196e08a commit b5e4499

File tree

6 files changed

+198
-58
lines changed

6 files changed

+198
-58
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
<dependency>
3737
<groupId>com.github.ArtemGet</groupId>
3838
<artifactId>entrys</artifactId>
39-
<version>0.4.0</version>
39+
<version>0.4.1</version>
4040
</dependency>
4141
<dependency>
4242
<groupId>com.github.ArtemGet</groupId>

src/main/java/io/github/artemget/tagrelease/Entrypoint.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@
3636
import io.github.artemget.tagrelease.command.CmdListServices;
3737
import io.github.artemget.tagrelease.command.CmdListServicesAll;
3838
import io.github.artemget.tagrelease.command.CmdListStands;
39+
import io.github.artemget.tagrelease.command.CmdListServicesAllTags;
3940
import io.github.artemget.tagrelease.domain.Services;
4041
import io.github.artemget.tagrelease.domain.ServicesAll;
4142
import io.github.artemget.tagrelease.domain.Stands;
4243
import io.github.artemget.tagrelease.domain.StandsGl;
4344
import io.github.artemget.tagrelease.match.MatchAdmin;
4445
import io.github.artemget.tagrelease.match.MatchReply;
46+
import io.github.artemget.teleroute.match.MatchAny;
4547
import io.github.artemget.teleroute.match.MatchRegex;
4648
import io.github.artemget.teleroute.route.RouteDfs;
4749
import io.github.artemget.teleroute.route.RouteFork;
@@ -76,7 +78,7 @@ public static void main(final String[] args) throws EntryException, TelegramApiE
7678
new MatchAdmin(new ESplit(new EVal("bot.admins"))),
7779
new RouteDfs<>(
7880
new RouteFork<>(
79-
new MatchRegex<>("[Э]эхо"),
81+
new MatchRegex<>("[Ээ]хо"),
8082
new RouteFork<>(
8183
new MatchReply(),
8284
new CmdEchoReply(),
@@ -96,7 +98,14 @@ public static void main(final String[] args) throws EntryException, TelegramApiE
9698
new CmdListStands(stands)
9799
),
98100
new RouteFork<>(
99-
new MatchRegex<>("[Сс]обери сервисы \\{([^{}]*)\\}\\s+префикс\\s+\\{([^{}]*)\\}$"),
101+
new MatchRegex<>("[Пп]окажи тег \\{([^{}]*)\\}\\s+префикс\\s+\\{([^{}]*)\\}$"),
102+
new CmdListServicesAllTags(host, project, token)
103+
),
104+
new RouteFork<>(
105+
new MatchAny<>(
106+
new MatchRegex<>("[Сс]обери тег \\{([^{}]*)\\}\\s+префикс\\s+\\{([^{}]*)\\}$"),
107+
new MatchRegex<>("[Сс]обери тег \\{([^{}]*)\\}\\s+префикс\\s+\\{([^{}]*)\\}\\s+ветка\\s+\\{([^{}]*)\\}$")
108+
),
100109
new CmdBuildTags(host, project, token)
101110
)
102111
// new RouteFork<>(

src/main/java/io/github/artemget/tagrelease/command/CmdBuildTags.java

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,13 @@
2626

2727
import io.github.artemget.entrys.Entry;
2828
import io.github.artemget.entrys.EntryException;
29+
import io.github.artemget.entrys.fake.EFake;
2930
import io.github.artemget.entrys.operation.ESplit;
30-
import io.github.artemget.entrys.operation.EUnwrap;
3131
import io.github.artemget.tagrelease.domain.Service;
3232
import io.github.artemget.tagrelease.domain.Services;
3333
import io.github.artemget.tagrelease.domain.ServicesAll;
3434
import io.github.artemget.tagrelease.domain.Tag;
35+
import io.github.artemget.tagrelease.domain.TagEa;
3536
import io.github.artemget.tagrelease.domain.Tags;
3637
import io.github.artemget.tagrelease.domain.TagsGl;
3738
import io.github.artemget.tagrelease.exception.DomainException;
@@ -69,27 +70,18 @@ public CmdBuildTags(final Services services, final Tags tags) {
6970
@Override
7071
public Send<AbsSender> execute(Update update) throws CmdException {
7172
final List<String> names;
72-
final String branch;
73-
final String prefix;
7473
final String[] values = StringUtils.substringsBetween(update.getMessage().getText(), "{", "}");
7574
try {
76-
names = new ESplit(new EUnwrap(values[0]), ",").value();
77-
} catch (final EntryException exception) {
78-
throw new CmdException("Failed to parse service names for tag build", exception);
79-
}
80-
try {
81-
prefix = new EUnwrap(values[1]).value();
75+
names = new ESplit(new EFake<>(values[0]), ",").value();
8276
} catch (final EntryException exception) {
83-
throw new CmdException("Failed to parse prefix name for tag build", exception);
77+
throw new CmdException("Failed to parse service names for tag fetch", exception);
8478
}
85-
try {
86-
if (values.length >= 3) {
87-
branch = new EUnwrap(values[2]).value();
88-
} else {
89-
branch = "develop";
90-
}
91-
} catch (final EntryException exception) {
92-
throw new CmdException("Failed to parse branch name for tag build", exception);
79+
final String prefix = values[1];
80+
final String branch;
81+
if (values.length >= 3) {
82+
branch = values[2];
83+
} else {
84+
branch = "develop";
9385
}
9486
final List<Tag> succeed = new ArrayList<>();
9587
final List<String> failed = new ArrayList<>();
@@ -110,18 +102,28 @@ public Send<AbsSender> execute(Update update) throws CmdException {
110102
failed.add(name);
111103
continue;
112104
}
113-
succeed.add(tag);
105+
succeed.add(new TagEa(service.name(), tag.name(), tag.branch(), tag.fromCommit(), tag.message(), tag.created()));
114106
}
115107
final SendMessage message = new SendMessage(
116108
update.getMessage().getChatId().toString(),
117-
String.format(
118-
"Собраны сервисы:\n%s\nОшибка сборки сервисов:\n%s",
119-
new Tag.Printed(succeed).asString(),
120-
String.join("\n", failed)
121-
)
109+
String.format("Собраны сервисы:\n%s", new Tag.Printed(succeed).asString())
110+
.concat(CmdBuildTags.checked(failed))
122111
);
123112
message.setReplyToMessageId(update.getMessage().getMessageId());
124113
message.enableMarkdownV2(true);
125114
return new SendMessageWrap<>(message);
126115
}
116+
117+
private static String checked(List<String> failed) {
118+
final String message;
119+
if (failed.isEmpty()) {
120+
message = "";
121+
} else {
122+
message = String.format(
123+
"\nОшибка поиска тегов по сервисам:\n%s",
124+
String.format("```\n%s\n```", String.join("\n", failed))
125+
);
126+
}
127+
return message;
128+
}
127129
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
package io.github.artemget.tagrelease.command;
2+
3+
import io.github.artemget.entrys.Entry;
4+
import io.github.artemget.entrys.EntryException;
5+
import io.github.artemget.entrys.fake.EFake;
6+
import io.github.artemget.entrys.operation.ESplit;
7+
import io.github.artemget.tagrelease.domain.Service;
8+
import io.github.artemget.tagrelease.domain.Services;
9+
import io.github.artemget.tagrelease.domain.ServicesAll;
10+
import io.github.artemget.tagrelease.domain.Tag;
11+
import io.github.artemget.tagrelease.domain.TagEa;
12+
import io.github.artemget.tagrelease.domain.Tags;
13+
import io.github.artemget.tagrelease.domain.TagsGl;
14+
import io.github.artemget.tagrelease.exception.DomainException;
15+
import io.github.artemget.teleroute.command.Cmd;
16+
import io.github.artemget.teleroute.command.CmdException;
17+
import io.github.artemget.teleroute.send.Send;
18+
import io.github.artemget.teleroute.telegrambots.send.SendMessageWrap;
19+
import java.util.ArrayList;
20+
import java.util.List;
21+
import org.apache.commons.lang3.StringUtils;
22+
import org.slf4j.Logger;
23+
import org.slf4j.LoggerFactory;
24+
import org.telegram.telegrambots.meta.api.methods.send.SendMessage;
25+
import org.telegram.telegrambots.meta.api.objects.Update;
26+
import org.telegram.telegrambots.meta.bots.AbsSender;
27+
28+
public class CmdListServicesAllTags implements Cmd<Update, AbsSender> {
29+
private final Logger log = LoggerFactory.getLogger(CmdListServicesAllTags.class);
30+
private final Services services;
31+
private final Tags tags;
32+
33+
public CmdListServicesAllTags(
34+
final Entry<String> host,
35+
final Entry<String> project,
36+
final Entry<String> token
37+
) {
38+
this(new ServicesAll(host, project, token), new TagsGl(host, token));
39+
}
40+
41+
public CmdListServicesAllTags(final Services services, final Tags tags) {
42+
this.services = services;
43+
this.tags = tags;
44+
}
45+
46+
@Override
47+
public Send<AbsSender> execute(Update update) throws CmdException {
48+
final List<String> names;
49+
final String[] values = StringUtils.substringsBetween(update.getMessage().getText(), "{", "}");
50+
try {
51+
names = new ESplit(new EFake<>(values[0]), ",").value();
52+
} catch (final EntryException exception) {
53+
throw new CmdException("Failed to parse service names for tag fetch", exception);
54+
}
55+
final String prefix = values[1];
56+
final String branch;
57+
if (values.length >= 3) {
58+
branch = values[2];
59+
} else {
60+
branch = "develop";
61+
}
62+
final List<Tag> succeed = new ArrayList<>();
63+
final List<String> failed = new ArrayList<>();
64+
for (final String name : names) {
65+
Service service;
66+
try {
67+
service = this.services.service(name);
68+
} catch (final DomainException exception) {
69+
log.error("Failed to fetch service:'{}' for tag build", name, exception);
70+
failed.add(name);
71+
continue;
72+
}
73+
final Tag tag;
74+
try {
75+
tag = this.tags.current(service.id(), branch, prefix);
76+
} catch (final DomainException exception) {
77+
log.error("Failed to fetch current tag for service:'{}'", name, exception);
78+
failed.add(name);
79+
continue;
80+
}
81+
succeed.add(new TagEa(service.name(), tag.name(), tag.branch(), tag.fromCommit(), tag.message(), tag.created()));
82+
}
83+
final SendMessage message = new SendMessage(
84+
update.getMessage().getChatId().toString(),
85+
String.format("Найдены теги:\n```\n%s\n```", new Tag.Printed(succeed).asString())
86+
.concat(CmdListServicesAllTags.checked(failed))
87+
);
88+
message.setReplyToMessageId(update.getMessage().getMessageId());
89+
message.enableMarkdownV2(true);
90+
return new SendMessageWrap<>(message);
91+
}
92+
93+
private static String checked(List<String> failed) {
94+
final String message;
95+
if (failed.isEmpty()) {
96+
message = "";
97+
} else {
98+
message = String.format(
99+
"\nОшибка поиска тегов по сервисам:\n%s",
100+
String.format("```\n%s\n```", String.join("\n", failed))
101+
);
102+
}
103+
return message;
104+
}
105+
}

src/main/java/io/github/artemget/tagrelease/domain/Tag.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public Printed(final List<Tag> tags) {
5757
public String asString() {
5858
final StringBuilder string = new StringBuilder();
5959
for (final Tag tag : this.tags) {
60-
string.append(String.format("```%s:%s```\n", tag.repo(), tag.name()));
60+
string.append(String.format("%s:%s\n", tag.repo(), tag.name()));
6161
}
6262
return string.toString();
6363
}

0 commit comments

Comments
 (0)