• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jreleaser / jreleaser / #510

27 Jul 2025 12:31PM UTC coverage: 45.783% (-3.6%) from 49.39%
#510

push

github

aalmiray
feat(packagers): Stage distribution publication in a fixed directory

Closes #1943

12 of 25 new or added lines in 4 files covered. (48.0%)

2208 existing lines in 190 files now uncovered.

23924 of 52255 relevant lines covered (45.78%)

0.46 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.73
/sdks/jreleaser-telegram-java-sdk/src/main/java/org/jreleaser/sdk/telegram/TelegramSdk.java
1
/*
2
 * SPDX-License-Identifier: Apache-2.0
3
 *
4
 * Copyright 2020-2025 The JReleaser authors.
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     https://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
package org.jreleaser.sdk.telegram;
19

20
import org.jreleaser.bundle.RB;
21
import org.jreleaser.model.api.JReleaserContext;
22
import org.jreleaser.sdk.commons.ClientUtils;
23
import org.jreleaser.sdk.commons.RestAPIException;
24
import org.jreleaser.sdk.telegram.api.Message;
25
import org.jreleaser.sdk.telegram.api.TelegramAPI;
26

27
import static java.util.Objects.requireNonNull;
28
import static org.jreleaser.util.StringUtils.isBlank;
29
import static org.jreleaser.util.StringUtils.requireNonBlank;
30

31
/**
32
 * @author Andres Almiray
33
 * @since 0.8.0
34
 */
35
public class TelegramSdk {
36
    private final JReleaserContext context;
37
    private final TelegramAPI api;
38
    private final boolean dryrun;
39

40
    private TelegramSdk(JReleaserContext context,
41
                        String apiHost,
42
                        int connectTimeout,
43
                        int readTimeout,
44
                        boolean dryrun) {
1✔
45
        requireNonNull(context, "'context' must not be null");
1✔
46
        requireNonBlank(apiHost, "'apiHost' must not be blank");
1✔
47

48
        this.context = context;
1✔
49
        this.dryrun = dryrun;
1✔
50
        this.api = ClientUtils.builder(context, connectTimeout, readTimeout)
1✔
51
            .target(TelegramAPI.class, apiHost);
1✔
52

53
        this.context.getLogger().debug(RB.$("workflow.dryrun"), dryrun);
1✔
54
    }
1✔
55

56
    public void sendMessage(String chatId, String message) throws TelegramException {
57
        Message payload = Message.of(chatId, message);
1✔
58
        context.getLogger().debug("telegram.message: " + payload);
1✔
59
        wrap(() -> api.sendMessage(payload));
1✔
60
    }
1✔
61

62
    private void wrap(Runnable runnable) throws TelegramException {
63
        try {
64
            if (!dryrun) runnable.run();
1✔
65
        } catch (RestAPIException e) {
1✔
66
            context.getLogger().trace(e.getStatus() + ": " + e.getReason());
1✔
67
            context.getLogger().trace(e);
1✔
68
            throw new TelegramException(RB.$("sdk.operation.failed", "Telegram"), e);
1✔
69
        }
1✔
70
    }
1✔
71

72
    public static Builder builder(JReleaserContext context) {
73
        return new Builder(context);
1✔
74
    }
75

76
    public static class Builder {
77
        private final JReleaserContext context;
78
        private boolean dryrun;
79
        private String apiHost;
80
        private String token;
81
        private int connectTimeout = 20;
1✔
82
        private int readTimeout = 60;
1✔
83

84
        private Builder(JReleaserContext context) {
1✔
85
            this.context = requireNonNull(context, "'context' must not be null");
1✔
86
        }
1✔
87

88
        public Builder dryrun(boolean dryrun) {
89
            this.dryrun = dryrun;
1✔
90
            return this;
1✔
91
        }
92

93
        public Builder apiHost(String apiHost) {
94
            this.apiHost = requireNonBlank(apiHost, "'apiHost' must not be blank").trim();
1✔
95
            return this;
1✔
96
        }
97

98
        public Builder token(String token) {
99
            this.token = requireNonBlank(token, "'token' must not be blank").trim();
1✔
100
            return this;
1✔
101
        }
102

103
        public Builder connectTimeout(int connectTimeout) {
104
            this.connectTimeout = connectTimeout;
1✔
105
            return this;
1✔
106
        }
107

108
        public Builder readTimeout(int readTimeout) {
109
            this.readTimeout = readTimeout;
1✔
110
            return this;
1✔
111
        }
112

113
        private void validate() {
114
            requireNonBlank(token, "'token' must not be blank");
1✔
115
            if (isBlank(apiHost)) {
1✔
UNCOV
116
                apiHost("https://api.telegram.org/bot");
×
117
            }
118

119
            if (!apiHost.endsWith(token)) {
1✔
120
                apiHost += token;
1✔
121
            }
122
        }
1✔
123

124
        public TelegramSdk build() {
125
            validate();
1✔
126

127
            return new TelegramSdk(
1✔
128
                context,
129
                apiHost,
130
                connectTimeout,
131
                readTimeout,
132
                dryrun);
133
        }
134
    }
135
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc