@@ -68,9 +68,7 @@ func (t *TelegramPayload) Create(p *api.CreatePayload) (api.Payloader, error) {
68
68
title := fmt .Sprintf (`[<a href="%s">%s</a>] %s <a href="%s">%s</a> created` , p .Repo .HTMLURL , p .Repo .FullName , p .RefType ,
69
69
p .Repo .HTMLURL + "/src/" + refName , refName )
70
70
71
- return & TelegramPayload {
72
- Message : title ,
73
- }, nil
71
+ return createPayload (title ), nil
74
72
}
75
73
76
74
// Delete implements PayloadConvertor Delete method
@@ -80,18 +78,14 @@ func (t *TelegramPayload) Delete(p *api.DeletePayload) (api.Payloader, error) {
80
78
title := fmt .Sprintf (`[<a href="%s">%s</a>] %s <a href="%s">%s</a> deleted` , p .Repo .HTMLURL , p .Repo .FullName , p .RefType ,
81
79
p .Repo .HTMLURL + "/src/" + refName , refName )
82
80
83
- return & TelegramPayload {
84
- Message : title ,
85
- }, nil
81
+ return createPayload (title ), nil
86
82
}
87
83
88
84
// Fork implements PayloadConvertor Fork method
89
85
func (t * TelegramPayload ) Fork (p * api.ForkPayload ) (api.Payloader , error ) {
90
86
title := fmt .Sprintf (`%s is forked to <a href="%s">%s</a>` , p .Forkee .FullName , p .Repo .HTMLURL , p .Repo .FullName )
91
87
92
- return & TelegramPayload {
93
- Message : title ,
94
- }, nil
88
+ return createPayload (title ), nil
95
89
}
96
90
97
91
// Push implements PayloadConvertor Push method
@@ -129,36 +123,28 @@ func (t *TelegramPayload) Push(p *api.PushPayload) (api.Payloader, error) {
129
123
}
130
124
}
131
125
132
- return & TelegramPayload {
133
- Message : title + "\n " + text ,
134
- }, nil
126
+ return createPayload (title + "\n " + text ), nil
135
127
}
136
128
137
129
// Issue implements PayloadConvertor Issue method
138
130
func (t * TelegramPayload ) Issue (p * api.IssuePayload ) (api.Payloader , error ) {
139
131
text , _ , attachmentText , _ := getIssuesPayloadInfo (p , htmlLinkFormatter , true )
140
132
141
- return & TelegramPayload {
142
- Message : strings .TrimSpace (text + "\n \n " + attachmentText ),
143
- }, nil
133
+ return createPayload (text + "\n \n " + attachmentText ), nil
144
134
}
145
135
146
136
// IssueComment implements PayloadConvertor IssueComment method
147
137
func (t * TelegramPayload ) IssueComment (p * api.IssueCommentPayload ) (api.Payloader , error ) {
148
138
text , _ , _ := getIssueCommentPayloadInfo (p , htmlLinkFormatter , true )
149
139
150
- return & TelegramPayload {
151
- Message : text + "\n " + p .Comment .Body ,
152
- }, nil
140
+ return createPayload (text + "\n " + p .Comment .Body ), nil
153
141
}
154
142
155
143
// PullRequest implements PayloadConvertor PullRequest method
156
144
func (t * TelegramPayload ) PullRequest (p * api.PullRequestPayload ) (api.Payloader , error ) {
157
145
text , _ , attachmentText , _ := getPullRequestPayloadInfo (p , htmlLinkFormatter , true )
158
146
159
- return & TelegramPayload {
160
- Message : text + "\n " + attachmentText ,
161
- }, nil
147
+ return createPayload (text + "\n " + attachmentText ), nil
162
148
}
163
149
164
150
// Review implements PayloadConvertor Review method
@@ -173,12 +159,9 @@ func (t *TelegramPayload) Review(p *api.PullRequestPayload, event models.HookEve
173
159
174
160
text = fmt .Sprintf ("[%s] Pull request review %s: #%d %s" , p .Repository .FullName , action , p .Index , p .PullRequest .Title )
175
161
attachmentText = p .Review .Content
176
-
177
162
}
178
163
179
- return & TelegramPayload {
180
- Message : text + "\n " + attachmentText ,
181
- }, nil
164
+ return createPayload (text + "\n " + attachmentText ), nil
182
165
}
183
166
184
167
// Repository implements PayloadConvertor Repository method
@@ -187,14 +170,10 @@ func (t *TelegramPayload) Repository(p *api.RepositoryPayload) (api.Payloader, e
187
170
switch p .Action {
188
171
case api .HookRepoCreated :
189
172
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
193
174
case api .HookRepoDeleted :
194
175
title = fmt .Sprintf ("[%s] Repository deleted" , p .Repository .FullName )
195
- return & TelegramPayload {
196
- Message : title ,
197
- }, nil
176
+ return createPayload (title ), nil
198
177
}
199
178
return nil , nil
200
179
}
@@ -203,12 +182,16 @@ func (t *TelegramPayload) Repository(p *api.RepositoryPayload) (api.Payloader, e
203
182
func (t * TelegramPayload ) Release (p * api.ReleasePayload ) (api.Payloader , error ) {
204
183
text , _ := getReleasePayloadInfo (p , htmlLinkFormatter , true )
205
184
206
- return & TelegramPayload {
207
- Message : text ,
208
- }, nil
185
+ return createPayload (text ), nil
209
186
}
210
187
211
188
// GetTelegramPayload converts a telegram webhook into a TelegramPayload
212
189
func GetTelegramPayload (p api.Payloader , event models.HookEventType , meta string ) (api.Payloader , error ) {
213
190
return convertPayloader (new (TelegramPayload ), p , event )
214
191
}
192
+
193
+ func createPayload (message string ) * TelegramPayload {
194
+ return & TelegramPayload {
195
+ Message : strings .TrimSpace (message ),
196
+ }
197
+ }
0 commit comments