MCPcopy Create free account
hub / github.com/bytebase/bytebase / postMessage

Function postMessage

backend/plugin/webhook/teams/teams.go:217–287  ·  view source on GitHub ↗
(context webhook.Context)

Source from the content-addressed store, hash-verified

215}
216
217func postMessage(context webhook.Context) error {
218 factList := []WebhookSectionFact{}
219 for _, meta := range context.GetMetaList() {
220 factList = append(factList, WebhookSectionFact(meta))
221 }
222
223 section := WebhookSection{
224 FactList: factList,
225 Text: context.Description,
226 }
227 if context.ActorName != "" {
228 section.ActivityTitle = fmt.Sprintf("%s (%s)", context.ActorName, context.ActorEmail)
229 }
230
231 post := Webhook{
232 Type: "MessageCard",
233 Context: "https://schema.org/extensions",
234 Summary: context.Title,
235 ThemeColor: themeColor,
236 Title: context.Title,
237 SectionList: []WebhookSection{
238 section,
239 },
240 ActionList: []WebhookAction{
241 {
242 Type: "OpenUri",
243 Name: "View in Bytebase",
244 TargetList: []WebhookActionTarget{
245 {
246 OS: "default",
247 URI: context.Link,
248 },
249 },
250 },
251 },
252 }
253 body, err := json.Marshal(post)
254 if err != nil {
255 return errors.Wrapf(err, "failed to marshal webhook POST request to %s", context.URL)
256 }
257 req, err := http.NewRequest("POST",
258 context.URL, bytes.NewBuffer(body))
259 if err != nil {
260 return errors.Wrapf(err, "failed to construct webhook POST request to %s", context.URL)
261 }
262
263 req.Header.Set("Content-Type", "application/json")
264 client := &http.Client{
265 Timeout: webhook.Timeout,
266 }
267 resp, err := client.Do(req)
268 if err != nil {
269 return errors.Wrapf(err, "failed to POST webhook to %s", context.URL)
270 }
271
272 b, err := io.ReadAll(resp.Body)
273 if err != nil {
274 return errors.Wrapf(err, "failed to read POST webhook response from %s", context.URL)

Callers 1

PostMethod · 0.70

Calls 6

WebhookSectionFactStruct · 0.85
GetMetaListMethod · 0.80
DoMethod · 0.80
ErrorfMethod · 0.80
CloseMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected