Skip to content

Commit 0df3158

Browse files
committed
Trim all spaces.
1 parent 900ec67 commit 0df3158

File tree

1 file changed

+17
-34
lines changed

1 file changed

+17
-34
lines changed

services/webhook/telegram.go

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,7 @@ func (t *TelegramPayload) Create(p *api.CreatePayload) (api.Payloader, error) {
6868
title := fmt.Sprintf(`[<a href="%s">%s</a>] %s <a href="%s">%s</a> created`, p.Repo.HTMLURL, p.Repo.FullName, p.RefType,
6969
p.Repo.HTMLURL+"/src/"+refName, refName)
7070

71-
return &TelegramPayload{
72-
Message: title,
73-
}, nil
71+
return createPayload(title), nil
7472
}
7573

7674
// Delete implements PayloadConvertor Delete method
@@ -80,18 +78,14 @@ func (t *TelegramPayload) Delete(p *api.DeletePayload) (api.Payloader, error) {
8078
title := fmt.Sprintf(`[<a href="%s">%s</a>] %s <a href="%s">%s</a> deleted`, p.Repo.HTMLURL, p.Repo.FullName, p.RefType,
8179
p.Repo.HTMLURL+"/src/"+refName, refName)
8280

83-
return &TelegramPayload{
84-
Message: title,
85-
}, nil
81+
return createPayload(title), nil
8682
}
8783

8884
// Fork implements PayloadConvertor Fork method
8985
func (t *TelegramPayload) Fork(p *api.ForkPayload) (api.Payloader, error) {
9086
title := fmt.Sprintf(`%s is forked to <a href="%s">%s</a>`, p.Forkee.FullName, p.Repo.HTMLURL, p.Repo.FullName)
9187

92-
return &TelegramPayload{
93-
Message: title,
94-
}, nil
88+
return createPayload(title), nil
9589
}
9690

9791
// Push implements PayloadConvertor Push method
@@ -129,36 +123,28 @@ func (t *TelegramPayload) Push(p *api.PushPayload) (api.Payloader, error) {
129123
}
130124
}
131125

132-
return &TelegramPayload{
133-
Message: title + "\n" + text,
134-
}, nil
126+
return createPayload(title + "\n" + text), nil
135127
}
136128

137129
// Issue implements PayloadConvertor Issue method
138130
func (t *TelegramPayload) Issue(p *api.IssuePayload) (api.Payloader, error) {
139131
text, _, attachmentText, _ := getIssuesPayloadInfo(p, htmlLinkFormatter, true)
140132

141-
return &TelegramPayload{
142-
Message: strings.TrimSpace(text + "\n\n" + attachmentText),
143-
}, nil
133+
return createPayload(text + "\n\n" + attachmentText), nil
144134
}
145135

146136
// IssueComment implements PayloadConvertor IssueComment method
147137
func (t *TelegramPayload) IssueComment(p *api.IssueCommentPayload) (api.Payloader, error) {
148138
text, _, _ := getIssueCommentPayloadInfo(p, htmlLinkFormatter, true)
149139

150-
return &TelegramPayload{
151-
Message: text + "\n" + p.Comment.Body,
152-
}, nil
140+
return createPayload(text + "\n" + p.Comment.Body), nil
153141
}
154142

155143
// PullRequest implements PayloadConvertor PullRequest method
156144
func (t *TelegramPayload) PullRequest(p *api.PullRequestPayload) (api.Payloader, error) {
157145
text, _, attachmentText, _ := getPullRequestPayloadInfo(p, htmlLinkFormatter, true)
158146

159-
return &TelegramPayload{
160-
Message: text + "\n" + attachmentText,
161-
}, nil
147+
return createPayload(text + "\n" + attachmentText), nil
162148
}
163149

164150
// Review implements PayloadConvertor Review method
@@ -173,12 +159,9 @@ func (t *TelegramPayload) Review(p *api.PullRequestPayload, event models.HookEve
173159

174160
text = fmt.Sprintf("[%s] Pull request review %s: #%d %s", p.Repository.FullName, action, p.Index, p.PullRequest.Title)
175161
attachmentText = p.Review.Content
176-
177162
}
178163

179-
return &TelegramPayload{
180-
Message: text + "\n" + attachmentText,
181-
}, nil
164+
return createPayload(text + "\n" + attachmentText), nil
182165
}
183166

184167
// Repository implements PayloadConvertor Repository method
@@ -187,14 +170,10 @@ func (t *TelegramPayload) Repository(p *api.RepositoryPayload) (api.Payloader, e
187170
switch p.Action {
188171
case api.HookRepoCreated:
189172
title = fmt.Sprintf(`[<a href="%s">%s</a>] Repository created`, p.Repository.HTMLURL, p.Repository.FullName)
190-
return &TelegramPayload{
191-
Message: title,
192-
}, nil
173+
return createPayload(title), nil
193174
case api.HookRepoDeleted:
194175
title = fmt.Sprintf("[%s] Repository deleted", p.Repository.FullName)
195-
return &TelegramPayload{
196-
Message: title,
197-
}, nil
176+
return createPayload(title), nil
198177
}
199178
return nil, nil
200179
}
@@ -203,12 +182,16 @@ func (t *TelegramPayload) Repository(p *api.RepositoryPayload) (api.Payloader, e
203182
func (t *TelegramPayload) Release(p *api.ReleasePayload) (api.Payloader, error) {
204183
text, _ := getReleasePayloadInfo(p, htmlLinkFormatter, true)
205184

206-
return &TelegramPayload{
207-
Message: text,
208-
}, nil
185+
return createPayload(text), nil
209186
}
210187

211188
// GetTelegramPayload converts a telegram webhook into a TelegramPayload
212189
func GetTelegramPayload(p api.Payloader, event models.HookEventType, meta string) (api.Payloader, error) {
213190
return convertPayloader(new(TelegramPayload), p, event)
214191
}
192+
193+
func createPayload(message string) *TelegramPayload {
194+
return &TelegramPayload{
195+
Message: strings.TrimSpace(message),
196+
}
197+
}

0 commit comments

Comments
 (0)