Skip to content

Commit

Permalink
refactor(announce): Tweak mastodon tread support. Relates to #1001
Browse files Browse the repository at this point in the history
  • Loading branch information
aalmiray committed Nov 19, 2022
1 parent 116a018 commit 99f277c
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 34 deletions.
Expand Up @@ -424,9 +424,9 @@ validation_slack_token = slack.token or slack.webhook must be
validation_extension_gav_directory = Cannot define both gav and directory for {}

default.discussion.title = {{projectNameCapitalized}} {{projectVersion}} released!
default.release.message = 🚀 {{projectNameCapitalized}} {{projectVersion}} has been released! {{releaseNotesUrl}}
default.category.feature = 🚀 Features
default.category.bug.fix = 🐛 Bug Fixes
default.release.message = ? {{projectNameCapitalized}} {{projectVersion}} has been released! {{releaseNotesUrl}}
default.category.feature = ? Features
default.category.bug.fix = ? Bug Fixes

ERROR_path_does_not_exist = Path does not exist {}
ERROR_unexpected_error_reading_template = Unexpected error reading template {}
Expand Down
Expand Up @@ -427,8 +427,6 @@ sdkman.release.announce.major = Объявление основного рели
sdkman.release.announce.minor = Объявление о незначительном релизе кандидата '{}'
twitter.tweet = твиттер: {}
twitter.tweet.size = статус составляет {} символов
mastodon.toot = tooting: {}
mastodon.toot.size = status este {} lung de caractere
ERROR_unexpected_json_format = Неожиданное сообщение об ошибке форматирования как JSON
mail.message.send = Отправка объявления по электронной почте
s3.bucket.check = проверка, существует ли сегмент {}
Expand Down
Expand Up @@ -44,13 +44,10 @@
* @since 0.4.0
*/
public final class MastodonAnnouncer extends AbstractAnnouncer<MastodonAnnouncer, org.jreleaser.model.api.announce.MastodonAnnouncer> {
private final List<String> statuses = new ArrayList<>();
private String host;
private String accessToken;

private String status;

private final List<String> statuses = new ArrayList<>();

private String statusTemplate;

private final org.jreleaser.model.api.announce.MastodonAnnouncer immutable = new org.jreleaser.model.api.announce.MastodonAnnouncer() {
Expand Down Expand Up @@ -191,15 +188,6 @@ public void setStatuses(List<String> statuses) {
this.statuses.addAll(statuses);
}

@Override
protected void asMap(boolean full, Map<String, Object> props) {
props.put("host", host);
props.put("accessToken", isNotBlank(accessToken) ? HIDE : UNSET);
props.put("status", status);
props.put("statuses", statuses);
props.put("statusTemplate", statusTemplate);
}

public String getStatusTemplate() {
return statusTemplate;
}
Expand All @@ -215,4 +203,13 @@ public String getStatus() {
public void setStatus(String status) {
this.status = status;
}

@Override
protected void asMap(boolean full, Map<String, Object> props) {
props.put("host", host);
props.put("accessToken", isNotBlank(accessToken) ? HIDE : UNSET);
props.put("status", status);
props.put("statuses", statuses);
props.put("statusTemplate", statusTemplate);
}
}
Expand Up @@ -97,8 +97,6 @@ public void announce() throws AnnounceException {
statuses.set(i, status);
}

context.getLogger().debug("statuses: {}", statuses);

try {
MastodonSdk sdk = MastodonSdk.builder(context.getLogger())
.host(mastodon.getHost())
Expand All @@ -107,7 +105,7 @@ public void announce() throws AnnounceException {
.readTimeout(mastodon.getReadTimeout())
.dryrun(context.isDryrun())
.build();
sdk.status(statuses);
sdk.toot(statuses);
} catch (MastodonException e) {
throw new AnnounceException(e);
}
Expand Down
Expand Up @@ -68,14 +68,11 @@ private MastodonSdk(JReleaserLogger logger,
this.logger.debug(RB.$("workflow.dryrun"), dryrun);
}

public void status(List<String> statuses) throws MastodonException {
public void toot(List<String> statuses) throws MastodonException {
wrap(() -> {
Status payload = Status.of(statuses.get(0), null);
Status status = api.status(payload);

Status status = api.status(Status.of(statuses.get(0)));
for (int i = 1; i < statuses.size(); i++) {
payload = Status.of(statuses.get(i), status.getId());
api.status(payload);
status = api.status(Status.of(statuses.get(i), status.getId()));
}
});
}
Expand Down
Expand Up @@ -25,9 +25,7 @@
*/
public class Status {
private String id;

private String status;

private String in_reply_to_id;

public String getStatus() {
Expand All @@ -47,6 +45,10 @@ public String toString() {
']';
}

public static Status of(String status) {
return of(status, null);
}

public static Status of(String status, String inReplyToId) {
Status o = new Status();
o.status = requireNonBlank(status, "'status' must not be blank").trim();
Expand Down
Expand Up @@ -53,7 +53,7 @@ public void testUpdateStatus() throws MastodonException {
.build();

// when:
command.status(Collections.singletonList("success"));
command.toot(Collections.singletonList("success"));

// then:
RequestPatternBuilder builder = postRequestedFor(urlEqualTo(API_V_1_STATUSES));
Expand All @@ -71,7 +71,7 @@ public void testUpdateStatuses() throws MastodonException {
.build();

// when:
command.status(Arrays.asList("success1", "success2"));
command.toot(Arrays.asList("success1", "success2"));

// then:
RequestPatternBuilder builder = postRequestedFor(urlEqualTo(API_V_1_STATUSES));
Expand Down
Expand Up @@ -73,8 +73,7 @@ public Twitter(JReleaserLogger logger,

public void updateStatus(List<String> statuses) throws TwitterException {
wrap(() -> {
String message = statuses.get(0);
Status status = twitter.updateStatus(message);
Status status = twitter.updateStatus(statuses.get(0));
for (int i = 1; i < statuses.size(); i++) {
status = twitter.updateStatus(new StatusUpdate(statuses.get(i))
.inReplyToStatusId(status.getId()));
Expand Down
Expand Up @@ -67,7 +67,6 @@ public boolean isEnabled() {

@Override
public void announce() throws AnnounceException {

List<String> statuses = new ArrayList<>();

if (isNotBlank(twitter.getStatusTemplate())) {
Expand Down

0 comments on commit 99f277c

Please sign in to comment.